From 479fa7fb6a5b7aa3c99d93358ff22d39e96ed2b0 Mon Sep 17 00:00:00 2001 From: Jake Plimack Date: Fri, 15 Aug 2025 23:03:01 -0600 Subject: [PATCH 1/2] feat: enhance post-annotations to support both workflow_run and same-workflow scenarios - Add dual download strategy using actions/download-artifact for same-workflow scenarios - Fallback to GitHub API for workflow_run events (fork PRs) - Support github.run_id in addition to github.event.workflow_run.id - Handle commit SHA for both fork PR and regular PR scenarios - Preserve backward compatibility for existing fork PR workflows This allows post-annotations to work for: 1. Fork PRs using workflow_run trigger (existing functionality) 2. Regular PRs with split jobs in same workflow (new functionality) 3. Regular PRs with direct posting (existing functionality) --- action.yaml | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/action.yaml b/action.yaml index 62cc3911..63d9ae90 100644 --- a/action.yaml +++ b/action.yaml @@ -395,21 +395,38 @@ runs: overwrite: true path: ${{ env.TRUNK_TMPDIR }}/annotations.bin - - name: Download annotations artifact - if: inputs.post-annotations == 'true' + - name: Download annotations artifact (same workflow) + if: inputs.post-annotations == 'true' && github.event.workflow_run.id == '' + uses: actions/download-artifact@v4 + continue-on-error: true + id: download-same-workflow + with: + name: trunk-annotations + path: ${{ env.TRUNK_TMPDIR }} + + - name: Download annotations artifact (workflow_run or fallback) + if: inputs.post-annotations == 'true' && (github.event.workflow_run.id != '' || steps.download-same-workflow.outcome == 'failure') uses: actions/github-script@v7 with: - # TODO(chris): We can't use the official download artifact action yet: https://github.com/actions/download-artifact/issues/172 + # TODO(chris): We can't use the official download artifact action yet for workflow_run: https://github.com/actions/download-artifact/issues/172 script: | + // Use workflow_run.id if available (when triggered by workflow_run event), + // otherwise fall back to github.run_id (for same-workflow scenarios where download-artifact failed) + let runId = ${{ github.event.workflow_run.id || github.run_id }}; + console.log(`Attempting to download artifacts from run ${runId}`); + let artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, - run_id: ${{ github.event.workflow_run.id }}, + run_id: runId, }); + let matchArtifact = artifacts.data.artifacts.filter((artifact) => { return artifact.name == "trunk-annotations" })[0]; + if (matchArtifact) { + console.log(`Found trunk-annotations artifact with ID ${matchArtifact.id}`); let download = await github.rest.actions.downloadArtifact({ owner: context.repo.owner, repo: context.repo.repo, @@ -418,13 +435,17 @@ runs: }); let fs = require('fs'); fs.writeFileSync('${{ env.TRUNK_TMPDIR }}/annotations.zip', Buffer.from(download.data)); + } else { + console.log('No trunk-annotations artifact found'); } - name: Unpack annotations artifact - if: inputs.post-annotations == 'true' + if: inputs.post-annotations == 'true' && github.event.workflow_run.id != '' run: | - # Unpack annotations artifact - cd ${{ env.TRUNK_TMPDIR }} && unzip annotations.zip + # Unpack annotations artifact (only needed for workflow_run scenario) + if [[ -f "${{ env.TRUNK_TMPDIR }}/annotations.zip" ]]; then + cd ${{ env.TRUNK_TMPDIR }} && unzip annotations.zip + fi shell: bash - name: Post annotations @@ -434,7 +455,8 @@ runs: # Post annotations ${GITHUB_ACTION_PATH}/annotate.sh env: - GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + # Use workflow_run.head_sha if available (fork PR scenario), otherwise use the current SHA + GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} - name: Upload landing state if: env.INPUT_UPLOAD_LANDING_STATE == 'true' From d4f266759f17c91ccd61afa10fae7e13e2edfd57 Mon Sep 17 00:00:00 2001 From: Jake Plimack Date: Fri, 15 Aug 2025 23:08:56 -0600 Subject: [PATCH 2/2] trigger: empty commit to register workflows