-
Notifications
You must be signed in to change notification settings - Fork 375
158 lines (139 loc) · 5.1 KB
/
runtime-upgrade-test.yaml
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
name: Runtime upgrade test
on:
issue_comment:
types: [created, edited]
jobs:
check-permission:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/runtime-upgrade-test')
runs-on: ubuntu-latest
steps:
- name: Check permission
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const response = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.actor
});
const actorPermissionLevel = response.data.permission;
console.log(actorPermissionLevel);
// <- lower higher ->
// ["none", "read", "write", "admin"]
if (!(actorPermissionLevel == "admin" || actorPermissionLevel == "write")) {
core.setFailed("Permission denied.");
}
runtime-upgrade-test:
# run only when PR comments start with '/runtime-upgrade-test'.
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/runtime-upgrade-test')
needs: check-permission
runs-on: ubuntu-latest
steps:
- name: Validate and set inputs
id: test-input
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const command = `${{ github.event.comment.body }}`.split(" ");
console.log(command);
// command should be '/runtime-upgrade-test runtime'
if (command.length != 2) {
core.setFailed("Invalid input. It should be '/runtime-upgrade-test [runtime]'");
}
const runtime = command[1];
if (!['shibuya', 'shiden', 'astar'].includes(runtime)) {
const err = "Invalid runtime. It should be 'shibuya', 'shiden', or 'astar'.";
// Error message in Actions.
core.setFailed(err);
// PR comment.
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: err
});
}
core.setOutput("runtime", runtime);
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- name: Get branch and sha
id: get-branch-sha
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const pull_request = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
core.setOutput("branch", pull_request.data.head.ref)
core.setOutput("sha", pull_request.data.head.sha)
- name: Post starting comment
uses: actions/github-script@v6
env:
MESSAGE: |
Runtime upgrade test is scheduled at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.
Please wait for a while.
Runtime: ${{ steps.test-input.outputs.runtime }}
Branch: ${{ steps.get-branch-sha.outputs.branch }}
SHA: ${{ steps.get-branch-sha.outputs.sha }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MESSAGE
})
- name: Checkout the source code
uses: actions/checkout@v3
with:
ref: ${{ steps.get-branch-sha.outputs.sha }}
submodules: true
- name: Install deps
run: sudo apt -y install protobuf-compiler
- name: Install & display rust toolchain
run: rustup show
- name: Check targets are installed correctly
run: rustup target list --installed
- name: Build runtime
run: cargo build -p ${{ steps.test-input.outputs.runtime }}-runtime --release --locked
- name: Run runtime upgrade test
id: test
run: |
cd tests/e2e
yarn --frozen-lockfile
yarn test:runtime-upgrade-${{ steps.test-input.outputs.runtime }} > ${{runner.temp}}/out.txt
- name: Post result comment
uses: actions/github-script@v6
env:
MESSAGE: |
Runtime upgrade test finished:
${{ steps.test.outputs.result }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const fs = require('fs')
const output = fs.readFileSync('${{runner.temp}}/out.txt').toString();
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `
Runtime upgrade test finished:
${output.trim()}
`
})