|
7 | 7 |
|
8 | 8 | jobs: |
9 | 9 | npm_audit: |
10 | | - runs-on: ubuntu-latest |
11 | | - |
12 | | - steps: |
13 | | - - name: Checkout code |
14 | | - uses: actions/checkout@v4 |
15 | | - |
16 | | - - name: Run npm audit |
17 | | - id: npm_audit |
18 | | - run: | |
19 | | - find public/modules/custom public/themes/custom -type f -name ".nvmrc" -exec sh -c ' |
20 | | - dir=$(dirname "$1") |
21 | | - node_version=$(cat "$1") |
22 | | - echo "Using Node.js version $node_version in $dir" |
23 | | - cd "$dir" |
24 | | - export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" |
25 | | - nvm install $node_version |
26 | | - nvm use $node_version |
27 | | - set +e |
28 | | - npm audit --package-lock-only --loglevel=error; |
29 | | - # The npm audit command will exit with a 0 exit code if no vulnerabilities were found. |
30 | | - if [ $? -gt 0 ]; then |
31 | | - npm audit fix --package-lock-only --loglevel=error; |
32 | | - if [ $? -gt 0 ]; then |
33 | | - echo "BC_BREAK=:exclamation: NPM Audit fix could not fix all vulnerabilities. Fix them manually by running \`npm audit fix --force\` and test the functionalities thoroughly as there might be breaking changes. :exclamation:" >> $GITHUB_ENV; |
34 | | - fi; |
35 | | - echo "CREATE_PR=true" >> $GITHUB_OUTPUT; |
36 | | - fi; |
37 | | - set -e |
38 | | - ' sh {} \; |
39 | | -
|
40 | | -
|
41 | | - - name: Create Pull Request |
42 | | - if: steps.npm_audit.outputs.CREATE_PR == 'true' |
43 | | - uses: peter-evans/create-pull-request@v4 |
44 | | - with: |
45 | | - committer: GitHub <noreply@github.com> |
46 | | - author: actions-bot <actions-bot@users.noreply.github.com> |
47 | | - commit-message: Updated node modules based on npm audit fix |
48 | | - title: Automatic npm audit fix |
49 | | - labels: auto-update |
50 | | - body: | |
51 | | - # Npm audit |
52 | | -
|
53 | | - ${{ env.BC_BREAK }} |
54 | | -
|
55 | | - ## How to install |
56 | | -
|
57 | | - * Update the HDBT theme |
58 | | - * `git fetch --all` |
59 | | - * `git checkout automation/npm-audit` |
60 | | - * `git pull origin automation/npm-audit` |
61 | | - * In the custom module or custom theme folder, run `nvm use && npm i && npm run build` |
62 | | -
|
63 | | - ## How to test |
64 | | - Run `npm audit` |
65 | | -
|
66 | | - * [ ] Check that the `npm audit` prints `found 0 vulnerabilities` |
67 | | - * [ ] Check that the changes for distributed files are sensible |
68 | | -
|
69 | | - branch: automation/npm-audit |
| 10 | + uses: city-of-helsinki/drupal-gh-actions/.github/workflows/npm-audit.yml@main |
0 commit comments