-
Notifications
You must be signed in to change notification settings - Fork 3
208 lines (182 loc) · 7.59 KB
/
main.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
name: Release Workflow
on:
# manual trigger
workflow_dispatch:
inputs:
# main branch name
prod-release:
description: 'Do prod release'
required: true
default: false
type: boolean
# main branch name
e2e-tests:
description: 'Do e2e tests'
required: true
default: true
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
run-name: ${{ inputs.prod-release && 'Prod' || 'Beta' }} release ${{ inputs.e2e-tests && 'with E2E tests' || '' }}
jobs:
merge-dev-into-main:
name: Merge Dev into Main
runs-on: ubuntu-latest
timeout-minutes: 10
if: ${{ inputs.prod-release }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set Git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "Badman Releaser"
- name: Merge develop back to main
run: |
git fetch --unshallow
git checkout main
git pull
git merge --no-ff develop -m "Merging develop into main"
git push
main:
name: Nx Cloud - Main Job
uses: ./.github/workflows/nx-cloud-main.yml
if: ${{ !cancelled() }}
needs: [merge-dev-into-main]
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
with:
number-of-agents: 3
node-version: ${{ vars.NODE_VERSION }}
main-branch-name: ${{ inputs.prod-release && 'main' || 'develop' }}
output-affected-projects: true
parallel-commands-on-agents: |
npx nx affected --target=build --parallel=3 --configuration ${{ inputs.prod-release && 'production' || 'beta'}}
npx nx affected --target=lint --parallel=3 --configuration ${{ inputs.prod-release && 'production' || 'beta'}}
npx nx affected --target=test --parallel=3 --configuration ${{ inputs.prod-release && 'production' || 'beta'}} --ci
# npx nx affected --target=server
timeout: 15
agents:
name: Nx Cloud - Agents
if: ${{ !cancelled() }}
needs: [merge-dev-into-main]
uses: ./.github/workflows/nx-cloud-agents.yml
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
with:
node-version: ${{ vars.NODE_VERSION }}
number-of-agents: 3
timeout: 15
release:
runs-on: ubuntu-latest
name: Release
needs: [e2e, main]
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
# output new version
outputs:
NEW_VERSION: ${{ steps.push_release.outputs.new_version }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.prod-release && 'main' || 'develop' }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ vars.NODE_VERSION }}
- name: install dependencies for release
run: npm --prefix \scripts install
- name: Get the new version and changelog
id: create_release
run: |
# if the prod release is false, then we want to create a beta release by appending --beta to the command
npm run --prefix \scripts create-release -- --affected="${{ needs.main.outputs.affectedProjects }}" --prod=${{ inputs.prod-release }}
- name: Push new version and changelog
id: push_release
run: |
git config --global user.email "[email protected]"
git config --global user.name "Badman Releaser"
git config advice.ignoredHook false
git add .
git status
git commit -m "chore(release): v${{ env.NEW_VERSION }}"
git tag -a v${{ env.NEW_VERSION }} -m "${{ env.CHANGELOG }}"
git push --follow-tags origin ${{ inputs.prod-release && 'main' || 'develop' }}
# output new version
echo new_version=${{ env.NEW_VERSION }} >> $GITHUB_OUTPUT
- name: Create Github Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
with:
tag_name: v${{ env.NEW_VERSION }}
release_name: v${{ env.NEW_VERSION }}
body: ${{ env.CHANGELOG }}
prerelease: ${{ !inputs.prod-release }}
- name: Trigger deploy hooks on Render.com (if affected)
run: |
# read the affected projects from the main job
affectedProjects=$(echo ${{ needs.main.outputs.affectedProjects }} | tr -d ' ')
echo "Affected Projects: $affectedProjects"
# check if the affected projects contains api or badman
if [[ $affectedProjects == *"api"* || $affectedProjects == *"badman"* ]]; then
curl -X POST -H "Content-Type: application/json" ${{ inputs.prod-release && secrets.PROD_API_HOOK || secrets.BETA_API_HOOK }}
fi
# check if the affected projects contains worker-sync
if [[ $affectedProjects == *"worker-sync"* ]]; then
curl -X POST -H "Content-Type: application/json" ${{ inputs.prod-release && secrets.PROD_WORKER_SYNC_HOOK || secrets.BETA_WORKER_SYNC_HOOK }}
fi
# check if the affected projects contains worker-sync
if [[ $affectedProjects == *"worker-ranking"* ]]; then
curl -X POST -H "Content-Type: application/json" ${{ inputs.prod-release && secrets.PROD_WORKER_RANKING_HOOK || secrets.BETA_WORKER_RANKING_HOOK }}
fi
## Vercel deploys automatically on push to branch with Chore: prefix
merge-main-into-dev:
name: Merge Main into Dev
runs-on: ubuntu-latest
needs: [release, main]
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && inputs.prod-release
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set Git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "Badman Releaser"
- name: Merge main back to develop
run: |
git fetch --unshallow
git checkout develop
git pull
git merge --no-ff origin/main -m "chore(release): v${{ needs.release.outputs.NEW_VERSION }}"
# git merge --no-ff main -m "Merging main into develop"
git push
- name: Trigger deploy hooks on Render.com (if affected)
run: |
# read the affected projects from the main job
affectedProjects=$(echo ${{ needs.main.outputs.affectedProjects }} | tr -d ' ')
echo "Affected Projects: $affectedProjects"
# check if the affected projects contains api or badman
if [[ $affectedProjects == *"api"* || $affectedProjects == *"badman"* ]]; then
curl -X POST -H "Content-Type: application/json" ${{ secrets.BETA_API_HOOK }}
fi
# check if the affected projects contains worker-sync
if [[ $affectedProjects == *"worker-sync"* ]]; then
curl -X POST -H "Content-Type: application/json" ${{ secrets.BETA_WORKER_SYNC_HOOK }}
fi
# check if the affected projects contains worker-sync
if [[ $affectedProjects == *"worker-ranking"* ]]; then
curl -X POST -H "Content-Type: application/json" ${{ secrets.BETA_WORKER_RANKING_HOOK }}
fi
e2e:
name: E2E Tests
needs: [agents, main]
if: always() && inputs.e2e-tests && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
uses: ./.github/workflows/playwright.yml