This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (114 loc) · 4.5 KB
/
test-and-release.yaml
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
name: Test and Release
permissions:
id-token: write
contents: write
issues: write
on:
push:
workflow_dispatch:
inputs:
skipCleanup:
description: "Skip cleanup"
required: false
default: "no"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
AWS_REGION: eu-west-1
AWS_DEFAULT_REGION: eu-west-1
AWS_ROLE: arn:aws:iam::127234870185:role/github-actions
jobs:
e2e-tests:
name: End-to-end tests
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"
- name: Install dependencies
run: npm ci --no-audit
- name: Check TypeScript
run: npx tsc
- name: Check source code with eslint
run: npx eslint .
- name: Check if source code is properly formatted
run: npx prettier -c ./
- name: Run Unit Tests
run: npm test
- name: Cache AWS CLI (Linux)
id: cache-aws-cli
uses: actions/cache@v4
with:
path: /tmp/aws/
key: cache-aws-cli
- name: Install AWS
if: steps.cache-aws-cli.outputs.cache-hit != 'true'
working-directory: /tmp
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install --update
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE }}
role-session-name: memfault-aws
aws-region: ${{ env.AWS_REGION }}
- name: Generate Stack ID
run: |
RANDOM_STRING=`node -e "const crypto = require('crypto'); process.stdout.write(crypto.randomBytes(Math.ceil(8 * 0.5)).toString('hex').slice(0, 8));"`
echo "STACK_NAME=memfault-aws-${RANDOM_STRING}" >> $GITHUB_ENV
- run: aws sts get-caller-identity
- run: echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
- name: Bootstrap AWS account for CDK
run: |
npx cdk bootstrap aws://`aws sts get-caller-identity | jq -r '.Account' | tr -d '\n'`/${{ env.AWS_REGION }}
- name: Deploy test stack
run: |
npx cdk -a 'node --unhandled-rejections=strict dist/cdk/test-resources.js' deploy --require-approval never
- name: Configure Memfault SSM parameters
run: |
mkdir ~/.aws
# Disable URL lookups
echo "[default]\ncli_follow_urlparam = false" > ~/.aws/config
# Dummy parameters
aws ssm put-parameter --type String --name /${STACK_NAME}/thirdParty/memfault/projectKey --value my-projectKey
aws ssm put-parameter --type String --name /${STACK_NAME}/thirdParty/memfault/organization --value my-org
aws ssm put-parameter --type String --name /${STACK_NAME}/thirdParty/memfault/project --value my-project
aws ssm put-parameter --type String --name /${STACK_NAME}/thirdParty/memfault/authToken --value my-authToken
# Set endpoint to mock API
MOCK_HTTP_API_ENDPOINT=`aws cloudformation describe-stacks --stack-name ${STACK_NAME}-test | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "apiURL") | .OutputValue' | sed -E 's/\/$//g'`
echo $MOCK_HTTP_API_ENDPOINT
aws ssm put-parameter --type String --name /${STACK_NAME}/thirdParty/memfault/apiEndpoint --value $MOCK_HTTP_API_ENDPOINT/api.memfault.com
aws ssm put-parameter --type String --name /${STACK_NAME}/thirdParty/memfault/chunksEndpoint --value $MOCK_HTTP_API_ENDPOINT/chunks.memfault.com
- name: Deploy solution stack
run: npx cdk deploy --require-approval never
- name: Run End-to-End Tests
run: npm run test:e2e
- name: Clean up End-to-End test resources
if: always()
run: |
npx cdk -a 'node --unhandled-rejections=strict dist/cdk/test-resources.js' destroy -f
- name: Destroy solution stack
if: always()
run: npx cdk destroy -f
release:
needs:
- e2e-tests
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/saga'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"
- name: Install dependencies
run: npm ci --no-audit
- name: Semantic release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release