-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (88 loc) · 2.86 KB
/
pipeline.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
name: Pipeline build
on:
push:
#paths:
# - 'src/backend/**'
branches:
- '*'
env:
PROJECT_ID: terrafarm-378218
GAR_LOCATION: europe-west4
GAR_REPOSITORY: pipelines-dev
GCP_FA_PRIVATE_KEY: ${{ secrets.GCP_FA_PRIVATE_KEY }}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Setup Python 3.10
with:
python-version: "3.10"
cache: 'pip'
- run: |
cd src/backend
python -m pip install --upgrade pip
pip install mypy pylint
pip install -r requirements.txt
- name: Run pylint
run: |
cd src/backend
pylint ./pipeline --fail-under 9
- name: Run mypy
run: |
cd src/backend
mypy . --explicit-package-bases
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
cd src/backend
python -m pip install --upgrade pip
pip install pytest
pip install -r requirements.txt
- name: Run pytest
run: pytest
deploy:
needs: [lint, test]
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Retrieve authentication token
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v0'
with:
token_format: 'access_token'
workload_identity_provider: 'projects/389517956549/locations/global/workloadIdentityPools/github/providers/github-provider'
service_account: 'github-493@terrafarm-378218.iam.gserviceaccount.com'
# Authenticate Docker to Google Cloud Artifact Registry
- name: Docker Auth
id: docker-auth
uses: 'docker/login-action@v1'
with:
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
# Build the container and then push it to the Artifact Registry
- name: Build and Push to GAR
run: |-
cd src/backend
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/latest:${{ github.sha }}" ./
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/latest:${{ github.sha }}"
# If required, use the Cloud Run url output in later steps
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}