-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (170 loc) · 6.78 KB
/
rust_test.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
189
190
191
name: Rust Test
on:
pull_request:
branches:
- 'main'
paths:
- 'examples/rust/**'
- '.github/workflows/rust_test.yml'
jobs:
set_variables:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.json2vars.outputs.os }}
versions_rust: ${{ steps.json2vars.outputs.versions_rust }}
ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set variables from JSON
id: json2vars
uses: 7rikazhexde/json2vars-setter@main
with:
#json-file: .github/workflows/matrix.json
json-file: .github/workflows/rust_project_matrix.json
- name: Debug output values
run: |
echo "os: ${{ steps.json2vars.outputs.os }}"
echo "os[0]: ${{ fromJson(steps.json2vars.outputs.os)[0] }}"
echo "os[1]: ${{ fromJson(steps.json2vars.outputs.os)[1] }}"
echo "os[2]: ${{ fromJson(steps.json2vars.outputs.os)[2] }}"
echo "versions_rust: ${{ steps.json2vars.outputs.versions_rust }}"
echo "versions_rust[0]: ${{ fromJson(steps.json2vars.outputs.versions_rust)[0] }}"
echo "versions_rust[1]: ${{ fromJson(steps.json2vars.outputs.versions_rust)[1] }}"
echo "versions_rust[2]: ${{ fromJson(steps.json2vars.outputs.versions_rust)[2] }}"
echo "versions_rust[3]: ${{ fromJson(steps.json2vars.outputs.versions_rust)[3] }}"
echo "versions_rust[4]: ${{ fromJson(steps.json2vars.outputs.versions_rust)[4] }}"
echo "ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}"
run_tests:
needs: set_variables
strategy:
matrix:
os: ${{ fromJson(needs.set_variables.outputs.os) }}
rust-version: ${{ fromJson(needs.set_variables.outputs.versions_rust) }}
runs-on: ${{ matrix.os }}
outputs:
test_status: ${{ steps.set_status.outputs.status }}
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust-version }}
components: rustfmt, clippy
- name: Set timezone
uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Tokyo"
timezoneMacos: "Asia/Tokyo"
timezoneWindows: "Tokyo Standard Time"
- name: Display Rust version
run: |
rustc --version
cargo --version
- name: Show matrix
shell: bash
run: |
# For non-list case
ghpages_branch="${{ needs.set_variables.outputs.ghpages_branch }}"
# For list case, explicitly enclose the list in "" to make it a string. (Note that it is not ''.)
os='${{ needs.set_variables.outputs.os }}'
versions_rust='${{ needs.set_variables.outputs.versions_rust }}'
# For list index case
os_0="${{ fromJson(needs.set_variables.outputs.os)[0] }}"
os_1="${{ fromJson(needs.set_variables.outputs.os)[1] }}"
os_2="${{ fromJson(needs.set_variables.outputs.os)[2] }}"
versions_rust_0="${{ fromJson(needs.set_variables.outputs.versions_rust)[0] }}"
versions_rust_1="${{ fromJson(needs.set_variables.outputs.versions_rust)[1] }}"
versions_rust_2="${{ fromJson(needs.set_variables.outputs.versions_rust)[2] }}"
versions_rust_3="${{ fromJson(needs.set_variables.outputs.versions_rust)[3] }}"
versions_rust_4="${{ fromJson(needs.set_variables.outputs.versions_rust)[4] }}"
echo "os: ${os}"
echo "os_0: ${os_0}"
echo "os_1: ${os_1}"
echo "os_2: ${os_2}"
echo "versions_rust: ${versions_rust}"
echo "versions_rust_0: ${versions_rust_0}"
echo "versions_rust_1: ${versions_rust_1}"
echo "versions_rust_2: ${versions_rust_2}"
echo "versions_rust_3: ${versions_rust_3}"
echo "versions_rust_4: ${versions_rust_4}"
echo "ghpages_branch: ${ghpages_branch}"
# For loop case
os_list=$(echo "${os}" | jq -r '.[]' | tr '\n' ' ' | sed 's/ $//')
rust_versions_list=$(echo "${versions_rust}" | jq -r '.[]' | tr '\n' ' ' | sed 's/ $//')
for current_os in ${os_list}; do
for version in ${rust_versions_list}; do
echo "Current OS: ${current_os}, Current Rust Version: ${version}"
done
done
- name: Run tests
id: rust_test
working-directory: ./examples/rust
continue-on-error: true
shell: bash
run: |
output="$(cargo test --verbose)"
echo "${output}"
# Optional: Add code format check
- name: Check formatting
working-directory: ./examples/rust
continue-on-error: true
run: cargo fmt -- --check
# Optional: Run clippy
- name: Run clippy
working-directory: ./examples/rust
continue-on-error: true
run: cargo clippy -- -D warnings
- name: Set test status
id: set_status
if: always()
shell: bash
run: |
if [ "${{ job.status }}" == "cancelled" ]; then
echo "status=cancelled" >> "$GITHUB_OUTPUT"
elif [ "${{ job.status }}" == "skipped" ]; then
echo "status=skipped" >> "$GITHUB_OUTPUT"
elif [ "${{ steps.rust_test.outcome }}" == "failure" ]; then
echo "status=failing" >> "$GITHUB_OUTPUT"
elif [ "${{ steps.rust_test.outcome }}" == "success" ]; then
echo "status=passing" >> "$GITHUB_OUTPUT"
else
echo "status=pending" >> "$GITHUB_OUTPUT"
fi
update_badge:
needs: run_tests
runs-on: ubuntu-latest
if: always()
steps:
- name: Set color
id: set_color
shell: bash
run: |
status="${{ needs.run_tests.outputs.test_status }}"
if [ "$status" == "passing" ]; then
echo "color=2ea44f" >> "$GITHUB_OUTPUT"
elif [ "$status" == "failing" ]; then
echo "color=cf222e" >> "$GITHUB_OUTPUT"
elif [ "$status" == "pending" ]; then
echo "color=dbab09" >> "$GITHUB_OUTPUT"
else
echo "color=808080" >> "$GITHUB_OUTPUT"
fi
- name: Create badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: 5e160d06cfffd42a8f0e4ae6e8e8f025
filename: rust-test-badge.json
label: Rust Test
message: ${{ needs.run_tests.outputs.test_status }}
color: ${{ steps.set_color.outputs.color }}
labelColor: "24292f"
style: "flat"
namedLogo: "github"
logoColor: "white"