-
Notifications
You must be signed in to change notification settings - Fork 1
124 lines (114 loc) · 4.58 KB
/
cypress-tests-via-comment-in-pr.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
name: Cypress Tests on Demand
on:
issue_comment:
types: [created]
jobs:
cypress-tests:
runs-on: ubuntu-latest
if: |
(contains(github.event.comment.body, 'e2e please!') &&
github.event.issue.pull_request.url)
container:
image: cypress/base:18.15.0
steps:
- name: Add rocket reaction to comment
uses: octokit/[email protected]
with:
route: POST /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions
owner: ${{ github.event.repository.owner.login }}
repo: ${{ github.event.repository.name }}
comment_id: ${{ github.event.comment.id }}
content: rocket
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Get pull request details
id: pr-details
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
apt-get update
apt-get install -y jq curl
PR_DETAILS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "${{ github.event.issue.pull_request.url }}" | jq '{ref: .head.ref, repo: .head.repo.full_name, sha: .head.sha}')
echo $PR_DETAILS
echo "PR_REF=$(echo $PR_DETAILS | jq -r .ref)" >> $GITHUB_ENV
echo "PR_REPO=$(echo $PR_DETAILS | jq -r .repo)" >> $GITHUB_ENV
echo "PR_SHA=$(echo $PR_DETAILS | jq -r .sha)" >> $GITHUB_ENV
- name: Request check run
id: request-check-run
uses: octokit/[email protected]
with:
route: POST /repos/{owner}/{repo}/check-runs
owner: ${{ github.event.repository.owner.login }}
repo: ${{ github.event.repository.name }}
name: Cypress Tests on Demand
head_sha: ${{ env.PR_SHA }}
status: in_progress
started_at: ${{ github.event.workflow_run.created_at }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: reinstall ca-certificates
# Fix for https://github.com/noisy/portfolio/actions/runs/4708656910/jobs/8351231323
# https://stackoverflow.com/a/35824116/338581
run: |
apt-get update
apt-get install -y --reinstall ca-certificates
- name: Checkout
uses: actions/checkout@v2
with:
repository: ${{ env.PR_REPO }}
ref: ${{ env.PR_REF }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
uses: cypress-io/[email protected]
with:
# just perform install
runTests: false
- name: E2E tests
uses: cypress-io/[email protected]
with:
config-file: cypress.config.e2e.ts
install: false
build: npm run build
start: npm run preview
wait-on: "http://localhost:5050"
wait-on-timeout: 120
record: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_E2E_RECORD_KEY }}
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# overwrite commit message sent to Cypress Cloud
COMMIT_INFO_MESSAGE: ${{ env.PR_TITLE }}
# re-enable PR comment bot
COMMIT_INFO_SHA: ${{ env.PR_SHA }}
- name: Components tests
uses: cypress-io/[email protected]
with:
config-file: cypress.config.components.ts
install: false
record: true
component: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_COMPONENTS_RECORD_KEY }}
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# overwrite commit message sent to Cypress Cloud
COMMIT_INFO_MESSAGE: ${{ env.PR_TITLE }}
# re-enable PR comment bot
COMMIT_INFO_SHA: ${{ env.PR_SHA }}
# Add this step at the end of the job steps
- name: Update check run
id: update-check-run
uses: octokit/[email protected]
with:
route: PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}
owner: ${{ github.event.repository.owner.login }}
repo: ${{ github.event.repository.name }}
check_run_id: ${{ fromJson(steps.request-check-run.outputs.data).id }}
status: completed
conclusion: ${{ job.status == 'success' && 'success' || 'failure' }}
completed_at: ${{ github.event.workflow_run.updated_at }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}