From 191e390ca2499865efc6e804010a06aa09cafa53 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Wed, 20 Sep 2023 17:37:00 +0200 Subject: [PATCH] .github: add dependabot integration Dependabot creates a PR for us so we have to introduce a new action which updates node-modules for us. --- .github/dependabot.yml | 22 +++++++++ .github/workflows/dependabot.yml | 83 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..52ad58b55 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" + labels: + - "node_modules" + - "no-test" + groups: + eslint: + patterns: + - "eslint*" + esbuild: + patterns: + - "esbuild*" + stylelint: + patterns: + - "stylelint*" + patternfly: + patterns: + - "@patternfly*" diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 000000000..6647a1cab --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,83 @@ +name: Update node_modules +on: + pull_request_target: + types: [opened, reopened, synchronize, labeled] + +jobs: + dependabot: + environment: npm-update + permissions: + contents: read + pull-requests: write + timeout-minutes: 5 + # 22.04's podman has issues with piping and causes tar errors + runs-on: ubuntu-20.04 + if: ${{ contains(github.event.pull_request.labels.*.name, 'node_modules') }} + + steps: + - name: Clone repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + fetch-depth: 0 + + - name: Clear node_modules label + uses: actions/github-script@v6 + with: + script: | + try { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + name: 'node_modules' + }); + } catch (e) { + if (e.name == 'HttpError' && e.status == 404) { + /* expected: 404 if label is unset */ + } else { + throw e; + } + } + + - name: Update node_modules for package.json changes + run: | + make tools/node-modules + git config --global user.name "GitHub Workflow" + git config --global user.email "cockpituous@cockpit-project.org" + eval $(ssh-agent) + ssh-add - <<< '${{ secrets.NODE_CACHE_DEPLOY_KEY }}' + ./tools/node-modules install + ./tools/node-modules push + git add node_modules + ssh-add -D + ssh-agent -k + + - name: Clear no-test label + uses: actions/github-script@v6 + with: + script: | + try { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + name: 'no-test' + }); + } catch (e) { + if (e.name == 'HttpError' && e.status == 404) { + /* expected: 404 if label is unset */ + } else { + throw e; + } + } + + - name: Force push node_modules update + run: | + git commit --amend --no-edit node_modules + eval $(ssh-agent) + ssh-add - <<< '${{ secrets.SELF_DEPLOY_KEY }}' + git push --force 'git@github.com:${{ github.repository }}' '${{ github.head_ref }}' + ssh-add -D + ssh-agent -k