-
Notifications
You must be signed in to change notification settings - Fork 10
140 lines (119 loc) · 5.01 KB
/
auto-deploy.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
name: auto-deploy.yml
# Deploys to Google App Engine upon commit to master branch and on schedule at midnight UTC
run-name: Deployment triggered by ${{ github.event_name }} / ${{ github.actor }}
on:
push:
branches:
- "master"
schedule:
- cron: "40 3 * * *" # every day at 8:40pm PDT / 5:40am GMT+2
# see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
workflow_dispatch:
# Only run 1 workflow at a time. If new one starts abort any that are already running.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
default-job:
if: github.repository_owner == 'sentry-demos' # don't run in forks
permissions:
contents: "read"
id-token: "write"
runs-on: ubuntu-22.04
steps:
- run: |
SENTRY_CRON='https://o87286.ingest.sentry.io/api/4505620224540672/cron/auto-deploy/21b95d7975af21218dd7c14f1e48e193/'
curl "$SENTRY_CRON?status=in_progress"
echo "SENTRY_CRON=$SENTRY_CRON" >> "$GITHUB_ENV"
- run: echo "Triggered by ${{ github.event_name }} event."
- run: echo "Branch is ${{ github.ref }}"
- name: Check out this repository code
uses: actions/checkout@v3
with:
path: empower
fetch-depth: 0
- name: Check out `empower-config` to get env-config
uses: actions/checkout@v3
with:
repository: sentry-demos/empower-config
path: empower-config
token: ${{ secrets.KOSTY_PERSONAL_ACCESS_TOKEN_FOR_SYNC_DEPLOY_FORK }}
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Setup Sentry CLI
uses: mathieu-bour/[email protected]
with:
version: 2.17.4
token: ${{ SECRETS.SENTRY_AUTH_TOKEN }} # from GitHub secrets
- name: Get commit SHA that was last successfully deployed
uses: nrwl/[email protected]
with:
main-branch-name: master
error-on-no-successful-workflow: false
working-directory: ./empower
# Test previous step worked
- run: |
echo "BASE: ${{ env.NX_BASE }}"
echo "HEAD: ${{ env.NX_HEAD }}"
- name: Run React tests
run: |
npm install
npm test -- --coverage --reporters=jest-junit
working-directory: ./empower/react
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: frontend
- name: Run Python Tests
run: |
pip install -U pytest
pip install pytest-codecov
pytest --cov=. --cov-report=xml --junitxml=junit.xml -o junit_family=legacy
working-directory: ./empower/flask/src
- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: api
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Get GCP_ env variables from empower-config/.gcloudrc
run: |
source empower-config/.gcloudrc
echo "GCP_WORKLOAD_IDENTITY_PROVIDER=$GCP_WORKLOAD_IDENTITY_PROVIDER" >> $GITHUB_OUTPUT
echo "GCP_SERVICE_ACCOUNT=$GCP_SERVICE_ACCOUNT" >> $GITHUB_OUTPUT
id: gcloudrc
- id: "auth"
name: "Authenticate Google Cloud"
uses: "google-github-actions/auth@v0"
with:
workload_identity_provider: ${{ steps.gcloudrc.outputs.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ steps.gcloudrc.outputs.GCP_SERVICE_ACCOUNT }}
- name: "Set up Google Cloud SDK"
uses: "google-github-actions/setup-gcloud@v0"
- name: Get env-config/production.env from empower-config
run: cp empower-config/production.env empower/env-config/
- name: Deploy to production
run: |
CHANGED_PROJECTS=$(./bin/projects_changed_bw_commits.sh "${{ env.NX_BASE }}" "${{ env.NX_HEAD }}")
if [[ ! -z "$CHANGED_PROJECTS" ]]; then
./deploy.sh $CHANGED_PROJECTS --env=production
elif [[ `./bin/release.sh` != `./bin/release.sh 1` ]]; then # different release than yesterday
# currently we create regular calendar releases only for React
./deploy.sh react --env=production
else
echo "No deployable projects have been changed since last successful deployment. New calendar release is not due either. Nothing to do."
fi
working-directory: ./empower
- run: echo "Job status is ${{ job.status }}."
- name: Report success to Cron monitor (demo/empower-github-workflows)
run: curl "${{ env.SENTRY_CRON }}?status=ok"
# 'if: always()' ensures step is run even if earlier step failed
- name: Report error to Cron monitor (demo/empower-github-workflows)
if: always() && job.status == 'failure'
run: curl "${{ env.SENTRY_CRON }}?status=error"