From 75e65b4d812e4109ca3f9c52e4f253f55faf558d Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Wed, 5 Nov 2025 17:30:02 -0500 Subject: [PATCH 1/2] Generate dist files on main branch This adapts an approach taken by the Gradle actions in order to generate the dist files on the main branch rather than having every contributor need to generate them. (In fact, people will no longer be able to submit PRs with the dist files updated). This change is important because the current approach means that people encounter merge conflicts all the time and will need to keep regenerating the dist files in order to land their change. --- .github/workflows/check-dist.yml | 71 +++++++++++----------------- .github/workflows/ci-update-dist.yml | 60 +++++++++++++++++++++++ 2 files changed, 87 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/ci-update-dist.yml diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 66bc632..0c17f38 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -1,57 +1,40 @@ -# `dist/index.js` is a special file in Actions. -# When you reference an action with `uses:` in a workflow, -# `index.js` is the code that will run. -# For our project, we generate this file through a build process from other source files. -# We need to make sure the checked-in `index.js` actually matches what we expect it to be. -name: Check dist/ +name: CI-check-no-dist-update +# Prohibit any change to 'dist/**' on a non-release branch on: - push: - branches: - - main - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' workflow_dispatch: + pull_request: + paths: + - 'dist/**' permissions: contents: read jobs: - check-dist: + fail-on-dist-update: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set Node.js 20.x - uses: actions/setup-node@v4 + - name: Checkout sources + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: - node-version: 20.x - cache: npm + fetch-depth: 0 - - name: Install dependencies - run: npm ci - - - name: Rebuild the dist/ directory - run: | - npm run build - npm run package - - - name: Compare the expected and actual dist/ directories - run: | - if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then - echo "Detected uncommitted changes after build. See status below:" - git diff - exit 1 - fi - id: diff - - # If index.js was different than expected, upload the expected version as an artifact - - uses: actions/upload-artifact@v4 - if: ${{ failure() && steps.diff.conclusion == 'failure' }} + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0 with: - name: dist - path: dist/ + files: | + dist/** + + - name: Print changes to dist directory + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + for file in ${ALL_CHANGED_FILES}; do + echo "$file was changed" + done + + - run: | + echo "The 'dist' directory is automatically updated by the release process." + echo "It should not be updated manually in a non-release branch or a pull request." + exit 1 diff --git a/.github/workflows/ci-update-dist.yml b/.github/workflows/ci-update-dist.yml new file mode 100644 index 0000000..be065ca --- /dev/null +++ b/.github/workflows/ci-update-dist.yml @@ -0,0 +1,60 @@ +name: CI-update-dist + +on: + workflow_dispatch: + push: + branches: + - 'main' + paths-ignore: + - 'dist/**' + +permissions: + contents: read + +jobs: + update-dist: + # Only run for the original DRA repository; otherwise when users create pull requests from their `main` branch + # it would erroneously update `dist` on their branch (and the pull request) + if: github.repository == 'actions/dependency-review-action' + permissions: + contents: write + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + token: ${{ secrets.BOT_GITHUB_TOKEN }} + + - name: Set up Node.js + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: 20 + cache: npm + cache-dependency-path: sources/package-lock.json + + - name: Install npm dependencies + run: | + npm clean-install + working-directory: sources + + - name: Build distribution + run: | + npm run build + npm run package + working-directory: sources + + - name: Copy the generated sources/dist directory to the top-level dist + run: | + cp -r sources/dist . + + # Commit and push changes; has no effect if the files did not change + # Important: The push event will not trigger any other workflows, see + # https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#commits-made-by-this-action-do-not-trigger-new-workflow-runs + - name: Commit & push changes + uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0 + with: + commit_author: 'github-actions[bot] ' + commit_user_name: 'github-actions[bot]' + commit_user_email: 'github-actions[bot]@users.noreply.github.com' + commit_message: '[bot] Update dist directory [skip ci]' + file_pattern: 'dist/' From 94004c34446b909ba0c79df1adfe66d519e6228b Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Wed, 5 Nov 2025 18:04:42 -0500 Subject: [PATCH 2/2] Remove dist directory change blocking We don't really need to prevent changes to the dist directory being committed. If someone does push a change to the dist directory, they'd be able to test with that. Plus the files will be regenerated on main, so that we know the final dist files are correct. This also fixes up some paths in the ci-update-dist.yml workflow which generates the dist files on main. --- .github/workflows/check-dist.yml | 40 ---------------------------- .github/workflows/ci-update-dist.yml | 7 ----- 2 files changed, 47 deletions(-) delete mode 100644 .github/workflows/check-dist.yml diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml deleted file mode 100644 index 0c17f38..0000000 --- a/.github/workflows/check-dist.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: CI-check-no-dist-update - -# Prohibit any change to 'dist/**' on a non-release branch -on: - workflow_dispatch: - pull_request: - paths: - - 'dist/**' - -permissions: - contents: read - -jobs: - fail-on-dist-update: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - fetch-depth: 0 - - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0 - with: - files: | - dist/** - - - name: Print changes to dist directory - env: - ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} - run: | - for file in ${ALL_CHANGED_FILES}; do - echo "$file was changed" - done - - - run: | - echo "The 'dist' directory is automatically updated by the release process." - echo "It should not be updated manually in a non-release branch or a pull request." - exit 1 diff --git a/.github/workflows/ci-update-dist.yml b/.github/workflows/ci-update-dist.yml index be065ca..a8f5b93 100644 --- a/.github/workflows/ci-update-dist.yml +++ b/.github/workflows/ci-update-dist.yml @@ -30,22 +30,15 @@ jobs: with: node-version: 20 cache: npm - cache-dependency-path: sources/package-lock.json - name: Install npm dependencies run: | npm clean-install - working-directory: sources - name: Build distribution run: | npm run build npm run package - working-directory: sources - - - name: Copy the generated sources/dist directory to the top-level dist - run: | - cp -r sources/dist . # Commit and push changes; has no effect if the files did not change # Important: The push event will not trigger any other workflows, see