Skip to content

Commit fe475a5

Browse files
authored
Merge pull request #3274 from codecrafters-io/ci-separate-lint-workflow
ci: move lint workflow to a dedicated lint.yml file
2 parents 025c7fe + d34ee72 commit fe475a5

File tree

2 files changed

+83
-26
lines changed

2 files changed

+83
-26
lines changed

.github/workflows/lint.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
runs-on: depot-ubuntu-24.04-16
16+
permissions:
17+
contents: write
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
persist-credentials: false
22+
# Ensure we are on an actual branch (not a detached HEAD)
23+
ref: ${{ github.head_ref || github.ref }}
24+
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: '22'
28+
29+
# Caching node_modules is faster than using setup-node's cache: 'npm' (https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/)
30+
- id: cache
31+
name: Cache dependencies
32+
uses: actions/cache@v4
33+
with:
34+
path: ./node_modules
35+
key: modules-v2-${{ hashFiles('package-lock.json') }}
36+
37+
- name: Install dependencies
38+
if: steps.cache.outputs.cache-hit != 'true'
39+
run: npm ci --ignore-scripts
40+
41+
- name: Run linter
42+
id: lint
43+
continue-on-error: true
44+
run: npm run lint
45+
46+
- name: Auto-fix with linter
47+
if: steps.lint.outcome == 'failure'
48+
run: npm run lint:fix
49+
50+
- name: Show diff, commit and push fixes (non-master/main only)
51+
if: |
52+
steps.lint.outcome == 'failure' &&
53+
github.ref != 'refs/heads/master' &&
54+
github.ref != 'refs/heads/main' &&
55+
(github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
56+
run: |
57+
BRANCH="${{ github.head_ref || github.ref_name }}"
58+
echo "Preparing to push fixes to $BRANCH"
59+
60+
# Ensure we're on a branch, not detached HEAD
61+
git checkout -B "$BRANCH"
62+
63+
git config user.name "codecrafters-bot"
64+
git config user.email "[email protected]"
65+
66+
# Only commit if there are changes
67+
if ! git diff --quiet; then
68+
echo "Auto-fix diff (before commit):"
69+
git --no-pager diff
70+
git add -A
71+
git commit -m "chore(lint): auto-fix lint offenses"
72+
git remote set-url origin "https://x-access-token:${{ secrets.CODECRAFTERS_BOT_TOKEN_FOR_LINT_FIXES }}@github.com/${{ github.repository }}.git"
73+
git push origin HEAD:"$BRANCH"
74+
else
75+
echo "No changes to commit"
76+
fi
77+
78+
- name: Fail if linting failed
79+
if: steps.lint.outcome == 'failure'
80+
run: |
81+
echo "Linting failed. Auto-fixes (if any) have been pushed back to the branch. Failing the job to keep visibility."
82+
exit 1
83+

.github/workflows/test.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,3 @@ jobs:
115115
files: test-results.xml
116116
seconds_between_github_writes: 0.01
117117
seconds_between_github_reads: 0.01
118-
119-
lint:
120-
runs-on: depot-ubuntu-24.04-16
121-
# Use cheaper machines for dependabot if we're low on namespace credits
122-
# runs-on: ${{ github.actor == 'dependabot[bot]' && 'namespace-profile-frontend-light' || 'namespace-profile-frontend' }}
123-
124-
steps:
125-
- uses: actions/checkout@v3
126-
127-
- uses: actions/setup-node@v4
128-
with:
129-
node-version: '22'
130-
131-
# Caching node_modules is faster than using setup-node's cache: 'npm' (https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/)
132-
- id: cache
133-
name: Cache dependencies
134-
uses: actions/cache@v4
135-
with:
136-
path: ./node_modules
137-
key: modules-v2-${{ hashFiles('package-lock.json') }}
138-
139-
- name: Install dependencies
140-
if: steps.cache.outputs.cache-hit != 'true'
141-
run: npm ci --ignore-scripts
142-
143-
- run: npm run lint

0 commit comments

Comments
 (0)