forked from barneygale/httpio
-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (178 loc) · 6.6 KB
/
shared-ext-ci-workflow.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
# This workflow is manged centrally in CommonTooling
name: Shared CI Workflow
on:
workflow_call:
inputs:
forceDocsUpload:
description: 'Force upload of documentation'
required: false
type: boolean
pythonVersion:
description: 'Python version to use'
required: false
default: '3.10'
type: string
commontoolingBranch:
description: 'Commontooling branch or tag to use'
required: true
default: 'main'
type: string
checkoutRef:
description: 'Overrides the branch of the repo under test to checkout'
required: false
type: string
ciEnvironment:
description: 'The Actions Environment to use when running CI'
required: false
type: string
enableArtifactory:
description: 'Upload to artifactory instead of PyPi'
required: false
type: boolean
enableUploadDocker:
description: 'Enable docker upload step. NOTE: Docker images will only be uploaded if the build is on a tag.'
required: false
type: boolean
secrets:
COMMONTOOLING_DEPLOY_KEY:
description: 'A deploy key that may be used to fetch Commontooling'
required: true
ARTIFACTORY_USERNAME:
description: 'An artifactory username with read/write access'
required: false
ARTIFACTORY_TOKEN:
description: 'An artifactory token with read/write access'
required: false
AWS_ACCOUNT_ID:
description: 'An AWS Account ID'
required: true
env:
PYTHON_VERSION: ${{ inputs.pythonVersion == '' && '3.10' || inputs.pythonVersion }}
COMMONTOOLING_BRANCH: ${{ inputs.commontoolingBranch == '' && 'main' || inputs.commontoolingBranch }}
CHECKOUT_REF: ${{ inputs.checkoutRef == '' && github.ref || inputs.checkoutRef }}
jobs:
CheckStaticFiles:
name: Check Static Files
permissions:
contents: read
runs-on: ubuntu-22.04
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ env.CHECKOUT_REF }}
- name: Initialise commontooling
uses: actions/checkout@v4
with:
repository: bbc/rd-cloudfit-commontooling
ref: ${{ env.COMMONTOOLING_BRANCH }}
path: commontooling
fetch-depth: 1
ssh-key: ${{ secrets.COMMONTOOLING_DEPLOY_KEY }}
- name: Check static files
run: make check-static-files
CI:
name: CI
permissions:
actions: read
contents: read
pages: read
id-token: write
runs-on: ubuntu-22.04
needs: CheckStaticFiles
environment:
name: ${{ startsWith(inputs.checkoutRef == '' && github.ref || inputs.checkoutRef, 'refs/tags/') && 'publish-packages' || '' }}
steps:
####################
## Initialise run ##
####################
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0 # check out entire repo for version calculation
ref: ${{ env.CHECKOUT_REF }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ (((inputs.enableUploadDocker && startsWith(env.CHECKOUT_REF, 'refs/tags/')) && 'gha_ecr_public_write') || 'gha_ecr_public_read') }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
mask-password: true
- name: Create pip conf
run: touch ${{ github.workspace }}/.pip.conf
###############
## Run tests ##
###############
- name: Build artefacts
run: make artefacts
- name: Lint
run: make lint
- name: Typecheck
run: make typecheck
- name: Tests
run: make test
##########################################
## Build remaining deployable artefacts ##
##########################################
- name: Build docs
run: make docs
- name: Build wheels
run: make wheel
#################################
## Upload deployable artefacts ##
#################################
- name: ${{ format('{0}Upload wheels to PyPi', ((inputs.enableArtifactory) && 'NOT ENABLED | ' || '') ) }}
if: ${{ (!inputs.enableArtifactory) && startsWith(env.CHECKOUT_REF, 'refs/tags/') }}
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e # v1.8.10
with:
skip-existing: true
- name: ${{ format('{0}Upload wheels to Artifactory', ((!inputs.enableArtifactory) && 'NOT ENABLED | ' || '') ) }}
if: ${{ inputs.enableArtifactory && startsWith(env.CHECKOUT_REF, 'refs/tags/') }}
env:
TWINE_REPO: ${{ secrets.ARTIFACTORY_REPO }}
TWINE_REPO_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
TWINE_REPO_PASSWORD: ${{ secrets.ARTIFACTORY_TOKEN }}
run: make upload-wheels
- name: ${{ format('{0}Upload docker images', ((! inputs.enableUploadDocker) && 'NOT ENABLED | ' || '') ) }}
if: ${{ inputs.enableUploadDocker && startsWith(env.CHECKOUT_REF, 'refs/tags/') }}
run: make upload-docker
- name: Setup pages
if: ${{ inputs.forceDocsUpload || startsWith(env.CHECKOUT_REF, 'refs/tags/') }}
uses: actions/configure-pages@v4
- name: Upload documentation artifact
if: ${{ inputs.forceDocsUpload || startsWith(env.CHECKOUT_REF, 'refs/tags/') }}
uses: actions/upload-pages-artifact@v3
with:
path: './docs'
######################
## Post-Job cleanup ##
######################
- name: Post job - cleanup pip config
if: ${{ always() }}
run: |
rm -f ${{ github.workspace }}/.pip.conf
DeployPages:
name: Deploy Pages
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
runs-on: ubuntu-22.04
needs: CI
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
if: ${{ startsWith(inputs.checkoutRef == '' && github.ref || inputs.checkoutRef, 'refs/tags/') }}
steps:
- name: Deploy documentation to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Adding summary
run: |
echo "Documentation URL: ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY