Skip to content

Commit 9bc00cc

Browse files
committed
ci: CI setup
1 parent 663cb2a commit 9bc00cc

File tree

4 files changed

+431
-0
lines changed

4 files changed

+431
-0
lines changed

.github/workflows/integrate.yml

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
linuxNode16:
15+
name: "[Linux] Node.js v16: Unit tests"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v2
20+
21+
- name: Retrieve dependencies from cache
22+
id: cacheNpm
23+
uses: actions/cache@v2
24+
with:
25+
path: |
26+
~/.npm
27+
node_modules
28+
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
29+
restore-keys: npm-v16-${{ runner.os }}-${{ github.ref }}-
30+
31+
- name: Install Node.js and npm
32+
uses: actions/setup-node@v1
33+
with:
34+
node-version: 16.x
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
- name: Unit tests
42+
run: npm test
43+
44+
linuxNode18:
45+
name: "[Linux] Node.js v18: Unit tests"
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v2
50+
51+
- name: Retrieve dependencies from cache
52+
id: cacheNpm
53+
uses: actions/cache@v2
54+
with:
55+
path: |
56+
~/.npm
57+
node_modules
58+
key: npm-v18-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
59+
restore-keys: npm-v18-${{ runner.os }}-${{ github.ref }}-
60+
61+
- name: Install Node.js and npm
62+
uses: actions/setup-node@v1
63+
with:
64+
node-version: 17.x
65+
66+
- name: Install dependencies
67+
if: steps.cacheNpm.outputs.cache-hit != 'true'
68+
run: |
69+
npm update --no-save
70+
npm update --save-dev --no-save
71+
72+
- name: Unit tests
73+
run: npm test
74+
75+
linuxNode14:
76+
name: "[Linux] Node.js v14: Unit tests"
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v2
81+
82+
- name: Retrieve dependencies from cache
83+
id: cacheNpm
84+
uses: actions/cache@v2
85+
with:
86+
path: |
87+
~/.npm
88+
node_modules
89+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
90+
restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}-
91+
92+
- name: Install Node.js and npm
93+
uses: actions/setup-node@v1
94+
with:
95+
node-version: 14.x
96+
97+
- name: Install dependencies
98+
if: steps.cacheNpm.outputs.cache-hit != 'true'
99+
run: |
100+
npm update --no-save
101+
npm update --save-dev --no-save
102+
- name: Unit tests
103+
run: npm test
104+
105+
linuxNode12:
106+
name: "[Linux] Node.js v12: Unit tests"
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v2
111+
112+
- name: Retrieve dependencies from cache
113+
id: cacheNpm
114+
uses: actions/cache@v2
115+
with:
116+
path: |
117+
~/.npm
118+
node_modules
119+
key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
120+
restore-keys: npm-v12-${{ runner.os }}-${{ github.ref }}-
121+
122+
- name: Install Node.js and npm
123+
uses: actions/setup-node@v1
124+
with:
125+
node-version: 12.x
126+
127+
- name: Install dependencies
128+
if: steps.cacheNpm.outputs.cache-hit != 'true'
129+
run: |
130+
npm update --no-save
131+
npm update --save-dev --no-save
132+
- name: Unit tests
133+
run: npm test
134+
135+
linuxNode10:
136+
name: "[Linux] Node.js v10: Unit tests"
137+
runs-on: ubuntu-latest
138+
steps:
139+
- name: Checkout repository
140+
uses: actions/checkout@v2
141+
142+
- name: Retrieve dependencies from cache
143+
id: cacheNpm
144+
uses: actions/cache@v2
145+
with:
146+
path: |
147+
~/.npm
148+
node_modules
149+
key: npm-v10-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
150+
restore-keys: npm-v10-${{ runner.os }}-${{ github.ref }}-
151+
152+
- name: Install Node.js and npm
153+
uses: actions/setup-node@v1
154+
with:
155+
node-version: 10.x
156+
157+
- name: Install dependencies
158+
if: steps.cacheNpm.outputs.cache-hit != 'true'
159+
run: |
160+
npm update --no-save
161+
npm update --save-dev --no-save
162+
- name: Unit tests
163+
run: npm test
164+
165+
tagIfNewVersion:
166+
name: Tag if new version
167+
runs-on: ubuntu-latest
168+
needs: [linuxNode16, linuxNode18, linuxNode14, linuxNode12, linuxNode10]
169+
steps:
170+
- name: Checkout repository
171+
uses: actions/checkout@v2
172+
with:
173+
# Ensure to have complete history of commits pushed with given push operation
174+
# It's loose and imperfect assumption that no more than 30 commits will be pushed at once
175+
fetch-depth: 30
176+
# Tag needs to be pushed with real user token, otherwise pushed tag won't trigger the actions workflow
177+
# Hence we're passing 'serverless-ci' user authentication token
178+
token: ${{ secrets.USER_GITHUB_TOKEN }}
179+
- name: Tag if new version
180+
if: github.event.before != '0000000000000000000000000000000000000000' # Skip on first commit
181+
run: |
182+
NEW_VERSION=`git diff -U0 ${{ github.event.before }} package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
183+
if [ -n "$NEW_VERSION" ];
184+
then
185+
git tag v$NEW_VERSION
186+
git push --tags
187+
fi

.github/workflows/publish.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
# It'll work with secrets.GITHUB_TOKEN (which is provided by GitHub unconditionally)
16+
# Still then release author would be "github-actions"
17+
GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
22+
- name: Retrieve dependencies from cache
23+
uses: actions/cache@v2
24+
with:
25+
path: |
26+
~/.npm
27+
node_modules
28+
key: npm-v16-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
29+
30+
- name: Install Node.js and npm
31+
uses: actions/setup-node@v1
32+
with:
33+
node-version: 16.x
34+
registry-url: https://registry.npmjs.org
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Publish new version
40+
# Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work
41+
# as it appears actions/setup-node sets own value
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
run: npm publish
45+
46+
# Normally we have a guarantee that deps are already there, still it may not be the case when:
47+
# - `master` build for same commit failed (and we still pushed tag manually)
48+
# - We've pushed tag manually before `master` build finalized
49+
- name: Install dependencies
50+
if: steps.cacheNpm.outputs.cache-hit != 'true'
51+
run: |
52+
npm update --no-save
53+
npm update --save-dev --no-save
54+
55+
- name: Publish release notes
56+
run: |
57+
TEMP_ARRAY=($(echo $GITHUB_REF | tr "/" "\n"))
58+
TAG=${TEMP_ARRAY[@]: -1}
59+
npx github-release-from-cc-changelog $TAG

0 commit comments

Comments
 (0)