Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-9380: Npm audit action #889

Merged
merged 60 commits into from
Jan 30, 2024
Merged
Changes from 52 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7c6d0d1
UHF-9380: Added a github action to run NPM Audit on Sundays in every …
khalima Jan 23, 2024
a1d15d3
UHF-9380: Switched npm-audit branch to automation/npm-audit.
khalima Jan 23, 2024
d5dbf34
UHF-9380: Fixed indentation.
khalima Jan 23, 2024
1a9aaa5
UHF-9380: Build NodeJS manually.
khalima Jan 23, 2024
f30610a
UHF-9380: Path change for the PR template.
khalima Jan 23, 2024
9b0f264
UHF-9380: Switched the deprecated set-output command to GITHUB_OUTPUT.
khalima Jan 23, 2024
45b817a
UHF-9380: Use peter-evans/create-pull-request instead of manually mad…
khalima Jan 23, 2024
49be2af
UHF-9380: Added workflow dispatch for testing purposes.
khalima Jan 23, 2024
e83d03f
UHF-9380: Trigger on UHF-9380 branch push.
khalima Jan 23, 2024
783ce7c
UHF-9380: Retrieve the PR template from URL.
khalima Jan 23, 2024
a1e962e
UHF-9380: Add pull request template via variable.
khalima Jan 23, 2024
cf0d1d7
UHF-9380: UHF-9380: Use text instead of a template.
khalima Jan 23, 2024
c4e5ad3
UHF-9380: Remove the step for retrieving the template file.
khalima Jan 23, 2024
5e737cf
UHF-9380: Removed obsolete template.
khalima Jan 23, 2024
4b0110a
UHF-9380: Updated the PR instructions.
khalima Jan 23, 2024
e0cc1b6
UHF-9380: Create PR only if there are changes.
khalima Jan 23, 2024
db059e7
UHF-9380: Fixed logical error from npm_audit step.
khalima Jan 23, 2024
4449b87
UHF-9380: Fixed typo.
khalima Jan 23, 2024
8ff96a7
UHF-9380: Fixed npm audit script.
khalima Jan 23, 2024
3d1056c
UHF-9380: Switched the Github variable.
khalima Jan 23, 2024
b4a3dba
UHF-9380: Move the npm audit fix to its' own step.
khalima Jan 23, 2024
6c95389
UHF-9380: Converted if statement to oneliner.
khalima Jan 23, 2024
5e2bb98
UHF-9380: Removed conditional set of variable create_pr.
khalima Jan 23, 2024
c0ea6ea
UHF-9380: Debugging...
khalima Jan 23, 2024
cbc1906
UHF-9380: Debugging...
khalima Jan 23, 2024
d6ac08d
UHF-9380: Debugging...
khalima Jan 23, 2024
eca3ea1
UHF-9380: Debugging...
khalima Jan 23, 2024
c3c1052
UHF-9380: Debugging...
khalima Jan 23, 2024
acf3b77
UHF-9380: Debugging...
khalima Jan 23, 2024
2e5f059
UHF-9380: Debugging...
khalima Jan 23, 2024
bfe2a08
UHF-9380: Debugging...
khalima Jan 23, 2024
288f248
UHF-9380: Debugging...
khalima Jan 23, 2024
c17da4c
UHF-9380: Debugging...
khalima Jan 23, 2024
e3c7474
UHF-9380: Debugging...
khalima Jan 24, 2024
672bd08
UHF-9380: Debugging...
khalima Jan 24, 2024
42d07ec
UHF-9380: Merge branch 'main' of https://github.com/City-of-Helsinki/…
khalima Jan 24, 2024
6c829d9
UHF-9380: Added a branch for testing purposes.
khalima Jan 24, 2024
78862ef
UHF-9380: Fixed logical error during npm audit fix.
khalima Jan 24, 2024
6604182
UHF-9380: Continue if the NPM audit returns exit code 1.
khalima Jan 24, 2024
bd95dcf
UHF-9380: Debugging...
khalima Jan 24, 2024
6d61b30
UHF-9380: Debugging...
khalima Jan 24, 2024
d3ac531
UHF-9380: Debugging...
khalima Jan 24, 2024
4a47f00
UHF-9380: Debugging...
khalima Jan 24, 2024
52b6d4b
UHF-9380: Debugging...
khalima Jan 24, 2024
e6c0e97
UHF-9380: Debugging...
khalima Jan 24, 2024
54fe3d1
UHF-9380: Debugging...
khalima Jan 24, 2024
6223a7f
UHF-9380: Debugging...
khalima Jan 24, 2024
4d31be1
UHF-9380: Debugging...
khalima Jan 24, 2024
d5df978
UHF-9380: Removed testing branch.
khalima Jan 24, 2024
94d2ef4
UHF-9380: Removed testing triggers.
khalima Jan 24, 2024
82dca47
UHF-9380: Changed the naming convention of the github action to match…
khalima Jan 24, 2024
d102a9a
UHF-9380: Fixed naming conventions for npm.
khalima Jan 24, 2024
e41673e
UHF-9380: Testing NVM without retrieving it.
khalima Jan 25, 2024
0d1ef49
UHF-9380: Added a note of breaking changes.
khalima Jan 25, 2024
96c10ec
UHF-9380: Added PR warning text as a conditional block.
khalima Jan 25, 2024
aae05b3
UHF-9380: Debugging...
khalima Jan 25, 2024
9ede0f3
UHF-9380: Debugging...
khalima Jan 25, 2024
66ac192
UHF-9380: Removed traces of testing branches.
khalima Jan 25, 2024
c74f270
UHF-9380: Simplified npm audit action.
khalima Jan 29, 2024
624cec8
UHF-9380: More descriptive step name for the npm audit.
khalima Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/npm-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Npm audit

on:
schedule:
- cron: '0 12 * * 0' # Run every fortnight on Sunday at 12

jobs:
npm_audit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js, install dependencies
run: |
node_version=$(cat .nvmrc)
echo "Using Node.js version $node_version"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install $node_version
nvm use $node_version
npm install --silent

- name: Check for vulnerabilities
id: npm_audit
run: |
set +e
npm audit --package-lock-only --loglevel=error;

# The npm audit command will exit with a 0 exit code if no vulnerabilities were found.
if [ $? -eq 0 ]; then echo "CREATE_PR=false" >> $GITHUB_OUTPUT; else echo "CREATE_PR=true" >> $GITHUB_OUTPUT; fi;
set -e

- name: Run npm audit fix
if: steps.npm_audit.outputs.CREATE_PR == 'true'
run: npm audit fix --package-lock-only --loglevel=error;

- name: Create Pull Request
if: steps.npm_audit.outputs.CREATE_PR == 'true'
uses: peter-evans/create-pull-request@v4
with:
committer: GitHub <noreply@github.com>
author: actions-bot <actions-bot@users.noreply.github.com>
commit-message: Updated node modules based on npm audit fix
title: Automatic npm audit fix
labels: auto-update
body: |
# Npm audit
## How to install

* Update the HDBT theme
* `git fetch --all`
* `git checkout automation/npm-audit`
* `git pull origin automation/npm-audit`
* In theme folder, run `nvm use && npm i && npm run build`

## How to test
Run `npm audit`

* [ ] Check that the `npm audit` prints `found 0 vulnerabilities`
* [ ] Check that the changes for distributed files are sensible

branch: automation/npm-audit