diff --git a/.eslintignore b/.eslintignore index 21869472..86bb4716 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ dist/ +action/ lib/ -node_modules/ \ No newline at end of file +node_modules/ diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml deleted file mode 100644 index 7af4189b..00000000 --- a/.github/workflows/check-dist.yml +++ /dev/null @@ -1,51 +0,0 @@ -# `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 directory - -on: - push: - branches: - - main - - releases/** - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - workflow_dispatch: - -jobs: - check-dist: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 20 - - name: Build - run: | - npm -v - node -v - npm clean-install - npm run build - - - 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' }} - with: - name: dist - path: dist/ diff --git a/.github/workflows/check-pull-request-no-dist-change.yml b/.github/workflows/check-pull-request-no-dist-change.yml new file mode 100644 index 00000000..20fb779c --- /dev/null +++ b/.github/workflows/check-pull-request-no-dist-change.yml @@ -0,0 +1,22 @@ +# Pull request authors are not expected to update `action/index.js` themselves +name: Check no dist update +on: + pull_request: + # For simplicity determine if the file was changed using `paths` here (instead of running any diff command below) + # There are some limitations to this, but they most likely won't cause any issues here + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#git-diff-comparisons + paths: + - 'action/index.js' + +jobs: + check-no-dist-update: + name: Check no dist update + runs-on: ubuntu-latest + + steps: + - name: Check no dist update + # Fail unconditionally; this workflow is only run if the file has changed, see + # condition at the start of this file + run: | + echo "Pull requests should not update 'action/index.js'" + exit 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14a2078f..addb1413 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,13 +36,13 @@ jobs: with: node-version: 20 - - name: Build action (pull request) - # Pull requests are not expected to update `dist/index.js` themselves; therefore build `dist/index.js` - # here before running integration test - if: github.event_name == 'pull_request' + - name: Build action + # Pull requests are not expected to update `action/index.js`, and pushes to the `main` branch + # might not have updated the file either (and rely on CI to do that), therefore build the + # action here first run: | npm clean-install - npm run build + npm run github_ci_all - name: Run wrapper-validation-action id: action-test @@ -76,13 +76,13 @@ jobs: with: node-version: 20 - - name: Build action (pull request) - # Pull requests are not expected to update `dist/index.js` themselves; therefore build `dist/index.js` - # here before running integration test - if: github.event_name == 'pull_request' + - name: Build action + # Pull requests are not expected to update `action/index.js`, and pushes to the `main` branch + # might not have updated the file either (and rely on CI to do that), therefore build the + # action here first run: | npm clean-install - npm run build + npm run github_ci_all - name: Run wrapper-validation-action id: action-test diff --git a/.github/workflows/update-dist.yml b/.github/workflows/update-dist.yml new file mode 100644 index 00000000..10bf6bf4 --- /dev/null +++ b/.github/workflows/update-dist.yml @@ -0,0 +1,49 @@ +name: Update `action/index.js` +on: + push: + branches: + - main + +jobs: + update-dist: + runs-on: ubuntu-latest + + permissions: + # Allow the job to push the changed file to the repository + contents: write + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Build and test + run: | + npm -v + node -v + npm clean-install + npm run github_ci_all + + # To be safe, verify that either there are no changes or only `action/index.js` has changed + - name: Verify no unexpected changes + run: | + # Check for changes to any file other than `action/index.js`, see https://stackoverflow.com/a/29374503 + # Note that this does not detect new untracked files + if ! git diff --exit-code --quiet -- . ':!action/index.js'; then + echo "Unexpected changes:" + git diff -- . ':!action/index.js' + exit 1 + fi + + # Commit and push changes; has no effect if the file 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: Update dist & push changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'Update `action/index.js`' + file_pattern: 'action/index.js' diff --git a/.gitignore b/.gitignore index cf46feff..e1ff361d 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,7 @@ lib/**/* .idea/ *.iml + +# Ignore `index.js` file created during build; it is copied by CI to a separate directory +# Otherwise authors of PRs would commit it, causing merge conflicts or erroneous merges +/dist diff --git a/.prettierignore b/.prettierignore index 21869472..86bb4716 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ dist/ +action/ lib/ -node_modules/ \ No newline at end of file +node_modules/ diff --git a/RELEASING.md b/RELEASING.md index 2595abb3..9ba0c518 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,9 +1,10 @@ # Release * starting on `main` -* `npm install` +* `npm clean-install` * `npm run all` -* Commit and push any changes to the `dist` directory. Wait for CI. +* verify that `dist/index.js` matches `action/index.js` +* if not, commit and push the changes, then wait for CI to finish * `git tag v1.0.x && git push --tags` with the actual version number * `git tag -f -a v1 && git push -f --tags` * go to https://github.com/gradle/wrapper-validation-action/releases diff --git a/action.yml b/action.yml index 192b54ba..03af714e 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ outputs: runs: using: 'node20' - main: 'dist/index.js' + main: 'action/index.js' branding: icon: 'shield' diff --git a/dist/index.js b/action/index.js similarity index 100% rename from dist/index.js rename to action/index.js diff --git a/package.json b/package.json index 3bf2f343..a227deda 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "compile": "ncc build", "test": "jest", "build": "npm run check && npm run compile", - "all": "npm run build && npm test" + "all": "npm run build && npm test", + "github_ci_all": "npm run all && cp dist/index.js action/index.js" }, "repository": { "type": "git",