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

Improve dependency graph failure handling (#1036)

One goal for the original dependency-graph support was to minimize it's
impact on existing workflows, by operating transparently and not
impacting the build outcome. This meant that any failures in
dependency-graph generation or submission were logged as warnings, but
did not cause the workflow to fail.

However, in some cases the primary purpose of a workflow is to generate
and submit a dependency graph: in these cases it is desirable to have
the workflow fail when this process breaks.

This PR introduces a new `dependency-graph-continue-on-failure`
parameter, which when `false` will enable the latter behaviour. It also
adds test coverage for different failures in dependency graph generation
and submission.

Fixes #1034 
Fixes #997 
parents 11693a11 610728fa
Loading
Loading
Loading
Loading
+5
Changes for .github/workflows/ci-full-check.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,11 @@ jobs:
    with:
      cache-key-prefix: ${{github.run_number}}-

  dependency-graph-failures:
    uses: ./.github/workflows/integ-test-dependency-graph-failures.yml
    with:
      cache-key-prefix: ${{github.run_number}}-

  execution-with-caching:
    uses: ./.github/workflows/integ-test-execution-with-caching.yml
    with:
+7
Changes for .github/workflows/ci-quick-check.yml: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -59,6 +59,13 @@ jobs:
      runner-os: '["ubuntu-latest"]'
      download-dist: true

  dependency-graph-failures:
    needs: build-distribution
    uses: ./.github/workflows/integ-test-dependency-graph-failures.yml
    with:
      runner-os: '["ubuntu-latest"]'
      download-dist: true

  execution-with-caching:
    needs: build-distribution
    uses: ./.github/workflows/integ-test-execution-with-caching.yml
+103
Changes for .github/workflows/integ-test-dependency-graph-failures.yml: 103 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: Test dependency graph

on:
  workflow_call:
    inputs:
      cache-key-prefix:
        type: string
      runner-os:
        type: string
        default: '["ubuntu-latest"]'
      download-dist:
        type: boolean
        default: false

env:
  DOWNLOAD_DIST: ${{ inputs.download-dist }}
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: dependency-graph-${{ inputs.cache-key-prefix }}
  GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true

jobs:
  unsupported-gradle-version-warning:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Download distribution if required
      uses: ./.github/actions/download-dist
    - name: Setup Gradle for dependency-graph generate
      uses: ./
      with:
        gradle-version: 7.0.1
        dependency-graph: generate
        dependency-graph-continue-on-failure: true
    - name: Run with unsupported Gradle version
      working-directory: .github/workflow-samples/groovy-dsl
      run: |
        if gradle help | grep -q 'warning::Dependency Graph is not supported for Gradle 7.0.1. No dependency snapshot will be generated.';
        then
          echo "Got the expected warning"
        else
          echo "Did not get the expected warning"
          exit 1
        fi

  unsupported-gradle-version-failure:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Download distribution if required
      uses: ./.github/actions/download-dist
    - name: Setup Gradle for dependency-graph generate
      uses: ./
      with:
        gradle-version: 7.0.1
        dependency-graph: generate
        dependency-graph-continue-on-failure: false
    - name: Run with unsupported Gradle version
      working-directory: .github/workflow-samples/groovy-dsl
      run: |
        if gradle help; then
          echo "Expected build to fail with Gradle 7.0.1"
          exit 1
        fi

  insufficient-permissions-warning:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Download distribution if required
      uses: ./.github/actions/download-dist
    - name: Setup Gradle for dependency-graph generate
      uses: ./
      with:
        dependency-graph: generate-and-submit
        dependency-graph-continue-on-failure: true
    - name: Run with insufficient permissions
      working-directory: .github/workflow-samples/groovy-dsl
      run: ./gradlew help
      # This test is primarily for demonstration: it's unclear how to check for warnings emitted in the post-action

  SHOULD_FAIL-insufficient-permissions-failure:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    continue-on-error: true
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Download distribution if required
      uses: ./.github/actions/download-dist
    - name: Setup Gradle for dependency-graph generate
      uses: ./
      with:
        dependency-graph: generate-and-submit
        dependency-graph-continue-on-failure: false
    - name: Run with insufficient permissions
      working-directory: .github/workflow-samples/groovy-dsl
      run: ./gradlew help
      # This test is primarily for demonstration: it's unclear how to check for a failure in the post-action
+16
Changes for README.md: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -512,6 +512,22 @@ Depending on [repository settings](https://docs.github.com/en/actions/security-g
> for a PR submitted from a forked repository.
> For a configuration that supports this setup, see [Dependency Graphs for pull request workflows](#dependency-graphs-for-pull-request-workflows).

### Making dependency graph failures cause Job failures

By default, if a failure is encountered when generating or submitting the dependency graph, the action will log the failure as a warning and continue.
This allows your workflow to be resilient to dependency graph failures, in case dependency graph production is a side-effect rather than the primary purpose of a workflow.

If instead you have a workflow that has a primary purpose to generate and submit a dependency graph, then it makes sense for this workflow to fail if the dependency
graph cannot be generated or submitted. You can enable this behaviour with the `dependency-graph-continue-on-failure` parameter, which defaults to `true`.

```yaml
# Ensure that the workflow Job will fail if the dependency graph cannot be submitted
- uses: gradle/gradle-build-action@v3
  with:
    dependency-graph: generate-and-submit
    dependency-graph-continue-on-failure: false
```

### Using a custom plugin repository

By default, the action downloads the `github-dependency-graph-gradle-plugin` from the Gradle Plugin Portal (https://plugins.gradle.org). If your GitHub Actions environment does not have access to this URL, you can specify a custom plugin repository to use. 
+5
Changes for action.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -73,6 +73,11 @@ inputs:
    required: false
    default: 'disabled'

  dependency-graph-continue-on-failure:
    description: When 'false' a failure to generate or submit a dependency graph will fail the Step or Job. When 'true' a warning will be emitted but no failure will result.
    required: false
    default: true

  artifact-retention-days:
    description: Specifies the number of days to retain any artifacts generated by the action. If not set, the default retention settings for the repository will apply.
    required: false
Loading