diff --git a/.github/actions/build-dist/action.yml b/.github/actions/build-dist/action.yml index 5ab27ea..d8e5b85 100644 --- a/.github/actions/build-dist/action.yml +++ b/.github/actions/build-dist/action.yml @@ -6,6 +6,9 @@ runs: - uses: actions/setup-node@v4 with: node-version: 20 + cache: npm + cache-dependency-path: sources/package-lock.json + - name: Build distribution shell: bash run: | 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..8a864d4 --- /dev/null +++ b/.github/workflows/ci-check-no-dist-update.yml @@ -0,0 +1,26 @@ +name: CI-check-no-dist-update + +# Will run on 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-dependency-review.yml b/.github/workflows/ci-dependency-review.yml deleted file mode 100644 index b31c1ee..0000000 --- a/.github/workflows/ci-dependency-review.yml +++ /dev/null @@ -1,28 +0,0 @@ -# Dependency Review Action -# -# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging. -# -# Source repository: https://github.com/actions/dependency-review-action -# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement -name: CI-dependency-review -on: [pull_request] - -permissions: - contents: write - -jobs: - dependency-review: - runs-on: ubuntu-latest - steps: - - name: 'Checkout Repository' - uses: actions/checkout@v4 - - name: Dependencies for groovy-dsl - uses: ./dependency-submission - with: - build-root-directory: .github/workflow-samples/groovy-dsl - - name: Dependencies for kotlin-dsl - uses: ./dependency-submission - with: - build-root-directory: .github/workflow-samples/kotlin-dsl - - name: 'Dependency Review' - uses: actions/dependency-review-action@v4 diff --git a/.github/workflows/ci-format-and-unit-test.yml b/.github/workflows/ci-format-and-unit-test.yml new file mode 100644 index 0000000..a9de0c8 --- /dev/null +++ b/.github/workflows/ci-format-and-unit-test.yml @@ -0,0 +1,29 @@ +name: CI-format-and-unit-test + +on: + push: + +permissions: + contents: read + +jobs: + check-format-and-unit-test: + 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 and check formatting + run: | + npm install + npm run build-ci + working-directory: sources + - name: Run unit tests + run: | + npm test + working-directory: sources diff --git a/.github/workflows/ci-full-check.yml b/.github/workflows/ci-full-check.yml index d2e3219..b4f8e2e 100644 --- a/.github/workflows/ci-full-check.yml +++ b/.github/workflows/ci-full-check.yml @@ -2,18 +2,12 @@ name: CI-full-check on: workflow_dispatch: - pull_request: - types: - - assigned - - review_requested push: branches: - main - release/** paths: - - '.github/**' - 'dist/**' - - '**/action.yml' jobs: action-inputs: diff --git a/.github/workflows/ci-quick-check.yml b/.github/workflows/ci-quick-check.yml index 32e481f..bcd682a 100644 --- a/.github/workflows/ci-quick-check.yml +++ b/.github/workflows/ci-quick-check.yml @@ -3,9 +3,6 @@ name: CI-quick-check on: workflow_dispatch: push: - branches-ignore: - - main - - release/** jobs: build-distribution: @@ -16,21 +13,6 @@ jobs: - name: Build and upload distribution uses: ./.github/actions/build-dist - run-unit-tests: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - name: Configure Gradle as default for unit test - uses: ./setup-gradle - with: - gradle-version: 8.7 - - name: Run tests - run: | - npm install - npm run all - working-directory: sources - action-inputs: needs: build-distribution uses: ./.github/workflows/integ-test-action-inputs.yml diff --git a/.github/workflows/ci-update-dist.yml b/.github/workflows/ci-update-dist.yml new file mode 100644 index 0000000..776624e --- /dev/null +++ b/.github/workflows/ci-update-dist.yml @@ -0,0 +1,49 @@ +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 build-ci + 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 12dd172..0000000 --- a/.github/workflows/ci-verify-outputs.yml +++ /dev/null @@ -1,45 +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 - - 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 e366242..aa13399 100644 --- a/sources/package.json +++ b/sources/package.json @@ -5,17 +5,19 @@ "description": "Execute Gradle Build", "scripts": { "postinstall": "patch-package", - "format": "prettier --write 'src/**/*.ts'", - "format-check": "prettier --check 'src/**/*.ts'", + "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 format lint", + "check": "npm-run-all --parallel prettier-check lint", + "format": "npm-run-all --parallel prettier-write lint", "test": "jest", - "build": "npm run check && npm run compile", + "build": "npm run format && npm run compile", + "build-ci": "npm run check && npm run compile", "all": "npm run build && npm test" }, "repository": {