From cfe3d81cb53b03b68152e711e31f02f9baf4fc06 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Mon, 24 Apr 2023 12:11:49 -0700 Subject: [PATCH] Add workflow to automatically build for npm changes --- .github/workflows/check-dist.yml | 1 + .github/workflows/dependabot-build.yml | 70 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 .github/workflows/dependabot-build.yml diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 99c1f04..2c6f6b5 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -15,6 +15,7 @@ on: paths-ignore: - '**.md' workflow_dispatch: + workflow_call: jobs: check-dist: diff --git a/.github/workflows/dependabot-build.yml b/.github/workflows/dependabot-build.yml new file mode 100644 index 0000000..29972ac --- /dev/null +++ b/.github/workflows/dependabot-build.yml @@ -0,0 +1,70 @@ +name: Run build for dependabot PRs + +on: + pull_request: + types: [opened, synchronize] + +permissions: + contents: write + pull-requests: read + +defaults: + run: + shell: bash + +jobs: + build: + if: ${{ github.actor == 'dependabot[bot]' }} + runs-on: ubuntu-latest + outputs: + update: ${{ steps.commit.outputs.update }} + steps: + - name: Fetch Dependabot metadata + id: dependabot-metadata + uses: dependabot/fetch-metadata@v1 + + - uses: actions/checkout@v3 + if: ${{ steps.dependabot-metadata.outputs.package-ecosystem == 'npm_and_yarn' }} + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Node.js 16.x + if: ${{ steps.dependabot-metadata.outputs.package-ecosystem == 'npm_and_yarn' }} + uses: + actions/setup-node@v3 + with: + node-version: 16.x + + - name: Install dependencies + if: ${{ steps.dependabot-metadata.outputs.package-ecosystem == 'npm_and_yarn' }} + run: npm ci + + - name: Run build + if: ${{ steps.dependabot-metadata.outputs.package-ecosystem == 'npm_and_yarn' }} + run: | + npm run build + npm run package + + - name: Check if dist/ needs to be updated + id: commit + if: ${{ steps.dependabot-metadata.outputs.package-ecosystem == 'npm_and_yarn' }} + run: | + update=false + if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then + echo "Detected uncommitted changes after build." + git config user.name "Luca Comellini" + git config user.email "${{ secrets.EMAIL }}}}" + git remote set-url origin https://x-access-token:${{ secrets.COMMIT_PAT }}@github.com/$GITHUB_REPOSITORY + + git add dist/ + git commit -m "Update dist/ for dependabot" + git push -u origin HEAD:${{ github.event.pull_request.head.ref }} + update=true + fi + echo "update=$update" >> $GITHUB_OUTPUT + + check-dist: + name: Call check-dist + needs: build + if: ${{ needs.build.outputs.update == 'true' }} + uses: ./.github/workflows/check-dist.yml