-
Notifications
You must be signed in to change notification settings - Fork 46
168 lines (149 loc) · 5.52 KB
/
Copy pathvalidate.yml
File metadata and controls
168 lines (149 loc) · 5.52 KB
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
name: Validate
run-name: "Validate ${{ github.event.workflow_run.head_branch || github.event.workflow_run.head_sha }}"
on:
workflow_run:
workflows: [Dispatch]
types: [completed]
permissions:
actions: read
statuses: write
pull-requests: write
issues: write
discussions: write
contents: write
checks: write
concurrency:
group: ${{github.workflow}}-${{ github.event.workflow_run.head_branch || github.event.workflow_run.head_sha }}
cancel-in-progress: true
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
steps:
- name: Register Check
uses: myrotvorets/set-commit-status-action@v2.0.1
with:
context: Validate Schemas
sha: ${{ github.event.workflow_run.head_sha }}
status: pending
- name: Download Payload
uses: actions/download-artifact@v7
with:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
name: payload
- name: Get Payload Info
id: payload
run: |
PAYLOAD=$(cat payload.json)
echo "event=$(echo $PAYLOAD | jq -r '.event')" >> $GITHUB_OUTPUT
echo "actor=$(echo $PAYLOAD | jq -r '.actor')" >> $GITHUB_OUTPUT
echo "head_ref=$(echo $PAYLOAD | jq -r '.head_ref')" >> $GITHUB_OUTPUT
echo "base_ref=$(echo $PAYLOAD | jq -r '.base_ref')" >> $GITHUB_OUTPUT
- name: Get PR Number
if: steps.payload.outputs.event == 'pr'
uses: actions/github-script@v7
id: pr_number
with:
script: |
const head_sha = "${{ github.event.workflow_run.head_sha }}";
console.log("Finding PR for SHA:", head_sha);
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
const pr = prs.find(pr => pr.head.sha === head_sha);
if (pr) {
console.log("Found PR:", pr.number);
return pr.number;
} else {
core.setFailed("PR not found");
}
- name: Print Dispatch Info
run: |
echo "Actor: ${{ steps.payload.outputs.actor }}"
echo "PR Number: ${{ steps.pr_number.outputs.result || 'N/A' }}"
echo "Head Ref: ${{ steps.payload.outputs.head_ref }}"
echo "Head Sha: ${{ github.event.workflow_run.head_sha }}"
echo "Base Ref: ${{ steps.payload.outputs.base_ref }}"
- name: Checkout Head (${{ steps.payload.outputs.head_ref }})
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
persist-credentials: false
path: pr
- name: Checkout Base (${{ steps.payload.outputs.base_ref }})
uses: actions/checkout@v4
with:
ref: ${{ steps.payload.outputs.base_ref }}
persist-credentials: false
path: base
- name: Download EXDTools
uses: robinraju/release-downloader@v1
with:
repository: xivdev/EXDTools
fileName: "EXDTooler"
latest: true
- name: Chmod Executable
run: chmod +x EXDTooler
- name: Run Validation
id: validation
run: |
./EXDTooler --gha --debug --verbose validate -c base/.github/columns.yml -s pr -b base
- name: Write out summary
if: always()
env:
SUMMARY_CONTENT: ${{steps.validation.outputs.summary}}
run: |
echo "$SUMMARY_CONTENT" > summary.txt
cat summary.txt >> $GITHUB_STEP_SUMMARY
- uses: myrotvorets/set-commit-status-action@v2.0.1
if: always()
with:
sha: ${{ github.event.workflow_run.head_sha }}
context: Validate Schemas
status: ${{job.status}}
- name: Wipe previous comments (PR)
if: always() && steps.payload.outputs.event == 'pr'
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ steps.pr_number.outputs.result }}
with:
script: |
const pr = Number(process.env.PR_NUMBER);
const comments = (await github.rest.issues.listComments({
issue_number: pr,
owner: context.repo.owner,
repo: context.repo.repo
})).data
const comment = comments.filter(comment => comment.user.login === 'github-actions[bot]');
if (comment.length > 0) {
for (const c of comment) {
await github.graphql(`
mutation MinimizeComment($classifier: ReportedContentClassifiers!, $id: ID!) {
minimizeComment(input:{classifier: $classifier, subjectId: $id}) {
minimizedComment {
isMinimized
viewerCanMinimize
}
}
}
`, { classifier: 'OUTDATED', id: c.node_id });
}
}
- name: Post Validation Results (PR)
if: always() && steps.payload.outputs.event == 'pr'
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ steps.pr_number.outputs.result }}
with:
script: |
const summary = require('fs').readFileSync('summary.txt', 'utf-8');
const pr = Number(process.env.PR_NUMBER);
github.rest.issues.createComment({
issue_number: pr,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});