|
| 1 | +name: autorun-npm-audit-fix |
| 2 | +run-name: Automatically run npm audit fix |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '45 08 1 * *' # Run at 1:45 AM PDT on the 1st of every month |
| 6 | +jobs: |
| 7 | + autorun-npm-audit-fix: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: write |
| 11 | + defaults: |
| 12 | + run: |
| 13 | + shell: bash |
| 14 | + working-directory: ./ |
| 15 | + steps: |
| 16 | + - name: Check out repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + - name: Set up node |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: '18' |
| 22 | + - name: Get whether autorun-npm-audit-fix branch exists |
| 23 | + run: | |
| 24 | + echo "Getting whether autorun-npm-audit-fix branch exists" |
| 25 | + git config user.name github-actions |
| 26 | + git config user.email [email protected] |
| 27 | + { |
| 28 | + echo 'git_ls_remote_origin_autorun_npm_audit_fix<<EOF' |
| 29 | + git ls-remote origin autorun-npm-audit-fix |
| 30 | + echo EOF |
| 31 | + } >> "$GITHUB_OUTPUT" |
| 32 | + id: run_git_ls_remote_origin_autorun_npm_audit_fix |
| 33 | + - name: Delete autorun-npm-audit-fix if it exists |
| 34 | + if: ${{ contains(steps.run_git_ls_remote_origin_autorun_npm_audit_fix.outputs.git_ls_remote_origin_autorun_npm_audit_fix, '/autorun-npm-audit-fix') }} |
| 35 | + run: | |
| 36 | + echo "Deleting remote autorun-npm-audit-fix branch" |
| 37 | + git push origin --delete autorun-npm-audit-fix |
| 38 | + - name: Run npm audit fix |
| 39 | + run: | |
| 40 | + echo "Running npm audit fix (breaking changes will need to be addressed manually)" |
| 41 | + npm audit fix || true |
| 42 | + - name: Add any changes |
| 43 | + run: | |
| 44 | + echo "Determining if there are any changes" |
| 45 | + git config user.name github-actions |
| 46 | + git config user.email [email protected] |
| 47 | + git checkout -b autorun-npm-audit-fix |
| 48 | + git add . |
| 49 | + - name: Run git status |
| 50 | + run: | |
| 51 | + { |
| 52 | + echo 'git_status<<EOF' |
| 53 | + git status |
| 54 | + echo EOF |
| 55 | + } >> "$GITHUB_OUTPUT" |
| 56 | + id: run_git_status |
| 57 | + - name: Commit and push changes if any |
| 58 | + if: ${{ !contains(steps.run_git_status.outputs.git_status, 'nothing to commit, working tree clean') }} |
| 59 | + run: | |
| 60 | + echo "Committing and pushing changes to autorun-npm-audit-fix branch" |
| 61 | + git commit -m "Automatically run npm audit fix" |
| 62 | + git push --set-upstream origin autorun-npm-audit-fix |
0 commit comments