1+ name : run tests
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ # TODO: All these inputs are not entirely necessary, they are just there for convenience of "setup Node.js" step,
7+ # where they are required. Making them optional requires additional logic, that might be un-necessary for our purposes
8+ # Best would be if "actions/setup-node" would be able to parse these from .npmrc and .nvmrc (except token of course)
9+ npmAuth :
10+ description : Whether to authenticate to NPM registry
11+ required : false
12+ type : boolean
13+ default : true
14+ nodeVersionFile :
15+ description : Path to node version file
16+ required : false
17+ type : string
18+ default : .nvmrc
19+ npmRegistryUrl :
20+ description : NPM registry url
21+ required : false
22+ type : string
23+ default : https://npm.pkg.github.com/
24+ npmScope :
25+ description : NPM scope
26+ required : true
27+ type : string
28+ npmTestScript :
29+ description : Script for test in package.json
30+ required : true
31+ type : string
32+ title :
33+ description : Title displayed in slack message
34+ required : false
35+ type : string
36+ default : " integration tests"
37+ revision :
38+ description : Revision that is being tested (This is strictly informative)
39+ required : true
40+ type : string
41+ slackChannelId :
42+ description : Slack Channel ID
43+ required : true
44+ type : string
45+ actorOverride :
46+ description : Override the author of event
47+ required : false
48+ type : string
49+ envVariables :
50+ description : Space separated list of environment variables to be set during test phase
51+ required : false
52+ type : string
53+ # example:
54+ # envVariables: >
55+ # FOO=bar
56+ # BAR=foo
57+
58+ secrets :
59+ npmToken :
60+ description : NPM token
61+ required : false
62+ slackToken :
63+ description : Slack API token
64+ required : true
65+
66+
67+ jobs :
68+ tests :
69+ runs-on : ubuntu-latest
70+ steps :
71+ - name : Send notification to slack
72+ uses : slackapi/slack-github-action@v1.19.0
73+ env :
74+ SLACK_BOT_TOKEN : ${{ secrets.slackToken }}
75+ with :
76+ channel-id : ${{ inputs.slackChannelId }}
77+ payload : |
78+ {
79+ "text": ":large_blue_circle: *${{ github.repository }} ${{ inputs.title }} started*",
80+ "attachments": [
81+ {
82+ "color": "#0066ff",
83+ "blocks": [
84+ {
85+ "type": "section",
86+ "fields": [
87+ {
88+ "type": "mrkdwn",
89+ "text": "*Author:* ${{ inputs.actorOverride || github.actor }}"
90+ },
91+ {
92+ "type": "mrkdwn",
93+ "text": "*Revision:* ${{ inputs.revision }}"
94+ },
95+ {
96+ "type": "mrkdwn",
97+ "text": "*Details:* <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|trigger>, <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>"
98+ },
99+ {
100+ "type": "mrkdwn",
101+ "text": "*Triggered by:* ${{ github.event_name }}"
102+ }
103+ ]
104+ }
105+ ]
106+ }
107+ ]
108+ }
109+
110+ - name : clone local repository
111+ uses : actions/checkout@v3
112+
113+ # TODO: turn on caching
114+ - name : setup Node.js
115+ uses : actions/setup-node@v3
116+ with :
117+ always-auth : ${{ inputs.npmAuth }}
118+ node-version-file : ${{ inputs.nodeVersionFile }}
119+ registry-url : ${{ inputs.npmRegistryUrl }}
120+ scope : ${{ inputs.npmScope }}
121+
122+ - name : run tests
123+ run : |
124+ if [ "${{ inputs.envVariables }}" != "" ]; then
125+ export $(echo ${{ inputs.envVariables }})
126+ fi
127+
128+ if [ "${{ secrets.npmToken }}" != "" ]; then
129+ export NODE_AUTH_TOKEN=${{ secrets.npmToken }}
130+ fi
131+ npm install
132+ npm run ${{ inputs.npmTestScript }}
133+
134+ - name : helper - get slack message formatting
135+ id : helper
136+ if : ${{ always() }}
137+ run : |
138+ if [ "${{ job.status }}" = "success" ]
139+ then
140+ echo ::set-output name=color::#00cc00
141+ echo ::set-output name=emoji::large_green_circle
142+ else
143+ echo ::set-output name=color::#ff0000
144+ echo ::set-output name=emoji::red_circle
145+ fi
146+
147+ - name : send result to slack
148+ if : ${{ always() }}
149+ uses : slackapi/slack-github-action@v1.19.0
150+ env :
151+ SLACK_BOT_TOKEN : ${{ secrets.slackToken }}
152+ with :
153+ channel-id : ${{ inputs.slackChannelId }}
154+ payload : |
155+ {
156+ "text": ":${{ steps.helper.outputs.emoji }}: *${{ github.repository }} ${{ inputs.title }} result: ${{ job.status }}*",
157+ "attachments": [
158+ {
159+ "color": "${{ steps.helper.outputs.color }}",
160+ "blocks": [
161+ {
162+ "type": "section",
163+ "fields": [
164+ {
165+ "type": "mrkdwn",
166+ "text": "*Author:* ${{ inputs.actorOverride || github.actor }}"
167+ },
168+ {
169+ "type": "mrkdwn",
170+ "text": "*Revision:* ${{ inputs.revision }}"
171+ },
172+ {
173+ "type": "mrkdwn",
174+ "text": "*Details:* <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|trigger>, <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>"
175+ },
176+ {
177+ "type": "mrkdwn",
178+ "text": "*Triggered by:* ${{ github.event_name }}"
179+ }
180+ ]
181+ }
182+ ]
183+ }
184+ ]
185+ }
0 commit comments