-
Notifications
You must be signed in to change notification settings - Fork 170
202 lines (175 loc) · 6.93 KB
/
deployment-v2.yml
File metadata and controls
202 lines (175 loc) · 6.93 KB
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
name: Deployment v2
on:
push:
branches: [ main ]
tags: [ cowswap-*, explorer-* ]
concurrency:
group: release-branch-sync
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
jobs:
collect-release-metadata:
name: Collect release metadata
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
outputs:
release-tags: ${{ steps.collect.outputs.release-tags }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Collect tags for release commit
id: collect
run: |
set -euo pipefail
git fetch --tags origin
release_commit="$(git rev-list -n 1 "${GITHUB_REF}")"
release_tags="$(
git tag --points-at "${release_commit}" \
| sort \
| paste -sd ', ' -
)"
if [ -z "${release_tags}" ]; then
release_tags="${GITHUB_REF_NAME}"
fi
echo "release-tags=${release_tags}" >> "$GITHUB_OUTPUT"
sync-develop:
name: Sync main to develop
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
TARGET_BRANCH: develop
SYNC_BRANCH: automation/sync-main-to-develop
PR_TITLE: 'chore(sync): merge main into develop'
PR_BODY: |
This PR contains an automated merge commit from `main` into `develop`.
steps:
- name: Checkout workflow repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Setup release sync
id: setup
uses: ./.github/actions/setup-release-sync
with:
app-id: ${{ vars.COWSWAP_RELEASE_SYNC_APP_ID }}
private-key: ${{ secrets.COWSWAP_RELEASE_SYNC_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repository: ${{ github.event.repository.name }}
pull-requests-write: 'true'
- name: Prepare merge branch
id: prepare
run: |
set -euo pipefail
git config user.name "${APP_SLUG}[bot]"
git config user.email "${APP_USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
git fetch origin main "${TARGET_BRANCH}"
git checkout -B "${TARGET_BRANCH}" "origin/${TARGET_BRANCH}"
before_sha="$(git rev-parse HEAD)"
git merge --no-ff --no-edit -m "${PR_TITLE}" origin/main
after_sha="$(git rev-parse HEAD)"
if [ "${before_sha}" = "${after_sha}" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "has_changes=true" >> "$GITHUB_OUTPUT"
env:
APP_SLUG: ${{ steps.setup.outputs.app-slug }}
APP_USER_ID: ${{ steps.setup.outputs.app-user-id }}
- name: Create or update pull request
if: steps.prepare.outputs.has_changes == 'true'
id: create-pr
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ steps.setup.outputs.token }}
branch: ${{ env.SYNC_BRANCH }}
base: ${{ env.TARGET_BRANCH }}
title: ${{ env.PR_TITLE }}
body: ${{ env.PR_BODY }}
commit-message: ${{ env.PR_TITLE }}
delete-branch: false
draft: false
- name: Notify Slack for develop review
if: steps.prepare.outputs.has_changes == 'true'
run: |
curl -X POST -H "Content-type: application/json" \
--data "{\"text\": \"➡️ Develop sync PR is ready for review. <$PR_URL|Open pull request>.\"}" \
"$SLACK_WEBHOOK_URL"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
PR_URL: ${{ steps.create-pr.outputs.pull-request-url }}
sync-staging:
name: Fast-forward staging to main
if: startsWith(github.ref, 'refs/tags/cowswap-') || startsWith(github.ref, 'refs/tags/explorer-')
needs: collect-release-metadata
runs-on: ubuntu-latest
steps:
- name: Checkout workflow repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Setup release sync
id: setup
uses: ./.github/actions/setup-release-sync
with:
app-id: ${{ vars.COWSWAP_RELEASE_SYNC_APP_ID }}
private-key: ${{ secrets.COWSWAP_RELEASE_SYNC_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repository: ${{ github.event.repository.name }}
- name: Fast-forward staging
run: |
set -euo pipefail
git fetch origin main staging
git checkout -B staging origin/staging
git merge --ff-only origin/main
git push origin staging
notify-production-approval:
name: Notify Slack for production approval
if: startsWith(github.ref, 'refs/tags/cowswap-') || startsWith(github.ref, 'refs/tags/explorer-')
needs: [ collect-release-metadata, sync-staging ]
runs-on: ubuntu-latest
steps:
- name: Notify Slack
run: |
curl -X POST -H "Content-type: application/json" \
--data "{\"text\": \"⏳ Production release for tag(s) \`${RELEASE_TAGS}\` is waiting for approval. <$SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID|Review the workflow run>.\"}" \
"$SLACK_WEBHOOK_URL"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
RELEASE_TAGS: ${{ needs.collect-release-metadata.outputs.release-tags }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
sync-production:
name: Fast-forward production to main
if: startsWith(github.ref, 'refs/tags/cowswap-') || startsWith(github.ref, 'refs/tags/explorer-')
needs: [ collect-release-metadata, notify-production-approval ]
runs-on: ubuntu-latest
environment: production # Env configured in GitHub UI. Requires manual approval before this job can run
steps:
- name: Checkout workflow repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Setup release sync
id: setup
uses: ./.github/actions/setup-release-sync
with:
app-id: ${{ vars.COWSWAP_RELEASE_SYNC_APP_ID }}
private-key: ${{ secrets.COWSWAP_RELEASE_SYNC_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repository: ${{ github.event.repository.name }}
- name: Fast-forward production
run: |
set -euo pipefail
git fetch origin main production
git checkout -B production origin/production
git merge --ff-only origin/main
git push origin production