Skip to content

Commit 2ac7a0f

Browse files
authored
fix: various fixes (#1)
1 parent c53a234 commit 2ac7a0f

File tree

3 files changed

+230
-21
lines changed

3 files changed

+230
-21
lines changed

.github/workflows/build_docker_image_and_push_to_ecr.yaml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ on:
3030
required: true
3131
type: string
3232
setNodeVersion:
33-
description: Put NODE_VERSION from .nvmrc to GITHUB_ENV
33+
description: Put NODE_VERSION from .nvmrc to docker build args
3434
required: false
3535
type: string
36-
default: "yes"
36+
default: true
37+
dockerBuildArgs:
38+
description: Values for --build-arg argument
39+
required: false
40+
type: string
41+
# This is just a dummy default, so docker does not complain
42+
default: FOO=BAR
3743
actorOverride:
3844
description: Override the author of event
3945
required: false
@@ -49,12 +55,17 @@ on:
4955
slackToken:
5056
description: Slack API token
5157
required: true
58+
npmToken:
59+
description: Put NPM_TOKEN to docker build args
60+
required: false
5261

5362
env:
5463
AWS_ACCESS_KEY_ID: ${{ secrets.awsAccessKeyId }}
5564
AWS_SECRET_ACCESS_KEY: ${{ secrets.awsSecretAccessKey }}
5665
AWS_REGION: ${{ inputs.awsRegion }}
5766

67+
# NPMRC_TEMP_FILE: npmrc-temp-file
68+
5869
jobs:
5970
build:
6071
runs-on: ubuntu-latest
@@ -101,9 +112,16 @@ jobs:
101112
- name: clone repository
102113
uses: actions/checkout@v3
103114

104-
- name: initialize
105-
if: inputs.setNodeVersion == 'yes'
106-
run: echo "NODE_VERSION=$(head -1 .nvmrc)" >> $GITHUB_ENV
115+
- name: set docker build args and secrets
116+
run: |
117+
BUILD_ARGS=${{ inputs.dockerBuildArgs }}
118+
if [ "${{ inputs.setNodeVersion }}" = true ]; then
119+
BUILD_ARGS="${BUILD_ARGS}\nNODE_VERSION=$(head -1 .nvmrc)"
120+
fi
121+
122+
echo 'BUILD_ARGS<<EOF' >> $GITHUB_ENV
123+
echo -e ${BUILD_ARGS} >> $GITHUB_ENV
124+
echo 'EOF' >> $GITHUB_ENV
107125
108126
# NOTE: can be useful
109127
# - name: Set up QEMU
@@ -126,7 +144,9 @@ jobs:
126144
file: ${{ inputs.dockerFilePath }}
127145
push: true
128146
tags: ${{ inputs.registry }}/${{ inputs.repository }}:${{ inputs.imageTag }}
129-
build-args: NODE_VERSION=${{ env.NODE_VERSION }}
147+
build-args: |
148+
${{ env.BUILD_ARGS }}
149+
NPM_TOKEN=${{ secrets.npmToken }}
130150
131151
- name: helper - get slack message attachment color
132152
id: helper

.github/workflows/get_values.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,43 @@ on:
88
description: Commit SHA
99
required: false
1010
type: string
11-
default: ${{ github.event.pull_request.head.sha }}
1211

1312
outputs:
1413
short_commit_sha:
1514
description: Short commit sha
16-
value: ${{ jobs.get_short_commit_sha.outputs.short_commit_sha }}
15+
value: ${{ jobs.get_values.outputs.short_commit_sha }}
1716
commit_author:
18-
description: Author of give commit
19-
value: ${{ jobs.get_commit_author.outputs.commit_author }}
17+
description: Author of last commit
18+
value: ${{ jobs.get_values.outputs.commit_author }}
2019

2120
jobs:
22-
get_short_commit_sha:
21+
get_values:
2322
runs-on: ubuntu-latest
2423
outputs:
2524
short_commit_sha: ${{ steps.get_short_commit_sha.outputs.short_commit_sha }}
25+
commit_author: ${{ steps.get_commit_author.outputs.result }}
2626
steps:
2727
# Cannot use GITHUB_SHA because of https://github.community/t/github-sha-not-the-same-as-the-triggering-commit/18286/2
28-
- id: get_short_commit_sha
28+
- name: get short commit sha
29+
id: get_short_commit_sha
2930
run: |
30-
COMMIT_SHA=${{ inputs.commitSha }}
31+
if [ "${{ inputs.commitSha }}" != "" ]; then
32+
COMMIT_SHA=${{ inputs.commitSha }}
33+
elif [ "${{ github.event_name }}" = "pull_request" ]; then
34+
COMMIT_SHA=${{ github.event.pull_request.head.sha }}
35+
else
36+
COMMIT_SHA=${{ github.sha }}
37+
fi
38+
echo "SHORT_COMMIT_SHA=${COMMIT_SHA::10}" >> $GITHUB_ENV
3139
echo "::set-output name=short_commit_sha::${COMMIT_SHA::10}"
3240
33-
get_commit_author:
34-
runs-on: ubuntu-latest
35-
outputs:
36-
commit_author: ${{ steps.get_commit_author.outputs.result }}
37-
steps:
38-
- uses: actions/github-script@v6
41+
- name: get last commit author
42+
uses: actions/github-script@v6
3943
id: get_commit_author
4044
with:
4145
result-encoding: string
4246
script: |
43-
const commitSha = '${{ inputs.commitSha }}';
47+
const commitSha = process.env.SHORT_COMMIT_SHA;
4448
if (!commitSha) throw new Error(`Input: "commitSha" has invalid value ${commitSha}`)
4549
4650
const payload = await github.rest.repos.getCommit({
@@ -49,4 +53,4 @@ jobs:
4953
ref: commitSha,
5054
});
5155
52-
return payload.data.author.login;
56+
return payload.data.author.login;

.github/workflows/tests.yaml

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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

Comments
 (0)