Skip to content

Commit 50c3c25

Browse files
committed
ci: Upgrade CI/CD configuration
1 parent 7fc4346 commit 50c3c25

File tree

5 files changed

+236
-28
lines changed

5 files changed

+236
-28
lines changed

.github/workflows/integrate.yml

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

.github/workflows/nodejs.yml

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

.github/workflows/publish.yml

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

.github/workflows/validate.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# PR's only
2+
3+
name: Validate
4+
5+
on:
6+
pull_request:
7+
branches: [master]
8+
9+
env:
10+
FORCE_COLOR: 1
11+
12+
jobs:
13+
lintAndFormatting:
14+
name: Lint & Formatting
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
- name: Retrieve last master commit (for `git diff` purposes)
21+
run: |
22+
git checkout -b pr
23+
git fetch --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
24+
git checkout master
25+
git checkout pr
26+
27+
- name: Retrieve ~/.npm from cache
28+
uses: actions/cache@v1
29+
with:
30+
path: ~/.npm
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('**package*.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
- name: Retrieve node_modules from cache
36+
id: cacheNodeModules
37+
uses: actions/cache@v1
38+
with:
39+
path: node_modules
40+
key: node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
41+
restore-keys: |
42+
node-modules-v14-${{ runner.os }}-${{ github.ref }}-
43+
node-modules-v14-${{ runner.os }}-refs/heads/master-
44+
- name: Retrieve src/node_modules from cache
45+
id: cacheSrcNodeModules
46+
uses: actions/cache@v1
47+
with:
48+
path: src/node_modules
49+
key: src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('src/package*.json') }}
50+
restore-keys: |
51+
src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-
52+
src/node-modules-v14-${{ runner.os }}-refs/heads/master-
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+
- name: Validate Formatting
69+
run: npm run prettier-check:updated
70+
- name: Validate Lint rules
71+
run: npm run lint:updated

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
"license": "Apache",
66
"scripts": {
77
"lint": "eslint --ignore-path .gitignore .",
8+
"lint:updated": "pipe-git-updated --ext=js -- eslint --ignore-path .gitignore .",
89
"postinstall": "./scripts/install-nested-packages.js",
910
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,yaml,yml}\"",
11+
"prettier-check:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=yaml --ext=yml -- prettier -c",
1012
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,yaml,yml}\"",
13+
"prettify:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=yaml --ext=yml -- prettier --write",
1114
"publish": "components registry publish",
1215
"publish:dev": "components registry publish --dev",
1316
"test": "jest --bail 1 --testEnvironment node ./test/integration.test.js"
@@ -21,6 +24,7 @@
2124
"eslint": "^7.3.1",
2225
"eslint-plugin-import": "^2.22.0",
2326
"eslint-plugin-prettier": "^3.1.4",
27+
"git-list-updated": "^1.2.1",
2428
"jest": "^25.5.4",
2529
"prettier": "^2.0.5"
2630
},

0 commit comments

Comments
 (0)