Skip to content

Commit

Permalink
Add GitHub workflow for automatically updating index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 committed Feb 25, 2024
1 parent 63d15e7 commit 1aec294
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 67 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
action/
lib/
node_modules/
node_modules/
51 changes: 0 additions & 51 deletions .github/workflows/check-dist.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/check-pull-request-no-dist-change.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/update-dist.yml
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
action/
lib/
node_modules/
node_modules/
5 changes: 3 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ outputs:

runs:
using: 'node20'
main: 'dist/index.js'
main: 'action/index.js'

branding:
icon: 'shield'
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1aec294

Please sign in to comment.