-
Notifications
You must be signed in to change notification settings - Fork 18
188 lines (182 loc) · 6.73 KB
/
ci-improvement.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
name: CI/CD
on:
push:
branches: [master]
pull_request:
branches: [master]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
quick-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: './.github/templates/setup-node'
- run: pnpm npm-run-all --continue-on-error prettier-check lint types-check test build-storybook unimported
e2e-tests-run:
strategy:
fail-fast: false
matrix:
browser: [ 'chromium', 'firefox' ]
shardIndex: [ 1, 2 ]
shardTotal: [ 2 ]
runs-on: ubuntu-latest
env:
VITE_APP_SENTRY_DSN_URL: ${{ secrets.VITE_APP_SENTRY_DSN_URL }}
VITE_APP_POSTHOG_KEY: ${{ secrets.VITE_APP_POSTHOG_KEY }}
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: './.github/templates/setup-node'
- name: Build app
run: |
npx playwright install chromium
pnpm build
- name: Run E2E tests
uses: './.github/templates/run-playwright'
with:
project: '${{ matrix.browser }}'
packagescript: 'e2e'
shard: '${{ matrix.shardIndex }}'
shardTotal: '${{ matrix.shardTotal }}'
e2e-tests-add-summary:
runs-on: ubuntu-latest
if: ${{ failure() }}
needs: e2e-tests-run
steps:
- uses: actions/github-script@v7
with:
script: |
core.summary.addRaw(`
# E2E tests reports
| Name | Result |
| ----------------------- | - |
| **URL**: | https://${{ github.run_id }}.allkaraoke-party-tests-results.pages.dev |
`
).write();
ct-tests-run:
permissions:
contents: write # https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#usage
pull-requests: write # allows commenting on a PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: './.github/templates/setup-node'
- name: Run CT tests
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: './.github/templates/run-playwright'
with:
packagescript: 'test-ct'
- name: Run CT tests and update snapshots
if: github.ref != 'refs/heads/master'
uses: './.github/templates/run-playwright'
with:
packagescript: 'test-ct -u'
- name: Auto commit updated snapshots
id: auto-commit-action
uses: stefanzweifel/git-auto-commit-action@v5
if: github.ref != 'refs/heads/master'
with:
commit_message: '[ci-skip] chore: update visual regression snapshots'
commit_options: '--no-verify'
- name: "Comment on PR to request a review of visual changes"
if: steps.auto-commit-action.outputs.changes_detected == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.pulls.createReview({ // https://octokit.github.io/rest.js/v20#pulls
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: 'Changes detected in visual regression tests. Please review.',
event: 'COMMENT',
})
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: ['e2e-tests-run', 'ct-tests-run', 'quick-checks']
environment:
name: production
url: https://allkaraoke.party/
env:
VITE_APP_SENTRY_DSN_URL: ${{ secrets.VITE_APP_SENTRY_DSN_URL }}
VITE_APP_POSTHOG_KEY: ${{ secrets.VITE_APP_POSTHOG_KEY }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 30 # needed for Sentry to get list of commits released
- name: Setup Node
uses: './.github/templates/setup-node'
- run: npx playwright install chromium
- run: pnpm build
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build # The folder the action should deploy.
- name: Upload to Cloudflare
id: deploy-report
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build --project-name=allkaraoke-party --branch=${{ github.ref_name }}
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
sourcemaps: './build'
- name: Add Deployment PostHog Annotation
run: |
curl \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${{ secrets.POSTHOG_PAT_KEY }}" \
-d '{"content":"Deployment https://github.com/Asvarox/allkaraoke/actions/runs/${{ github.run_id }}","date_marker":"'$(date --iso-8601=seconds)'","scope":"project","creation_type":"GIT"}' \
https://eu.posthog.com/api/projects/281/annotations/
env:
POSTHOG_PAT_KEY: ${{ secrets.POSTHOG_PAT_KEY }}
- name: "Start monitoring"
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PAT_REPOS_WORKFLOW }}
script: |
github.rest.actions.updateRepoVariable({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'MONITORING_ATTEMPTS',
value: '4'
});
github.rest.actions.enableWorkflow({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'monitor-posthog-events.yml',
});
deploy-branch:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/master'
environment:
name: prs
url: ${{ steps.deploy-report.outputs.deployment-url }}
env:
VITE_APP_SENTRY_DSN_URL: ${{ secrets.VITE_APP_SENTRY_DSN_URL }}
VITE_APP_POSTHOG_KEY: ${{ secrets.VITE_APP_POSTHOG_KEY }}
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: './.github/templates/setup-node'
- run: npx playwright install chromium
- run: pnpm build
shell: bash
- name: Upload to Cloudflare
id: deploy-report
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build --project-name=allkaraoke-party --branch=${{ github.ref_name }}