-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (207 loc) · 7.21 KB
/
pull-requests.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: pull-requests
on:
workflow_call:
inputs:
version_check:
description: "Check for library version increment"
type: boolean
required: false
default: false
db_revision_check:
description: "Check for multiple alembic HEADs"
type: boolean
required: false
default: true
update_iam:
description: "Update IAM Permissions"
type: boolean
required: false
default: false
python_version:
description: "The python version to use, in the format '{major}.{minor}'"
type: string
default: "3.9"
required: false
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
CODECOV_TOKEN:
required: true
PACKER_GH_TOKEN:
required: false
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
PACKER_GITHUB_API_TOKEN: ${{ secrets.PACKER_GH_TOKEN }}
DOCKER_BUILDKIT: 1
NODE_OPTIONS: "--max_old_space_size=4096 prettier asm.js"
jobs:
changes:
runs-on: ubuntu-latest
outputs:
python: ${{ steps.filter.outputs.python }}
src: ${{ steps.filter.outputs.src }}
tests: ${{ steps.filter.outputs.tests }}
stack-files: ${{ steps.filter.outputs.stack-files }}
revisions: ${{ steps.filter.outputs.revisions }}
ci-files: ${{ steps.filter.outputs.ci-files }}
has_tests: ${{ steps.check_files.outputs.files_exists }}
steps:
- id: project_src_name
run: |
export PROJECT_SRC=$(basename "$GITHUB_REPOSITORY" | sed 's/-/_/g')
echo "project_src=$PROJECT_SRC" >> $GITHUB_OUTPUT
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
python:
- '**/*.py'
src:
- 'poetry.lock'
- 'src/**'
- '${{ steps.project_src_name.outputs.project_src }}/**'
- 'yarn.lock'
tests:
- 'tests/**'
stack-files:
- 'scripts/**'
- 'docs/**'
revisions:
- '**/db/versions/**'
ci-files:
- 'bootstrap.sh'
- 'docker-compose.yml'
- 'docker-compose.test.yml'
- 'run'
- '.github/workflows/pull-requests.yml'
- uses: actions/checkout@v3
- uses: andstor/file-existence-action@v2
id: check_files
with:
files: "tests/conftest.py"
db-branch-check:
name: Check for Alembic Branches
needs: changes
if: ${{ (inputs.db_revision_check == 'true') && (needs.changes.outputs.revisions == 'true') }}
runs-on: ubuntu-latest
steps:
- uses: unitasglobal/nio-shared-actions/db-branch-check@main
static-analysis:
name: Run Self Check
needs: changes
if: ${{ needs.changes.outputs.python == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: unitasglobal/nio-shared-actions/static-analysis@main
with:
version_check: ${{ inputs.version_check }}
python_version: ${{ inputs.python_version }}
check-merge-base:
name: Check against main
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const base_ref = process.env.GITHUB_BASE_REF;
const head_ref = process.env.GITHUB_HEAD_REF;
console.log(`Base ref: ${base_ref}`);
console.log(`Head ref: ${head_ref}`);
const res = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: base_ref,
head: head_ref
});
const diff = res.data;
console.log(diff);
if (diff.behind_by != 0) {
core.setFailed(`"${head_ref}" is behind ${base_ref} by ${diff.behind_by} commits`)
}
test:
name: Run Tests
needs: [changes, static-analysis, check-merge-base]
if: ${{ !failure() && !cancelled() && needs.changes.outputs.has_tests == 'true' && (needs.changes.outputs.tests == 'true' || needs.changes.outputs.src == 'true' || needs.changes.outputs.ci-files == 'true') }}
runs-on: ubuntu-latest
steps:
- uses: unitasglobal/nio-shared-actions/run-tests@main
with:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
python_version: ${{ inputs.python_version }}
build-lambda-image:
name: Build Lambda ECR Image
needs: [changes, static-analysis, check-merge-base]
if: ${{ failure() != true && cancelled() != true && (needs.changes.outputs.src == 'true' || needs.changes.outputs.stack-files == 'true') }}
runs-on: ubuntu-latest-8-cores
steps:
- uses: unitasglobal/nio-shared-actions/python-setup@main
with:
python_version: ${{ inputs.python_version }}
- uses: docker/setup-buildx-action@v2
id: buildx-setup
with:
platforms: linux/amd64,linux/arm64
use: false
- name: Check for Docs
id: check_docs
uses: andstor/file-existence-action@v2
with:
files: "docs/*"
- name: Build user docs for deploy
if: ${{ steps.check_docs.outputs.files_exists == 'true' }}
shell: bash
run: ./run docs build-docs
- name: Build and deploy images
shell: bash
run: ./run cdk --review ${{ github.event.number }} prepare-ecr-image --multibuilder ${{ steps.buildx-setup.outputs.name }}
build-ami-image:
name: Build EC2 AMI Image
needs: [changes, static-analysis, check-merge-base]
if: ${{ failure() != true && cancelled() != true && (needs.changes.outputs.src == 'true' || needs.changes.outputs.stack-files == 'true') }}
runs-on: ubuntu-latest
steps:
- uses: unitasglobal/nio-shared-actions/python-setup@main
with:
python_version: ${{ inputs.python_version }}
- uses: docker/setup-buildx-action@v2
id: buildx-setup
with:
platforms: linux/amd64,linux/arm64
use: false
- name: Check for Docs
id: check_docs
uses: andstor/file-existence-action@v2
with:
files: "docs/*"
- name: Build user docs for deploy
if: ${{ steps.check_docs.outputs.files_exists == 'true' }}
shell: bash
run: ./run docs build-docs
- name: Build and deploy images
shell: bash
run: ./run cdk --review ${{ github.event.number }} prepare-ami
deploy-review:
name: Deploy Review Environment
concurrency: deploy-review-${{ github.ref_name }}
needs:
[
changes,
static-analysis,
test,
db-branch-check,
check-merge-base,
build-lambda-image,
build-ami-image,
]
if: ${{ failure() != true && cancelled() != true && (needs.changes.outputs.src == 'true' || needs.changes.outputs.stack-files == 'true') }}
runs-on: ubuntu-latest
steps:
- uses: unitasglobal/nio-shared-actions/deploy-review@main
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
update_iam: ${{ inputs.update_iam }}
python_version: ${{ inputs.python_version }}