From ff95447b08fd3bc45c3a55ce70e38c17b067a275 Mon Sep 17 00:00:00 2001 From: Allison Piper Date: Thu, 2 May 2024 15:25:15 +0000 Subject: [PATCH] More action refactoring [skip-tests][workflow:test][workflow:!pull_request] --- .github/actions/workflow-build/action.yml | 18 +++++++++--------- .github/actions/workflow-results/action.yml | 19 ++++++++----------- .../workflows/ci-workflow-pull-request.yml | 13 +++++++++++-- ci/build_common.sh | 2 +- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.github/actions/workflow-build/action.yml b/.github/actions/workflow-build/action.yml index e33d598fc56..36819b62295 100644 --- a/.github/actions/workflow-build/action.yml +++ b/.github/actions/workflow-build/action.yml @@ -9,10 +9,14 @@ inputs: description: "Skip running tests" default: "false" required: false - inspect-changes_script: + inspect_changes_script: description: "If defined, run this script to determine which projects/deps need to be tested." default: "" required: false + inspect_changes_base_sha: + description: "If defined, use this base ref for inspect-changes script." + default: "" + required: false matrix_file: description: "Path to the matrix file in the consumer repository." default: "ci/matrix.yaml" @@ -34,19 +38,15 @@ runs: using: "composite" steps: - - name: Lookup PR info - id: get-pr-info - uses: nv-gha-runners/get-pr-info@main - - name: Inspect changes - if: ${{ inputs.inspect-changes_script != '' }} + if: ${{ inputs.inspect_changes_script != '' && inputs.inspect_changes_base_sha != '' }} id: inspect-changes shell: bash --noprofile --norc -euo pipefail {0} env: - base_sha: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).base.sha }} + base_ref: ${{ inputs.inspect_changes_base_sha }} run: | echo "Running inspect-changes script..." - ${{ inputs.inspect-changes_script }} ${base_sha} ${GITHUB_SHA} + ${{ inputs.inspect_changes_script }} ${base_ref} ${GITHUB_SHA} echo "Exporting summary..." mkdir workflow cp ${GITHUB_STEP_SUMMARY} workflow/changes.md @@ -56,7 +56,7 @@ runs: shell: bash --noprofile --norc -euo pipefail {0} env: skip_tests: ${{ inputs.skip_tests == 'true' && '--skip-tests' || ''}} - dirty_projects_flag: ${{ inputs.inspect-changes_script != '' && '--dirty-projects' || ''}} + dirty_projects_flag: ${{ steps.inspect-changes.outputs.dirty_projects != '' && '--dirty-projects' || ''}} dirty_projects: ${{ steps.inspect-changes.outputs.dirty_projects }} matrix_parser: ${{ inputs.matrix_parser && inputs.matrix_parser || '${GITHUB_ACTION_PATH}/build-workflow.py' }} run: | diff --git a/.github/actions/workflow-results/action.yml b/.github/actions/workflow-results/action.yml index 6696024fa34..ad0f8059c7a 100644 --- a/.github/actions/workflow-results/action.yml +++ b/.github/actions/workflow-results/action.yml @@ -2,9 +2,12 @@ name: "CCCL Workflow Sentinal" description: "Check the results of the dispatched jobs and comment on the PR." inputs: - github-token: + github_token: description: "The GitHub token to use for commenting on the PR." required: true + pr_number: + description: "The PR number to comment on, if applicable. No comment will be made if not provided." + required: false outputs: success: @@ -15,18 +18,11 @@ runs: using: "composite" steps: - - name: Get Base Branch from PR - id: get-pr-info - uses: nv-gha-runners/get-pr-info@main - - name: Download workflow artifacts uses: actions/download-artifact@v3 with: name: workflow path: workflow/ - - run: | - find . | grep workflow - shell: bash --noprofile --norc -euo pipefail {0} - name: Download job success artifacts continue-on-error: true # This may fail if no jobs succeed. The checks below will catch this. @@ -64,20 +60,21 @@ runs: cp final_summary.md ${GITHUB_STEP_SUMMARY} - name: Comment on PR + if: ${{ !cancelled() && inputs.pr_number != '' }} continue-on-error: true env: - PR_NUMBER: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }} + PR_NUMBER: ${{ fromJSON(inputs.pr_number) }} COMMENT_BODY: ${{ steps.final-summary.outputs.SUMMARY }} uses: actions/github-script@v4 with: - github-token: ${{ inputs.github-token }} + github-token: ${{ inputs.github_token }} script: | const pr_number = process.env.PR_NUMBER; const owner = 'NVIDIA'; const repo = 'cccl'; // Decode URL-encoded string for proper display in comments const commentBody = decodeURIComponent(process.env.COMMENT_BODY); - console.log('::group::Commenting on PR #' + pr_number + ' with the following message:) + console.log('::group::Commenting on PR #' + pr_number + ' with the following message:') console.log(commentBody); console.log('::endgroup::'); github.issues.createComment({ diff --git a/.github/workflows/ci-workflow-pull-request.yml b/.github/workflows/ci-workflow-pull-request.yml index 3e84276271e..8b9c3ef4494 100644 --- a/.github/workflows/ci-workflow-pull-request.yml +++ b/.github/workflows/ci-workflow-pull-request.yml @@ -43,12 +43,16 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v3 + - name: Lookup PR info + id: get-pr-info + uses: nv-gha-runners/get-pr-info@main - name: Build workflow id: build-workflow uses: ./.github/actions/workflow-build with: skip_tests: ${{ toJSON(contains(github.event.head_commit.message, '[skip-tests]')) }} - inspect-changes_script: ${{ toJSON(!contains(github.event.head_commit.message, '[all-projects]') && 'ci/inspect_changes.sh' || '') }} + inspect_changes_script: ${{ toJSON(!contains(github.event.head_commit.message, '[all-projects]') && 'ci/inspect_changes.sh' || '') }} + inspect_changes_base_sha: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).base.sha }} workflows: >- ${{ !contains(github.event.head_commit.message, '[workflow:!pull_request]') && 'pull_request' || '' }} ${{ contains(github.event.head_commit.message, '[workflow:nightly]') && 'nightly' || '' }} @@ -92,11 +96,16 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 + - name: Get Base Branch from PR + id: get-pr-info + uses: nv-gha-runners/get-pr-info@main + - name: Check workflow success id: check-workflow uses: ./.github/actions/workflow-results with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_number: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }} - name: Check results run: | diff --git a/ci/build_common.sh b/ci/build_common.sh index 5d36919c4a1..12712ec11d7 100755 --- a/ci/build_common.sh +++ b/ci/build_common.sh @@ -218,7 +218,7 @@ function test_preset() local PRESET=$2 local GPU_REQUIRED=${3:-"true"} - if [ $GPU_REQUIRED -eq "true" ]; then + if [ "$GPU_REQUIRED" -eq "true" ]; then fail_if_no_gpu fi