From 9e47918adfda8f4546e9c025cbf99a651e342b99 Mon Sep 17 00:00:00 2001 From: daz Date: Wed, 10 Apr 2024 07:29:08 -0600 Subject: [PATCH] Build and commit changes to 'dist' automatically Instead of requiring that developers keep the 'dist' directory up-to-date, this process is now automated via a workflow. Whenever a commit is pushed to 'main' (or a 'release/**' branch), the workflow will build the application and commit any changes to the 'dist' directory. --- .github/workflows/ci-check-no-dist-update.yml | 26 ++++++++++ .github/workflows/ci-update-dist.yml | 50 +++++++++++++++++++ .github/workflows/ci-verify-outputs.yml | 47 ----------------- sources/.gitignore | 2 + sources/package.json | 8 +-- 5 files changed, 82 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/ci-check-no-dist-update.yml create mode 100644 .github/workflows/ci-update-dist.yml delete mode 100644 .github/workflows/ci-verify-outputs.yml diff --git a/.github/workflows/ci-check-no-dist-update.yml b/.github/workflows/ci-check-no-dist-update.yml new file mode 100644 index 0000000..67b66fe --- /dev/null +++ b/.github/workflows/ci-check-no-dist-update.yml @@ -0,0 +1,26 @@ +name: CI-check-no-dist-update + +# Prohibit any change to 'dist/**' on a non-release branch +on: + push: + branches-ignore: + - main + - release/* + paths: + - dist** + pull_request: + paths: + - dist/** + +permissions: + contents: read + +jobs: + fail-on-dist-update: + runs-on: ubuntu-latest + + steps: + - run: | + echo "The 'dist' directory is auotmatically 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..ad02823 --- /dev/null +++ b/.github/workflows/ci-update-dist.yml @@ -0,0 +1,50 @@ +name: CI-update-dist + +on: + workflow_dispatch: + push: + branches: + - main + - release/** + paths-ignore: + - 'dist/**' + +permissions: + contents: write + +jobs: + update-dist: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + cache-dependency-path: sources/package-lock.json + + - name: Build distribution + run: | + npm clean-install + npm run check + npm run compile + 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 + # Only run for the Gradle 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 == 'gradle/actions' + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'Update dist directory' + file_pattern: dist diff --git a/.github/workflows/ci-verify-outputs.yml b/.github/workflows/ci-verify-outputs.yml deleted file mode 100644 index f33cc7d..0000000 --- a/.github/workflows/ci-verify-outputs.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: CI-verify-outputs - -on: - pull_request: - types: - - assigned - - review_requested - push: - branches: - - main - - release/** - - dependabot/** - -jobs: - check: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: npm - cache-dependency-path: sources/package-lock.json - - name: Build - run: | - npm -v - node -v - npm install - npm run build - working-directory: sources - - - 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/sources/.gitignore b/sources/.gitignore index e66d851..b0c6848 100644 --- a/sources/.gitignore +++ b/sources/.gitignore @@ -102,3 +102,5 @@ __tests__/runner/* .idea/ *.iml +# Local 'dist' directory within 'sources'. This is copied to ../dist by CI. +dist/ diff --git a/sources/package.json b/sources/package.json index 6c3b53a..3985d5d 100644 --- a/sources/package.json +++ b/sources/package.json @@ -8,10 +8,10 @@ "prettier-write": "prettier --write 'src/**/*.ts'", "prettier-check": "prettier --check 'src/**/*.ts'", "lint": "eslint 'src/**/*.ts'", - "compile-dependency-submission-main": "ncc build src/dependency-submission/main.ts --out ../dist/dependency-submission/main --source-map --no-source-map-register", - "compile-dependency-submission-post": "ncc build src/dependency-submission/post.ts --out ../dist/dependency-submission/post --source-map --no-source-map-register", - "compile-setup-gradle-main": "ncc build src/setup-gradle/main.ts --out ../dist/setup-gradle/main --source-map --no-source-map-register", - "compile-setup-gradle-post": "ncc build src/setup-gradle/post.ts --out ../dist/setup-gradle/post --source-map --no-source-map-register", + "compile-dependency-submission-main": "ncc build src/dependency-submission/main.ts --out dist/dependency-submission/main --source-map --no-source-map-register", + "compile-dependency-submission-post": "ncc build src/dependency-submission/post.ts --out dist/dependency-submission/post --source-map --no-source-map-register", + "compile-setup-gradle-main": "ncc build src/setup-gradle/main.ts --out dist/setup-gradle/main --source-map --no-source-map-register", + "compile-setup-gradle-post": "ncc build src/setup-gradle/post.ts --out dist/setup-gradle/post --source-map --no-source-map-register", "compile": "npm-run-all --parallel compile-*", "check": "npm-run-all --parallel prettier-check lint", "format": "npm-run-all --parallel prettier-write lint",