Skip to content

Commit a9d1fa2

Browse files
committed
ci: Upgrade CI/CD configuration
1 parent 2880479 commit a9d1fa2

File tree

4 files changed

+223
-28
lines changed

4 files changed

+223
-28
lines changed

.github/workflows/integrate.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# master only
2+
3+
name: Integrate
4+
5+
on:
6+
push:
7+
branches: [master]
8+
9+
jobs:
10+
validate:
11+
name: Validate
12+
runs-on: ubuntu-latest
13+
env:
14+
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
15+
steps:
16+
- name: Resolve last validated commit hash (for `git diff` purposes)
17+
env:
18+
# See https://github.com/serverlessinc/setup-cicd-resources
19+
GET_LAST_VALIDATED_COMMIT_HASH_URL: ${{ secrets.GET_LAST_VALIDATED_COMMIT_HASH_URL }}
20+
PUT_LAST_VALIDATED_COMMIT_HASH_URL: ${{ secrets.PUT_LAST_VALIDATED_COMMIT_HASH_URL }}
21+
run: |
22+
curl -f "$GET_LAST_VALIDATED_COMMIT_HASH_URL" -o /home/runner/last-validated-commit-hash || :
23+
curl -v -X PUT -H "User-Agent:" -H "Accept:" -H "Content-Type:" -d "$GITHUB_SHA" "$PUT_LAST_VALIDATED_COMMIT_HASH_URL"
24+
- name: Store last validated commit hash (as it's to be used in other job)
25+
uses: actions/upload-artifact@v2
26+
with:
27+
name: last-validated-commit-hash
28+
path: /home/runner/last-validated-commit-hash
29+
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
33+
- name: Retrieve ~/.npm from cache
34+
uses: actions/cache@v1
35+
with:
36+
path: ~/.npm
37+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('**package*.json') }}
38+
restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}-
39+
- name: Retrieve node_modules from cache
40+
id: cacheNodeModules
41+
uses: actions/cache@v1
42+
with:
43+
path: node_modules
44+
key: node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
45+
restore-keys: node-modules-v14-${{ runner.os }}-${{ github.ref }}-
46+
- name: Retrieve src/node_modules from cache
47+
id: cacheSrcNodeModules
48+
uses: actions/cache@v1
49+
with:
50+
path: src/node_modules
51+
key: src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('src/package*.json') }}
52+
restore-keys: src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-
53+
54+
- name: Install Node.js and npm
55+
uses: actions/setup-node@v1
56+
with:
57+
node-version: 14.x
58+
59+
- name: Install root dependencies
60+
if: steps.cacheNodeModules.outputs.cache-hit != 'true'
61+
run: npm update --save-dev --no-save
62+
- name: Install src dependencies
63+
if: steps.cacheSrcNodeModules.outputs.cache-hit != 'true'
64+
run: |
65+
cd src
66+
npm ci
67+
68+
# Ensure no parallel runs
69+
# See: https://github.community/t/how-to-limit-concurrent-workflow-runs/16844/21
70+
- name: Turnstyle
71+
uses: softprops/turnstyle@v1
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Publish "dev" version
76+
run: npm run publish:dev
77+
78+
- name: Integration tests
79+
env:
80+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
81+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
82+
run: npm test
83+
84+
tagIfNewVersion:
85+
name: Tag if new version
86+
runs-on: ubuntu-latest
87+
needs: validate
88+
steps:
89+
- name: Checkout repository
90+
uses: actions/checkout@v2
91+
with:
92+
# Ensure to have complete history of commits pushed with given push operation
93+
# It's loose and imperfect assumption that no more than 30 commits will be pushed at once
94+
fetch-depth: 30
95+
# Tag needs to be pushed with real user token
96+
# (hence we're not relying on actions secrets.GITHUB_TOKEN)
97+
# Otherwise pushed tag won't trigger the actions workflow
98+
token: ${{ secrets.USER_GITHUB_TOKEN }}
99+
100+
- name: Resolve last validated commit hash (for `git diff` purposes)
101+
uses: actions/download-artifact@v2
102+
continue-on-error: true
103+
with:
104+
name: last-validated-commit-hash
105+
path: /home/runner
106+
107+
- name: Tag if new version
108+
run: |
109+
LAST_VALIDATED_COMMIT_HASH=`cat /home/runner/last-validated-commit-hash` || :
110+
if [ -n "$LAST_VALIDATED_COMMIT_HASH" ];
111+
then
112+
NEW_VERSION=`git diff -U0 $LAST_VALIDATED_COMMIT_HASH serverless.component.yml | grep 'version: ' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
113+
if [ -n "$NEW_VERSION" ];
114+
then
115+
git tag v$NEW_VERSION
116+
git push --tags
117+
fi
118+
fi

.github/workflows/nodejs.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Retrieve node_modules from cache
19+
uses: actions/cache@v1
20+
with:
21+
path: node_modules
22+
key: node-modules-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
23+
- name: Retrieve src/node_modules from cache
24+
uses: actions/cache@v1
25+
with:
26+
path: src/node_modules
27+
key: src/node-modules-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('src/package*.json') }}
28+
29+
- name: Install Node.js and npm
30+
uses: actions/setup-node@v1
31+
with:
32+
node-version: 14.x
33+
34+
- name: Publish new version
35+
env:
36+
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
37+
run: npm run publish

.github/workflows/validate.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# PR's only
2+
3+
name: Validate
4+
5+
on:
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
lintAndFormatting:
11+
name: Lint & Formatting
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
17+
- name: Retrieve last master commit (for `git diff` purposes)
18+
run: |
19+
git checkout -b pr
20+
git fetch --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
21+
git checkout master
22+
git checkout pr
23+
24+
- name: Retrieve ~/.npm from cache
25+
uses: actions/cache@v1
26+
with:
27+
path: ~/.npm
28+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('**package*.json') }}
29+
restore-keys: |
30+
npm-v14-${{ runner.os }}-${{ github.ref }}-
31+
npm-v14-${{ runner.os }}-refs/heads/master-
32+
- name: Retrieve node_modules from cache
33+
id: cacheNodeModules
34+
uses: actions/cache@v1
35+
with:
36+
path: node_modules
37+
key: node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
38+
restore-keys: |
39+
node-modules-v14-${{ runner.os }}-${{ github.ref }}-
40+
node-modules-v14-${{ runner.os }}-refs/heads/master-
41+
- name: Retrieve src/node_modules from cache
42+
id: cacheSrcNodeModules
43+
uses: actions/cache@v1
44+
with:
45+
path: src/node_modules
46+
key: src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('src/package*.json') }}
47+
restore-keys: |
48+
src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-
49+
src/node-modules-v14-${{ runner.os }}-refs/heads/master-
50+
51+
- name: Install Node.js and npm
52+
uses: actions/setup-node@v1
53+
with:
54+
node-version: 14.x
55+
56+
- name: Install root dependencies
57+
if: steps.cacheNodeModules.outputs.cache-hit != 'true'
58+
run: npm update --save-dev --no-save
59+
- name: Install src dependencies
60+
if: steps.cacheSrcNodeModules.outputs.cache-hit != 'true'
61+
run: |
62+
cd src
63+
npm ci
64+
65+
- name: Validate Formatting
66+
run: npm run prettier-check:updated
67+
- name: Validate Lint rules
68+
run: npm run lint:updated

0 commit comments

Comments
 (0)