Skip to content

Commit 63a5184

Browse files
committed
chore(ci): add linting
1 parent 49a40a4 commit 63a5184

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

.github/workflows/lifecycle.yml

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ concurrency: # FIXME: prevent release commit cancellation
2929

3030
jobs:
3131
release-please:
32+
if: github.event.action != 'closed'
3233
name: Release Please
3334
runs-on: blacksmith-2vcpu-ubuntu-2204
3435
outputs:
@@ -45,9 +46,109 @@ jobs:
4546
with:
4647
token: ${{ secrets.GITHUB_TOKEN }}
4748

49+
lint:
50+
name: Linters
51+
runs-on: blacksmith-2vcpu-ubuntu-2204
52+
#if: |
53+
# github.event.action != 'closed'
54+
# && !contains(github.actor, 'darcusk')
55+
env:
56+
APPLY_FIXES: all
57+
APPLY_FIXES_EVENT: all
58+
APPLY_FIXES_MODE: commit
59+
outputs:
60+
changes_detected: ${{ steps.autocommit.outputs.changes_detected }}
61+
commit_hash: ${{ steps.autocommit.outputs.commit_hash }}
62+
permissions:
63+
contents: write
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 1
69+
ref: ${{ github.head_ref }}
70+
71+
- name: Paths filter
72+
uses: dorny/paths-filter@v3.0.2
73+
id: filter
74+
with:
75+
list-files: shell
76+
filters: |
77+
addedOrModified:
78+
- added|modified: '**'
79+
80+
- name: Setup Python
81+
uses: useblacksmith/setup-python@v6
82+
with:
83+
python-version: "3.12"
84+
85+
- name: Cache pre-commit
86+
uses: useblacksmith/cache@v5
87+
with:
88+
path: ~/.cache/pre-commit
89+
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
90+
91+
- name: Install pre-commit
92+
shell: bash
93+
run: |
94+
python -m pip install pre-commit==4.0.1
95+
python -m pip freeze --local
96+
97+
- name: Run pre-commit
98+
id: precommit
99+
shell: bash
100+
run: |
101+
# Run against changes if addedOrModified is true, else run against all files
102+
if [[ "${{ steps.filter.outputs.addedOrModified }}" == "true" ]]; then
103+
pre-commit run --show-diff-on-failure --color=always --files "${{ steps.filter.outputs.addedOrModified_files }}" || RETRY="changes"
104+
else
105+
pre-commit run --show-diff-on-failure --color=always --all-files || RETRY="allfiles"
106+
fi
107+
108+
# Retry logic
109+
if [[ "$RETRY" == "changes" ]]; then
110+
pre-commit run --show-diff-on-failure --color=always --files "${{ steps.filter.outputs.addedOrModified_files }}"
111+
elif [[ "$RETRY" == "allfiles" ]]; then
112+
pre-commit run --show-diff-on-failure --color=always --all-files
113+
fi
114+
115+
- name: Run Mega-Linter
116+
if: ${{ !cancelled() }}
117+
uses: oxsecurity/megalinter/flavors/java@v8.3.0
118+
env:
119+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
120+
121+
- name: Archive production artifacts
122+
if: ${{ !cancelled() }}
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: Mega-Linter reports
126+
path: |
127+
megalinter-reports
128+
mega-linter.log
129+
130+
- name: Add reports directory to gitignore
131+
if: ${{ !cancelled() }}
132+
run: |
133+
touch .gitignore; grep -qxF 'megalinter-reports/' .gitignore ||
134+
echo 'megalinter-reports/' >> .gitignore
135+
wget https://raw.githubusercontent.com/packwiz/packwiz/refs/heads/main/go.sum
136+
137+
- name: Prepare commit
138+
if: ${{ !cancelled() }}
139+
run: sudo chown -Rc $UID .git/
140+
141+
- name: Commit and push applied linter fixes
142+
id: autocommit
143+
if: ${{ !cancelled() }}
144+
uses: stefanzweifel/git-auto-commit-action@v5.0.1
145+
with:
146+
branch: ${{ github.head_ref }}
147+
commit_message: "chore: apply linter fixes"
148+
48149
matrices:
49-
if: github.event.action != 'closed'
50150
name: Construct matrices
151+
if: github.job == 'notajob'
51152
needs: release-please
52153
runs-on: blacksmith-2vcpu-ubuntu-2204
53154
outputs:

0 commit comments

Comments
 (0)