Skip to content

Commit 9a137ab

Browse files
committed
ci: Switch to Github Actions
1 parent 446d161 commit 9a137ab

File tree

4 files changed

+405
-147
lines changed

4 files changed

+405
-147
lines changed

.github/workflows/integrate.yml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# master only
2+
3+
name: Integrate
4+
5+
on:
6+
push:
7+
branches: [master]
8+
9+
env:
10+
SLS_IGNORE_WARNING: '*'
11+
FORCE_COLOR: 1
12+
13+
jobs:
14+
linuxNode14:
15+
name: '[Linux] Node.js 14: Unit tests '
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Resolve last validated commit hash (for `git diff` purposes)
19+
env:
20+
# See https://github.com/serverlessinc/setup-cicd-resources
21+
GET_LAST_VALIDATED_COMMIT_HASH_URL: ${{ secrets.GET_LAST_VALIDATED_COMMIT_HASH_URL }}
22+
PUT_LAST_VALIDATED_COMMIT_HASH_URL: ${{ secrets.PUT_LAST_VALIDATED_COMMIT_HASH_URL }}
23+
run: |
24+
curl -f "$GET_LAST_VALIDATED_COMMIT_HASH_URL" -o /home/runner/last-validated-commit-hash || :
25+
curl -X PUT -H "User-Agent:" -H "Accept:" -H "Content-Type:" -d "$GITHUB_SHA" "$PUT_LAST_VALIDATED_COMMIT_HASH_URL"
26+
- name: Store last validated commit hash (as it's to be used in other job)
27+
uses: actions/upload-artifact@v2
28+
with:
29+
name: last-validated-commit-hash
30+
path: /home/runner/last-validated-commit-hash
31+
32+
- name: Checkout repository
33+
uses: actions/checkout@v2
34+
35+
- name: Install Node.js and npm
36+
uses: actions/setup-node@v1
37+
with:
38+
node-version: 14.x
39+
registry-url: https://registry.npmjs.org
40+
41+
- name: Retrieve dependencies from cache
42+
id: cacheNpm
43+
uses: actions/cache@v2
44+
with:
45+
path: |
46+
~/.npm
47+
node_modules
48+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
49+
restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}-
50+
51+
- name: Install dependencies
52+
if: steps.cacheNpm.outputs.cache-hit != 'true'
53+
run: |
54+
npm update --no-save
55+
npm update --save-dev --no-save
56+
- name: Unit tests
57+
run: npm test
58+
59+
linuxNode16:
60+
name: '[Linux] Node.js 16: Unit tests'
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v2
65+
66+
- name: Retrieve dependencies from cache
67+
id: cacheNpm
68+
uses: actions/cache@v2
69+
with:
70+
path: |
71+
~/.npm
72+
node_modules
73+
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
74+
restore-keys: npm-v16-${{ runner.os }}-${{ github.ref }}-
75+
76+
- name: Install Node.js and npm
77+
uses: actions/setup-node@v1
78+
with:
79+
node-version: 16.x
80+
81+
- name: Install dependencies
82+
if: steps.cacheNpm.outputs.cache-hit != 'true'
83+
run: |
84+
npm update --no-save
85+
npm update --save-dev --no-save
86+
- name: Unit tests
87+
run: npm test
88+
89+
linuxNode12:
90+
name: '[Linux] Node.js 12: Unit tests'
91+
runs-on: ubuntu-latest
92+
steps:
93+
- name: Checkout repository
94+
uses: actions/checkout@v2
95+
96+
- name: Retrieve dependencies from cache
97+
id: cacheNpm
98+
uses: actions/cache@v2
99+
with:
100+
path: |
101+
~/.npm
102+
node_modules
103+
key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
104+
restore-keys: npm-v12-${{ runner.os }}-${{ github.ref }}-
105+
106+
- name: Install Node.js and npm
107+
uses: actions/setup-node@v1
108+
with:
109+
node-version: 12.x
110+
111+
- name: Install dependencies
112+
if: steps.cacheNpm.outputs.cache-hit != 'true'
113+
run: |
114+
npm update --no-save
115+
npm update --save-dev --no-save
116+
- name: Unit tests
117+
run: npm test
118+
119+
linuxNode10:
120+
name: '[Linux] Node.js v10: Unit tests'
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Checkout repository
124+
uses: actions/checkout@v2
125+
126+
- name: Retrieve dependencies from cache
127+
id: cacheNpm
128+
uses: actions/cache@v2
129+
with:
130+
path: |
131+
~/.npm
132+
node_modules
133+
key: npm-v10-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
134+
restore-keys: |
135+
npm-v10-${{ runner.os }}-${{ github.ref }}-
136+
npm-v10-${{ runner.os }}-refs/heads/master-
137+
138+
- name: Install Node.js and npm
139+
uses: actions/setup-node@v1
140+
with:
141+
node-version: 10.x
142+
143+
- name: Install dependencies
144+
if: steps.cacheNpm.outputs.cache-hit != 'true'
145+
run: |
146+
npm update --no-save
147+
npm update --save-dev --no-save
148+
- name: Unit tests
149+
run: npm test
150+
151+
tagIfNewVersion:
152+
name: ubuntu-latest
153+
runs-on: ubuntu-latest
154+
needs: [linuxNode14, linuxNode16, linuxNode12, linuxNode10]
155+
timeout-minutes: 30 # Default is 360
156+
steps:
157+
- name: Checkout repository
158+
uses: actions/checkout@v2
159+
with:
160+
# Ensure to have complete history of commits pushed with given push operation
161+
# It's loose and imperfect assumption that no more than 30 commits will be pushed at once
162+
fetch-depth: 30
163+
# Tag needs to be pushed with real user token, otherwise pushed tag won't trigger the actions workflow
164+
# Hence we're passing 'serverless-ci' user authentication token
165+
token: ${{ secrets.USER_GITHUB_TOKEN }}
166+
167+
- name: Resolve last validated commit hash (for `git diff` purposes)
168+
uses: actions/download-artifact@v2
169+
continue-on-error: true
170+
with:
171+
name: last-validated-commit-hash
172+
path: /home/runner
173+
- name: Tag if new version
174+
run: |
175+
LAST_VALIDATED_COMMIT_HASH=`cat /home/runner/last-validated-commit-hash` || :
176+
if [ -n "$LAST_VALIDATED_COMMIT_HASH" ];
177+
then
178+
NEW_VERSION=`git diff -U0 $LAST_VALIDATED_COMMIT_HASH package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
179+
if [ -n "$NEW_VERSION" ];
180+
then
181+
git tag v$NEW_VERSION
182+
git push --tags
183+
fi
184+
fi

.github/workflows/publish.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Version tags only
2+
3+
name: Publish
4+
5+
on:
6+
push:
7+
tags:
8+
- v[0-9]+.[0-9]+.[0-9]+
9+
10+
jobs:
11+
publish:
12+
name: Publish
13+
runs-on: ubuntu-latest
14+
env:
15+
# Ensure release notes are published by our `serverless-ci` bot
16+
# (If instead we'd use unconditionally provided secrets.GITHUB_TOKEN then
17+
# "github-actions" user will be listed as release publisher)
18+
GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v2
22+
23+
- name: Retrieve dependencies from cache
24+
uses: actions/cache@v2
25+
with:
26+
path: |
27+
~/.npm
28+
node_modules
29+
key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
30+
31+
- name: Install Node.js and npm
32+
uses: actions/setup-node@v1
33+
with:
34+
node-version: 14.x
35+
registry-url: https://registry.npmjs.org
36+
37+
- name: Publish new version
38+
# Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work
39+
# as it appears actions/setup-node sets own value
40+
env:
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
run: npm publish
43+
44+
# Normally we have a guarantee that deps are already there, still it may not be the case when:
45+
# - `master` build for same commit failed (and we still pushed tag manually)
46+
# - We've pushed tag manually before `master` build finalized
47+
- name: Install dependencies
48+
if: steps.cacheNpm.outputs.cache-hit != 'true'
49+
run: |
50+
npm update --no-save
51+
npm update --save-dev --no-save
52+
- name: Publish release notes
53+
run: |
54+
TEMP_ARRAY=($(echo $GITHUB_REF | tr "/" "\n"))
55+
TAG=${TEMP_ARRAY[@]: -1}
56+
npx github-release-from-cc-changelog $TAG

0 commit comments

Comments
 (0)