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/'