-
Notifications
You must be signed in to change notification settings - Fork 5
166 lines (141 loc) · 5.88 KB
/
autofix-command.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
name: On-Demand AutoFix
on:
workflow_dispatch:
inputs:
pr:
description: "PR Number"
type: string
required: true
comment-id:
description: "Comment ID (Optional)"
type: string
required: false
jobs:
# This is copied from the `python_pytest.yml` file.
# Only the first two steps of the job are different, and they check out the PR's branch.
pr-fix-on-demand:
name: On-Demand PR Fix
# Don't run on forks. Run on pushes to main, and on PRs that are not from forks.
strategy:
matrix:
python-version: ["3.10"]
os: [Ubuntu]
fail-fast: false
runs-on: "${{ matrix.os }}-latest"
steps:
# Custom steps to fetch the PR and checkout the code:
- name: Checkout Airbyte
uses: actions/checkout@v4
with:
# Important that this is set so that CI checks are triggered again
# Without this we would be forever waiting on required checks to pass
token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }}
- name: Checkout PR (${{ github.event.inputs.pr }})
uses: dawidd6/action-checkout-pr@v1
with:
pr: ${{ github.event.inputs.pr }}
- name: Get PR info
id: pr-info
run: |
PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr }})
echo "repo=$(echo "$PR_JSON" | jq -r .head.repo.full_name)" >> $GITHUB_OUTPUT
echo "branch=$(echo "$PR_JSON" | jq -r .head.ref)" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
- name: Create URL to the run output
id: vars
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
- name: Append comment with job run link
id: first-comment-action
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.inputs.comment-id }}
issue-number: ${{ github.event.inputs.pr }}
body: |
> **Auto-Fix Job Info**
>
> This job attempts to auto-fix any linting or formating issues. If any fixes are made,
> those changes will be automatically committed and pushed back to the PR.
>
> Note: This job can only be run by maintainers. On PRs from forks, this command requires
> that the PR author has enabled the `Allow edits from maintainers` option.
> PR auto-fix job started... [Check job output.][1]
[1]: ${{ steps.vars.outputs.run-url }}
- name: Set up Poetry
uses: Gr1N/setup-poetry@v9
with:
poetry-version: "1.8.4"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: poetry install --all-extras
# Fix any lint or format issues
- name: Auto-Fix Ruff Lint Issues
run: poetry run ruff check --fix . || true
- name: Auto-Fix Ruff Format Issues
run: poetry run ruff format . || true
# Check for changes in git
- name: Check for changes
id: git-diff
run: |
git diff --quiet && echo "No changes to commit" || echo "changes=true" >> $GITHUB_OUTPUT
shell: bash
# Commit changes (if any)
- name: Commit changes
if: steps.git-diff.outputs.changes == 'true'
run: |
git config --global user.name "octavia-squidington-iii"
git config --global user.email "[email protected]"
git add .
git commit -m "Auto-fix lint and format issues"
# Fix any further 'unsafe' lint issues in a separate commit
- name: Auto-Fix Ruff Lint Issues (Unsafe)
run: poetry run ruff check --fix --unsafe-fixes . || true
- name: Auto-Fix Ruff Format Issues
run: poetry run ruff format . || true
# Check for changes in git (2nd time, for 'unsafe' lint fixes)
- name: Check for changes ('unsafe' fixes)
id: git-diff-2
run: |
git diff --quiet && echo "No changes to commit" || echo "changes=true" >> $GITHUB_OUTPUT
shell: bash
- name: Commit 'unsafe' lint fixes
if: steps.git-diff-2.outputs.changes == 'true'
run: |
git config --global user.name "octavia-squidington-iii"
git config --global user.email "[email protected]"
git add .
git commit -m "Auto-fix lint issues (unsafe)"
- name: Push changes to '(${{ steps.pr-info.outputs.repo }})'
if: steps.git-diff.outputs.changes == 'true' || steps.git-diff-2.outputs.changes == 'true'
run: |
git remote add contributor https://github.com/${{ steps.pr-info.outputs.repo }}.git
git push contributor HEAD:${{ steps.pr-info.outputs.branch }}
- name: Append success comment
uses: peter-evans/create-or-update-comment@v4
if: steps.git-diff.outputs.changes == 'true' || steps.git-diff-2.outputs.changes == 'true'
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: hooray
body: |
> ✅ Changes applied successfully.
- name: Append success comment (no-op)
uses: peter-evans/create-or-update-comment@v4
if: steps.git-diff.outputs.changes != 'true' && steps.git-diff-2.outputs.changes != 'true'
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: "+1"
body: |
> 🟦 Job completed successfully (no changes).
- name: Append failure comment
uses: peter-evans/create-or-update-comment@v4
if: failure()
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: confused
body: |
> ❌ Job failed.