-
Notifications
You must be signed in to change notification settings - Fork 14
181 lines (155 loc) · 7.06 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: build
# We want pushes to main, beta, and next to trigger a publish to npm for the corresponding npm dist-tag.
# NOTE: semantic-release detects pull requests and won't deploy on them so we don't have to deal with that complexity here.
# Any pull request should run all tests.
# NOTE: e2e tests use shared resource (AWS) and if they run concurrently they step on one another and cause errors.
# This can happen for beta & next branches if a PR targeting main also exists for them. There is some logic in e2e_tests job to mitigate this.
on:
push:
branches: [main, beta, next]
pull_request:
branches: [main]
# Allow one concurrent build for the same branch
concurrency:
group: current-branch-${{ github.ref }}
cancel-in-progress: true
jobs:
unit_tests:
runs-on: ubuntu-20.04
strategy:
matrix:
node: [14, 16, 18]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: "npm"
- name: install dependencies
run: |
npm i
- name: test
env:
CI_NODE_VERSION: ${{ matrix.node }}
run: |
npm run test
- name: publish coverage
uses: coverallsapp/github-action@master
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: nodejs-${{ matrix.node }}
parallel: true
update_code_coverage:
needs: unit_tests
runs-on: ubuntu-20.04
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
e2e_tests:
# Allow only one concurrent deployment for the target branch:
## no reason to run the long-running AWS e2e tests until we are sure this one will be viable
## NOTE: we could separate e2e_tests job into a e2e_tests_local and e2e_tests_remote since the local ones are quite a lot faster
concurrency:
group: target-branch-${{ github.base_ref }}
permissions:
# NOTE: If you specify the access for any of these scopes, all of those that are not specified are set to none.
# for AWS OIDC Token access per https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#updating-your-github-actions-workflow
id-token: write
contents: read
deployments: read
needs: unit_tests
runs-on: ubuntu-20.04
environment: aws
env:
# e2e tests use a shared resource in AWS. Since we trigger on both a push to beta/next and a PR with destination branch of main, a PR against beta/next will cause them to run concurrently and causes errors. To prevent this contention we use a serverless stage.
# For more information on serverless stages:
# - https://www.serverless.com/framework/docs/providers/aws/cli-reference/deploy/
# - https://www.serverless.com/framework/docs/providers/aws/guide/deploying#tips
# github.run_id: A unique number for each run within a repository. This number does not change if you re-run the workflow run. https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
# github format: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#format
SERVERLESS_STAGE: ${{ github.event_name == 'pull_request' && format('pr{0}', github.run_id) || format('push{0}', github.run_id) }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: build plugin locally
run: |
cd "$GITHUB_WORKSPACE"
npm i
npm pack
- name: run local end-to-end test in serverless-offline
run: |
"$GITHUB_WORKSPACE/test-files/scripts/test-local-e2e.sh"
- name: configure aws credentials
# Configures AWS credential and region environment variables for use in other GitHub Actions.
# The environment variables will be detected by both the AWS SDKs and the AWS CLI to determine the credentials and region to use for AWS API calls.
# More on this action at https://github.com/aws-actions/configure-aws-credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::166901232151:role/serverless-aws-static-file-handler-at-github
aws-region: us-west-2
- name: prepare to run remote end-to-end test
run: |
cd "$GITHUB_WORKSPACE/examples/basic"
npm i
# update to use the local plugin built above
npm install --save file://../../serverless-aws-static-file-handler-0.0.0.tgz
- name: run remote end-to-end test
run: |
cd "$GITHUB_WORKSPACE/examples/basic"
echo "Deploying serverless stage $SERVERLESS_STAGE"
./node_modules/.bin/serverless deploy --stage $SERVERLESS_STAGE
# get the APIG endpoint URL:
APIG_URL=$(./node_modules/.bin/serverless info --stage $SERVERLESS_STAGE | sed -nr "s#^.*(https://.+/$SERVERLESS_STAGE)\$#\1#p")
echo "Discovered APIG_URL: $APIG_URL"
# CURL to some known good endpoints expecting 200:
TEST_HTTP_EXEC=$GITHUB_WORKSPACE/test-files/scripts/test-http.sh
ROOT_URL=$APIG_URL
# 200; these all should succeed
$TEST_HTTP_EXEC $ROOT_URL/binary/png.png
$TEST_HTTP_EXEC $ROOT_URL/binary/jpg.jpg
$TEST_HTTP_EXEC $ROOT_URL/binary/glyphicons-halflings-regular.woff2
$TEST_HTTP_EXEC $ROOT_URL/binary/subdir/png.png
# 403
$TEST_HTTP_EXEC "$ROOT_URL/ff404.png" 403
$TEST_HTTP_EXEC "$ROOT_URL/jpeg404.jpg" 403
$TEST_HTTP_EXEC "$ROOT_URL/subdir404/ff.png" 403
$TEST_HTTP_EXEC "$ROOT_URL/subdir/ff404.png" 403
# 404
$TEST_HTTP_EXEC "$ROOT_URL/binary/404-glyphicons-halflings-regular.woff2" 404
$TEST_HTTP_EXEC "$ROOT_URL/binary/subdir/404-png.png" 404
- name: cleanup remote end-to-end test (destroy serverless stack)
# Run this step even if the prior one failed (to clean up)
if: ${{ always() }}
run: |
cd "$GITHUB_WORKSPACE/examples/basic"
echo "Destroying serverless stage $SERVERLESS_STAGE"
./node_modules/.bin/serverless remove --stage $SERVERLESS_STAGE
publish_package:
if: ${{ github.event_name != 'pull_request' }}
needs: [e2e_tests, unit_tests]
runs-on: ubuntu-20.04
environment: npm
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
#- name: debug publish_package
# uses: actions/bin/debug@master
- name: publish to npm
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm install
npx semantic-release@17