-
Notifications
You must be signed in to change notification settings - Fork 1
176 lines (152 loc) · 5.66 KB
/
dynamic-matrix.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
name: dynamic-matrix
on:
issue_comment:
types: [created]
jobs:
prepare:
runs-on: ubuntu-latest
if: contains(github.event.comment.body, '/run-automation')
outputs:
repositories: ${{ steps.json.outputs.repositories }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Parse issue body
id: parse-issue-body
uses: stefanbuck/github-issue-parser@v3
- run: echo $JSON_STRING
env:
JSON_STRING: ${{ steps.parse-issue-body.outputs.jsonString }}
- name: Build matrix
uses: actions/github-script@v7
id: json
with:
script: |
let repositories = process.env.REPOSITORIES.replace(/\r/g, '').split('\n');
let json = JSON.stringify(repositories);
console.log(json);
core.setOutput('repositories', json);
env:
REPOSITORIES: ${{ steps.parse-issue-body.outputs.issueparser_repositories }}
run-matrix:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix:
repository: ${{ fromJson(needs.prepare.outputs.repositories) }}
fail-fast: false
max-parallel: 15
steps:
- run: echo ${{ matrix.repository }}
- name: create failures sometimes
run: |
milliseconds=$(date +%s%N | cut -b1-13)
if (( milliseconds % 2 == 0 )); then
exit 1
fi
- name: upload status
if: always()
run: echo "${{ matrix.repository }}, ${{ job.status }}" > ${{ matrix.repository }}.txt
- uses: actions/upload-artifact@v3
if: always()
with:
name: statuses
path: ${{ matrix.repository }}.txt
test-output:
needs: prepare
runs-on: ubuntu-latest
steps:
- run: echo ${{ needs.prepare.outputs.repositories }}
post:
if: always()
needs: run-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
- name: loop thru
id: get-status
working-directory: statuses
continue-on-error: true
run: |
ISFAILED=0
failed_repos=""
successful_repos=""
for file in ./*.txt; do
# Read each line in the file
while IFS=, read -r repo status; do
echo "Repo: $repo, Status: $status"
if [ "$status" != "success" ]; then
# Add the repo to the failed list
failed_repos+="$repo\n"
else
# Add the repo to the successful list
successful_repos+="$repo\n"
fi
done < "$file"
done
echo -e "Failed repos: \n$failed_repos"
echo "failed-repos=$failed_repos" >> $GITHUB_OUTPUT
echo -e "Successful repos: \n$successful_repos"
echo "successful-repos=$successful_repos" >> $GITHUB_OUTPUT
if [ $ISFAILED = 1 ]; then
"isfailed=true" >> $GITHUB_OUTPUT
else
"isfailed=false" >> $GITHUB_OUTPUT
fi
- name: print failed repos
run: echo -e "${{ steps.get-status.outputs.failed-repos }}"
- name: or we could use the api to get failed jobs
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs --jq '.jobs[] | select(.conclusion != "success" and (.name | startswith("run-matrix"))) | { name: .name, conclusion: .conclusion}'
- name: and the api to get success jobs
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs --jq '.jobs[] | select(.conclusion == "success" and (.name | startswith("run-matrix"))) | { name: .name, conclusion: .conclusion}'
# success, handling canceled / incomplete cases
- uses: actions/github-script@v7
if: ${{ !steps.get-status.outputs.isfailed && steps.get-status.outputs.failed-repos != ''}}
with:
script: |
let commentBody
commentBody = `Success`
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
title: 'new issue',
body: commentBody.replace(/ +/g, ''),
labels: ['migration', 'gei']
})
# failure, handling canceled / incomplete cases
- uses: actions/github-script@v7
if: ${{ steps.get-status.outputs.isfailed && steps.get-status.outputs.failed-repos != ''}}
with:
script: |
let commentBody
commentBody = `Failure`
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
title: 'new issue',
body: commentBody.replace(/ +/g, ''),
labels: ['migration', 'gei']
})
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
run: echo '${{ toJSON(job) }}'
- name: Dump steps context
run: echo '${{ toJSON(steps) }}'
- name: Dump runner context
run: echo '${{ toJSON(runner) }}'
- name: Dump strategy context
run: echo '${{ toJSON(strategy) }}'
- name: Dump matrix context
run: echo '${{ toJSON(matrix) }}'
- run: echo ${{ matrix.repository }}