-
Notifications
You must be signed in to change notification settings - Fork 3
174 lines (150 loc) · 5.37 KB
/
main-v2.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
name: Release Workflow v2
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
# Needed for nx-set-shas when run on the main branch
permissions:
actions: read
contents: write
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 "info@badman.app"
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:
runs-on: ubuntu-latest
if: ${{ !cancelled() }}
needs: [merge-dev-into-main]
outputs:
NEW_VERSION: ${{ steps.create_release.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.prod-release && 'main' || 'develop' }}
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node
- run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml"
- run: npm ci
- uses: nrwl/nx-set-shas@v4
# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track main origin/main
# - run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build
# if the e2e-tests input is true, run the e2e tests
- name: Run Playwright tests
run: npx nx run-many -t e2e
if: ${{ inputs.e2e-tests }}
- name: e2e reports
if: always() && ${{ inputs.e2e-tests }}
run: |
echo "Combine all the reports into a single report"
# check if the "blob-reports" root directory exists and if it does, remove it and recreate it
if [ -d "blob-reports" ]; then
rm -rf blob-reports
fi
# create the "blob-reports" root directory
mkdir blob-reports
# copy all the reports into the "blob-reports" root directory
cp apps/**/blob-report/*.zip ./blob-reports
# create nx report
npx playwright merge-reports --reporter=html,github ./blob-reports
## for copy pasting in shell
# npx playwright show-report
- name: Set Git config
run: |
git config --local user.email "info@badman.app"
git config --local user.name "Badman Releaser"
# create release on master en develop
- name: Create release
id: create_release
run: node scripts/release.js --dry-run=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# deploy the new packages
- name: Deploy
run: npx nx affected -t deploy --no-agents
env:
API_HOOK: ${{ inputs.prod-release && secrets.PROD_API_HOOK || secrets.BETA_API_HOOK }}
WORKER_SYNC_HOOK: ${{ inputs.prod-release && secrets.PROD_WORKER_SYNC_HOOK || secrets.BETA_WORKER_SYNC_HOOK }}
WORKER_RANKING_HOOK: ${{ inputs.prod-release && secrets.PROD_WORKER_RANKING_HOOK || secrets.BETA_WORKER_RANKING_HOOK }}
- name: stop agents
run: npx nx-cloud complete-ci-run
if: always()
- uses: actions/upload-artifact@v3
if: always() && ${{ inputs.e2e-tests }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
merge-main-into-dev:
name: Merge Main into Dev
runs-on: ubuntu-latest
needs: [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 "info@badman.app"
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.main.outputs.NEW_VERSION }}"
# git merge --no-ff main -m "Merging main into develop"
git push
# deploy on beta if main branch
- name: Deploy beta
run: npx nx affected -t deploy
env:
API_HOOK: ${{ secrets.BETA_API_HOOK }}
WORKER_HOOK: ${{ secrets.BETA_WORKER_SYNC_HOOK }}
RANKING_HOOK: ${{ secrets.BETA_WORKER_RANKING_HOOK }}