Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR Don't run tests for Draft PRs #17299

Merged
merged 8 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon me, what is the purpose of this step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checks API has status and conclusion. The conclusion is only given if the status is "completed".

If we want to set a check to pending (as we've discussed in other PRs), we would send status=pending with no conclusion.

Because of the two forms of API call needed (one with conclusion, one without), we needed two steps with different arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mumrah, thanks for sharing. Although this step is not currently in use, it is intended to serve the needs of KAFKA-17607, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you meant https://issues.apache.org/jira/browse/KAFKA-17572 (clearing a status when re-running a job)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, you are right 😀

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