Skip to content

Commit 0bffdf6

Browse files
authored
Update eslint.yml for yarn support
1 parent 00243ab commit 0bffdf6

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

.github/workflows/eslint.yml

+39-21
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
# ESLint is a tool for identifying and reporting on patterns
6-
# found in ECMAScript/JavaScript code.
7-
# More details at https://github.com/eslint/eslint
8-
# and https://eslint.org
9-
101
name: ESLint
112

123
on:
134
push:
145
branches: ["main"]
156
pull_request:
16-
# The branches below must be a subset of the branches above
177
branches: ["main"]
188
schedule:
199
- cron: "25 21 * * 4"
2010

2111
jobs:
2212
eslint:
23-
name: Run eslint scanning
13+
name: Run ESLint Scanning
2414
runs-on: ubuntu-latest
2515
permissions:
2616
contents: read
2717
security-events: write
28-
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
18+
actions: read
2919
steps:
3020
- name: Checkout code
3121
uses: actions/checkout@v3
3222

33-
- name: Install ESLint
23+
- name: Detect package manager
24+
id: detect-package-manager
25+
run: |
26+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
27+
echo "manager=yarn" >> $GITHUB_OUTPUT
28+
echo "install-command=install" >> $GITHUB_OUTPUT
29+
echo "runner=yarn" >> $GITHUB_OUTPUT
30+
exit 0
31+
elif [ -f "${{ github.workspace }}/package-lock.json" ]; then
32+
echo "manager=npm" >> $GITHUB_OUTPUT
33+
echo "install-command=ci" >> $GITHUB_OUTPUT
34+
echo "runner=npx" >> $GITHUB_OUTPUT
35+
exit 0
36+
else
37+
echo "Unable to determine package manager"
38+
exit 1
39+
fi
40+
41+
- name: Setup Node.js
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: "20"
45+
cache: ${{ steps.detect-package-manager.outputs.manager }}
46+
47+
- name: Install dependencies
48+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.install-command }}
49+
50+
- name: Install ESLint dependencies
3451
run: |
35-
npm install [email protected]
36-
npm install @microsoft/[email protected]
52+
${{ steps.detect-package-manager.outputs.manager }} add [email protected]
53+
${{ steps.detect-package-manager.outputs.manager }} add @microsoft/[email protected]
3754
3855
- name: Run ESLint
39-
run: npx eslint .
40-
--config .eslintrc.cjs
41-
--ext .js,.jsx,.ts,.tsx
42-
# --format @microsoft/eslint-formatter-sarif
43-
# --output-file eslint-results.sarif
44-
# continue-on-error: false
56+
run: |
57+
${{ steps.detect-package-manager.outputs.runner }} eslint . \
58+
--config .eslintrc.cjs \
59+
--ext .js,.jsx,.ts,.tsx
60+
# --format @microsoft/eslint-formatter-sarif
61+
# --output-file eslint-results.sarif
4562

63+
# Uncomment the following step to upload SARIF results
4664
# - name: Upload analysis results to GitHub
4765
# uses: github/codeql-action/upload-sarif@v2
4866
# with:

0 commit comments

Comments
 (0)