-
Notifications
You must be signed in to change notification settings - Fork 264
130 lines (116 loc) · 4.47 KB
/
update-rli-commands.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
name: Update RLIs - Comment Commands
on:
issue_comment:
types: [ created ]
jobs:
check-rli:
if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '\inspector')
runs-on: ubuntu-latest
steps:
# ---- Find Trigger States ----
# Run Inspector autofix on everything
- name: Trigger-Check
uses: shanegenschaw/[email protected]
id: trigger-check-all
with:
trigger: '\inspector check all'
prefix_only: true
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
# Run Inspector autofix only on files changed by the PR
- name: Trigger-Diff
uses: shanegenschaw/[email protected]
id: trigger-diff
with:
trigger: '\inspector fix diff'
prefix_only: true
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
# Run Inspector autofix on everything
- name: Trigger-All
uses: shanegenschaw/[email protected]
id: trigger-all
with:
trigger: '\inspector fix all'
prefix_only: true
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
# If this is a comment without a command, exit.
- name: Quick exit
if: ${{ !steps.trigger-all.outputs.triggered && !steps.trigger-check-all.outputs.triggered && !steps.trigger-diff.outputs.triggered }}
run: exit 1
- name: Checkout [Common]
uses: actions/checkout@v4
- name: Checkout PR [Comment]
run: gh pr checkout $NUMBER
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
NUMBER: ${{ github.event.issue.number }}
# ---- Common - Run ----
# Remove unchanged files, unless explicitly triggered on everything
- name: Remove unchanged files
if: steps.trigger-all.outputs.triggered == 'false' && steps.trigger-check-all.outputs.triggered == 'false'
run: |
# Fetch upstream
git remote add upstream https://github.com/wpilibsuite/frc-docs.git
git fetch upstream
# Delete unchanged files
git ls-files -- *.rst | xargs rm
git diff upstream/main..HEAD --name-only --diff-filter=M -- *.rst | xargs -I{} git restore {}
# Make sure we still have the .github directory
git restore .github
# Run Inspector
- name: Inspect RLIs
uses: docker://ghcr.io/starlight220/inspector:v1.9
id: inspector
with:
root: ${{ github.workspace }}
env:
INSPECTOR_CONFIG: '.github/workflows/inspector.json'
# If diff-autofix is triggered, restore temporarily deleted files
- name: Restore unchanged files
# No point in restoring if we're not using them
if: steps.trigger-diff.outputs.triggered == 'true'
run: |
git diff --name-only --diff-filter=D | xargs -I{} git restore {}
# If autofix is triggered, commit changes
- name: Commit
if: steps.trigger-all.outputs.triggered == 'true' || steps.trigger-diff.outputs.triggered == 'true'
run: |
# Set credentials
git config user.name github-actions
git config user.email [email protected]
git diff --name-only --diff-filter=Md | xargs -I{} git add {}
# Commit
git commit -m "Autofix RLIs"
git push
# ---- Common - Post Report ----
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.issue.number }}
comment-author: 'github-actions[bot]'
body-includes: Inspector Report
direction: last
- name: Create comment
if: ${{ steps.fc.outputs.comment-id == 0 }}
uses: peter-evans/create-or-update-comment@v4
with:
body: ${{ env.REPORT }}
issue-number: ${{ github.event.issue.number }}
- name: Update comment
if: ${{ steps.fc.outputs.comment-id != 0 }}
uses: peter-evans/create-or-update-comment@v4
with:
body: |
${{ env.REPORT }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
# If there are any outdated or invalid RLIs, fail the status check
- name: Set exit code
if: ${{ steps.inspector.outputs.up-to-date == false }}
run: exit 1