Unverified Commit 38e54926 authored by Daz DeBoer's avatar Daz DeBoer Committed by GitHub
Browse files

Allow wrapper validation via the 'setup-gradle' action (#162)

Adds a 'validate-wrappers' option to `gradle/actions/setup-gradle`,
which defaults to 'false'.
When 'true', the action will first validate all Gradle wrappers in the
repository before proceeding.

Fixes #161 
parents 1c25312b e9d1819b
Loading
Loading
Loading
Loading
+1
Changes for .github/actions/init-integ-test/action.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ runs:

    # Downloads a 'dist' directory artifact that was uploaded in an earlier 'build-dist' step
    - name: Download dist
      if: ${{ !env.ACT }}
      uses: actions/download-artifact@v4
      with:
        name: dist
+2
Changes for .github/workflows/ci-integ-test.yml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -183,3 +183,5 @@ jobs:
  wrapper-validation:
    needs: [determine-suite, build-distribution]
    uses: ./.github/workflows/integ-test-wrapper-validation.yml
    with:
      runner-os: '["ubuntu-latest"]'
+31 −5
Changes for .github/workflows/integ-test-wrapper-validation.yml: 31 added lines, 5 removed lines.
Original line number Diff line number Diff line
name: Test sample Kotlin DSL project
name: Test wrapper validation

on:
  workflow_call:
    inputs:
      runner-os:
        type: string
        default: '["ubuntu-latest", "windows-latest", "macos-latest"]'

jobs:
  # Integration test for successful validation of wrappers
  test-setup-gradle-validation:
    strategy:
      fail-fast: false
      matrix:
        os: ${{fromJSON(inputs.runner-os)}}
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Initialize integ-test
      uses: ./.github/actions/init-integ-test

    - name: Run wrapper-validation-action
      id: setup-gradle
      uses: ./setup-gradle
      with:
        validate-wrappers: true
      continue-on-error: true

    - name: Check failure
      run: |
        if [ "${{ steps.setup-gradle.outcome}}" != "failure" ] ; then
          echo "Expected validation to fail, but it didn't"
          exit 1
        fi

  test-validation-success:
    name: 'Test: Validation success'
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
@@ -33,9 +61,7 @@ jobs:
          exit 1
        fi

  # Integration test for failing validation of wrappers
  test-validation-error:
    name: 'Test: Validation error'
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
+17 −4
Changes for build: 17 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -3,8 +3,21 @@
cd sources
npm install

if [ "$1" == "all" ]; then
    npm run all
else
case "$1" in
    all)
        nprm run all
        ;;
    act)
        # Build and copy outputs to the dist directory
        npm run build
fi
        cd ..
        cp -r sources/dist .
        # Run act
        $@
        # Revert the changes to the dist directory
        git co -- dist
        ;;
    *)
        npm run build
        ;;
esac
 No newline at end of file
+15
Changes for docs/setup-gradle.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -503,6 +503,21 @@ located at `USER_HOME/.gradle/init.d/gradle-actions.build-result-capture.init.gr
If you are adding any custom init scripts to the `USER_HOME/.gradle/init.d` directory, it may be necessary to ensure these files are applied before `gradle-actions.build-result-capture.init.gradle`.
Since Gradle applies init scripts in alphabetical order, one way to ensure this is via file naming.

## Gradle Wrapper validation

Instead of using the [wrapper-validation action](./wrapper-validation.md) separately, you can enable 
wrapper validation directly in your Setup Gradle step.

```yaml
    - name: Setup Gradle
      uses: gradle/actions/setup-gradle@v3
      with:
        validate-wrappers: true
```

If you need more advanced configuration, then you're advised to continue using a separate workflow step
with `gradle/actions/wrapper-validation`.

## Support for GitHub Enterprise Server (GHES)

You can use the `setup-gradle` action on GitHub Enterprise Server, and benefit from the improved integration with Gradle. Depending on the version of GHES you are running, certain features may be limited:
Loading