Repository navigation
133 lines (124 loc) · 4.62 KB
/
Copy pathpython-fix.yaml
File metadata and controls
133 lines (124 loc) · 4.62 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
name: Python Fix
run-name: "${{ github.actor }} fixing Python code"
"on":
issue_comment:
types:
- created
workflow_dispatch:
inputs:
ref:
description:
"The branch name to checkout and push fixes to (must be a branch, not a commit SHA). Defaults to the
repository's default branch."
required: false
type: string
workflow_call:
inputs:
checkout-path:
description: "Path to check out code to"
required: false
type: string
ref:
description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)"
required: true
type: string
repo:
description: "The repository to checkout from"
required: true
type: string
skip-comment:
description: "Skip posting PR comments"
required: false
type: boolean
default: false
outputs:
changes:
description: "Whether any fixes were applied"
value: ${{ jobs.apply_fixes.outputs.changes }}
pushed:
description: "Whether the fixes were pushed to the remote branch"
value: ${{ jobs.apply_fixes.outputs.pushed }}
commit_sha:
description: "The full commit SHA of the applied fixes"
value: ${{ jobs.apply_fixes.outputs.commit_sha }}
commit_sha_short:
description: "The short commit SHA of the applied fixes"
value: ${{ jobs.apply_fixes.outputs.commit_sha_short }}
patch_name:
description: "Name of the patch file if fixes could not be pushed"
value: ${{ jobs.apply_fixes.outputs.patch_name }}
permissions:
pull-requests: write
contents: write
issues: write
jobs:
setup:
runs-on: ubuntu-latest
name: Parse command
if: >
inputs.ref != '' || github.event_name == 'workflow_dispatch' || (
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER", "COLLABORATOR", "MEMBER"]'), github.event.comment.author_association) &&
startsWith(github.event.comment.body, format('@{0}bot python-fix', github.event.repository.name))
)
outputs:
ref: ${{ steps.setup.outputs.ref }}
repo: ${{ steps.setup.outputs.repo }}
checkout_path: ${{ steps.setup.outputs.checkout_path }}
steps:
- name: Workflow setup
id: setup
uses: Framework-R-D/action-workflow-setup@f73307dd8c13cb66c2565c9ace32571517b1cea8 # v1
with:
mode: fix
ref: ${{ inputs.ref }}
repo: ${{ inputs.repo }}
checkout-path: ${{ inputs.checkout-path }}
apply_fixes:
runs-on: ubuntu-latest
name: Apply fixes
needs: setup
if: needs.setup.result == 'success'
outputs:
changes: ${{ steps.handle_commit.outputs.changes }}
pushed: ${{ steps.handle_commit.outputs.pushed }}
commit_sha: ${{ steps.handle_commit.outputs.commit_sha }}
commit_sha_short: ${{ steps.handle_commit.outputs.commit_sha_short }}
patch_name: ${{ steps.handle_commit.outputs.patch_name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: ${{ needs.setup.outputs.checkout_path }}
ref: ${{ needs.setup.outputs.ref }}
repository: ${{ needs.setup.outputs.repo }}
token: ${{ secrets.WORKFLOW_PAT }}
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
- name: Install Python dependencies
run: uv tool install ruff
- name: Run ruff format and fix
working-directory: ${{ needs.setup.outputs.checkout_path }}
env:
FORCE_COLOR: 1
run: |
echo "Fixing Python format with ruff"
ruff format . || true
echo "Fixing Python linter issues with ruff"
ruff check --fix . || true
- name: Handle fix commit
id: handle_commit
uses: Framework-R-D/action-handle-fix-commit@c01368081dd06cbe5ef47b4a085dc6359a657a7f # v2
with:
tool: ruff
working-directory: ${{ needs.setup.outputs.checkout_path }}
token: ${{ secrets.WORKFLOW_PAT }}
pr-info-ref: ${{ needs.setup.outputs.ref }}
pr-info-repo: ${{ needs.setup.outputs.repo }}
skip-comment: ${{ inputs.skip-comment }}
- name: Update PR comment reactions
if: always() && github.event_name == 'issue_comment' && !inputs.skip-comment
uses: Framework-R-D/action-complete-pr-comment@5d16749c32fbb7b15503f264dde6e3c98b90b4fb # v2
with:
status: ${{ job.status }}