Skip to content

Commit

Permalink
MINOR Don't run tests for Draft PRs (apache#17299)
Browse files Browse the repository at this point in the history
Reviewers: Chia-Ping Tsai <[email protected]>
  • Loading branch information
mumrah authored and squah-confluent committed Sep 30, 2024
1 parent d9254d5 commit 0b97fa6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.
#
---
name: "Update Commit Status Check"
description: "Update the status of a commit check using the GH CLI"
name: "Update Check Run"
description: "Update the status of a commit check using the GH CLI. See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run"
inputs:
# Composite actions do not support typed parameters. Everything is treated as a string
# See: https://github.com/actions/runner/issues/2238
Expand All @@ -39,23 +39,43 @@ inputs:
description: "The text to display next to the check"
default: ""
required: false
context:
description: "The name of the status check"
title:
description: "The title of the status check"
required: true
state:
description: "The state of the check. Can be one of: error, failure, pending, success"
status:
description: "The status of the check. Can be one of: queued, in_progress, completed, waiting, requested, pending"
required: true
conclusion:
description: "Required if status is 'completed'. Can be one of: action_required, cancelled, failure, neutral, success, skipped, stale, timed_out"
required: false

runs:
using: "composite"
steps:
- name: Update Check
- if: inputs.conclusion == ''
shell: bash
env:
GH_TOKEN: ${{ inputs.gh-token }}
run: |
gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ inputs.repository }}/check-runs \
-f "head_sha=${{ inputs.commit_sha }}" \
-f "status=${{ inputs.status }}" \
-f "details_url=${{ inputs.url }}" \
-f "output[title]=${{ inputs.title }}" \
-f "output[summary]=${{ inputs.description }}" \
-f "name=${{ inputs.title }}"
- if: inputs.conclusion != ''
shell: bash
env:
GH_TOKEN: ${{ inputs.gh-token }}
run: |
gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ inputs.repository }}/statuses/${{ inputs.commit_sha }} \
-f "state=${{ inputs.state }}" -f "target_url=${{ inputs.url }}" \
-f "description=${{ inputs.description }}" \
-f "context=${{ inputs.context }}"
/repos/${{ inputs.repository }}/check-runs \
-f "head_sha=${{ inputs.commit_sha }}" \
-f "status=${{ inputs.status }}" \
-f "conclusion=${{ inputs.conclusion }}" \
-f "details_url=${{ inputs.url }}" \
-f "output[title]=${{ inputs.title }}" \
-f "output[summary]=${{ inputs.description }}" \
-f "name=${{ inputs.title }}"
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ jobs:
matrix:
java: [ 21, 17, 11, 8 ]
name: Compile and Check Java ${{ matrix.java }}
outputs:
is-draft: ${{ steps.check-draft-pr.outputs.is-draft }}
steps:
- name: Env
run: printenv
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Check for Draft PR
id: check-draft-pr
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.draft
run: echo "is-draft=true" >> "$GITHUB_OUTPUT"
- name: Checkout code
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -86,6 +94,7 @@ jobs:

test:
needs: validate
if: ${{ ! needs.validate.outputs.is-draft }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/ci-complete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ jobs:
path: ~/.gradle/build-scan-data # This is where Gradle buffers unpublished build scan data when --no-scan is given
- name: Handle missing scan
if: ${{ steps.download-build-scan.outcome == 'failure' }}
uses: ./.github/actions/gh-api-update-status
uses: ./.github/actions/gh-api-update-check
with:
gh-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
commit_sha: ${{ github.event.workflow_run.head_sha }}
url: '${{ github.event.workflow_run.html_url }}'
description: 'Could not find build scan'
context: 'Gradle Build Scan / Java ${{ matrix.java }}'
state: 'error'
title: 'Gradle Build Scan / Java ${{ matrix.java }}'
status: 'completed'
conclusion: 'skipped'
- name: Publish Scan
id: publish-build-scan
if: ${{ steps.download-build-scan.outcome == 'success' }}
Expand All @@ -98,23 +99,25 @@ jobs:
fi
- name: Handle failed publish
if: ${{ failure() && steps.publish-build-scan.outcome == 'failure' }}
uses: ./.github/actions/gh-api-update-status
uses: ./.github/actions/gh-api-update-check
with:
gh-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
commit_sha: ${{ github.event.workflow_run.head_sha }}
url: '${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}'
description: 'The build scan failed to be published'
context: 'Gradle Build Scan / Java ${{ matrix.java }}'
state: 'error'
title: 'Gradle Build Scan / Java ${{ matrix.java }}'
status: 'completed'
conclusion: 'failure'
- name: Update Status Check
if: ${{ steps.publish-build-scan.outcome == 'success' }}
uses: ./.github/actions/gh-api-update-status
uses: ./.github/actions/gh-api-update-check
with:
gh-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
commit_sha: ${{ github.event.workflow_run.head_sha }}
url: ${{ steps.publish-build-scan.outputs.build-scan-url }}
description: 'The build scan was successfully published'
context: 'Gradle Build Scan / Java ${{ matrix.java }}'
state: 'success'
title: 'Gradle Build Scan / Java ${{ matrix.java }}'
status: 'completed'
conclusion: 'success'
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
- 'trunk'

pull_request:
types: [ opened, synchronize, reopened ]
types: [ opened, synchronize, ready_for_review, reopened ]
branches:
- 'trunk'

Expand Down

0 comments on commit 0b97fa6

Please sign in to comment.