-
Notifications
You must be signed in to change notification settings - Fork 209
142 lines (125 loc) · 4.83 KB
/
run-cctp-tests.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
name: PR approved workflow
on:
issue_comment:
types:
- created
pull_request_review:
types:
- submitted
push:
branches: ["master"]
merge_group:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-cctp
cancel-in-progress: true
env:
NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }}
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID }}
THE_GRAPH_NETWORK_API_KEY: ${{ secrets.THE_GRAPH_NETWORK_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
check-files:
name: Check files
runs-on: ubuntu-latest
outputs:
run_tests: ${{ steps.check-files.outputs.run_tests }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/check-files
id: check-files
should-run-tests:
runs-on: ubuntu-latest
needs: [check-files]
outputs:
should_run: ${{ steps.should-run-tests.outputs.should_run }}
steps:
- name: Check trigger type and conditions
id: should-run-tests
run: |
if [[ "${{ github.event_name }}" == "issue_comment" ]]; then
if [[ "${{ contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association) }}" == "false" ]]; then
echo "should_run=false" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.comment.body }}" == "/run-cctp-tests" && "${{ github.event.issue.pull_request }}" != "" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
elif [[ "${{ github.event_name }}" == "pull_request_review" ]]; then
if [[ "${{ github.event.review.state }}" == "approved" && "${{ needs.check-files.outputs.run_tests }}" == "true" && "${{ contains(github.event.pull_request.title, 'hotfix') }}" == "false" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
build:
name: "Build"
runs-on: ubuntu-latest
needs: [should-run-tests]
if: needs.should-run-tests.outputs.should_run == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node_modules
uses: OffchainLabs/actions/node-modules/install@main
- name: Build
run: yarn build
env:
NEXT_PUBLIC_IS_E2E_TEST: true
NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }}
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID }}
THE_GRAPH_NETWORK_API_KEY: ${{ secrets.THE_GRAPH_NETWORK_API_KEY }}
- name: Cache build artifacts
uses: ./.github/actions/build-artifacts/cache
cctp-e2e-tests:
name: "CCTP E2E Tests"
needs: [build, check-files]
uses: ./.github/workflows/e2e-tests.yml
with:
test_type: 'cctp'
secrets: inherit
update-pr-status:
name: "Update PR Status"
needs: [cctp-e2e-tests]
runs-on: ubuntu-latest
if: always()
steps:
- name: Create check run
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
let pull_number;
if ('${{ github.event_name }}' === 'issue_comment') {
pull_number = context.issue.number;
} else if ('${{ github.event_name }}' === 'pull_request_review') {
pull_number = context.payload.pull_request.number;
} else {
console.log('Unexpected event type');
return;
}
// Fetch the PR data to get the latest SHA
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: pull_number,
});
const head_sha = pr.head.sha;
// Construct the URL for this workflow run
const workflowUrl = `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`;
await github.rest.checks.create({
owner,
repo,
name: 'CCTP Tests',
head_sha: head_sha,
status: 'completed',
conclusion: '${{ needs.cctp-e2e-tests.result }}',
output: {
title: 'CCTP Tests Result',
summary: `The CCTP tests have completed with status: ${{ needs.cctp-e2e-tests.result }}.`,
text: `For detailed information, please check the [workflow run](${workflowUrl}).`
}
});