Skip to content

Conversation

@pahud
Copy link
Contributor

@pahud pahud commented Nov 14, 2025

Added steps to save and upload pull request information.

Issue # (if applicable)

Closes #36055

Reason for this change

THE PROBLEM:

PR Linter can't determine which PR to validate because:

  1. No pr_info artifact exists
  2. pull_requests array is empty (GitHub limitation)

THE SOLUTION:

Add these steps to codebuild-pr-build.yml:

  - name: Save PR info for PR Linter
    if: github.event_name == 'pull_request'
    run: |
      mkdir -p ./pr
      echo "${{ github.event.pull_request.number }}" > ./pr/pr_number
      echo "${{ github.event.pull_request.head.sha }}" > ./pr/pr_sha

  - name: Upload PR info artifact
    if: github.event_name == 'pull_request'
    uses: actions/upload-artifact@v5
    with:
      name: pr_info
      path: pr/

WHY IT WORKS:

BEFORE (BROKEN):
┌─────────────────────────────────────────────────────────┐
│ Codebuild PR Build                                      │
│   Context: github.event.pull_request.number = 36049 ✓   │
│   Context: github.event.pull_request.head.sha = fc4... ✓│
│                                                          │
│   ✗ Does NOT save this info                             │
│   ✗ Does NOT upload artifact                            │
└─────────────────────────────────────────────────────────┘
                    │
                    │ workflow_run event
                    ▼
┌─────────────────────────────────────────────────────────┐
│ PR Linter (workflow_run context)                        │
│   Context: github.event.workflow_run.pull_requests = [] │
│   Context: No PR info available ✗                       │
│                                                          │
│   Tries to download pr_info artifact ──► ✗ Not found   │
│   Tries pull_requests[0].number ──────► ✗ Empty array  │
│                                                          │
│   Result: ✗ CANNOT DETERMINE PR NUMBER                  │
└─────────────────────────────────────────────────────────┘


AFTER (FIXED):
┌─────────────────────────────────────────────────────────┐
│ Codebuild PR Build                                      │
│   Context: github.event.pull_request.number = 36049 ✓   │
│   Context: github.event.pull_request.head.sha = fc4... ✓│
│                                                          │
│   ✓ Saves PR number to file: pr/pr_number               │
│   ✓ Saves PR SHA to file: pr/pr_sha                     │
│   ✓ Uploads pr_info artifact                            │
│      └─ Contains: pr_number=36049, pr_sha=fc4...        │
└─────────────────────────────────────────────────────────┘
                    │
                    │ workflow_run event
                    │ (artifact travels with event)
                    ▼
┌─────────────────────────────────────────────────────────┐
│ PR Linter (workflow_run context)                        │
│   Context: github.event.workflow_run.pull_requests = [] │
│                                                          │
│   Downloads pr_info artifact ─────────► ✓ Found!       │
│     └─ Extracts pr/pr_number ────────► ✓ 36049         │
│     └─ Extracts pr/pr_sha ───────────► ✓ fc4...        │
│                                                          │
│   Result: ✓ PR NUMBER DETERMINED = 36049                │
│           ✓ Can now validate the correct PR             │
└─────────────────────────────────────────────────────────┘

KEY INSIGHT:

┌──────────────────────────────────────────────────────────┐
│  The PR context EXISTS in Codebuild PR Build             │
│  (triggered by pull_request event)                       │
│                                                           │
│  But it DISAPPEARS in PR Linter                          │
│  (triggered by workflow_run event)                       │
│                                                           │
│  Solution: PERSIST the context via artifact              │
│            (artifacts survive the context switch)        │
└──────────────────────────────────────────────────────────┘

CONTEXT AVAILABILITY:

Codebuild PR Build (pull_request trigger):
✓ github.event.pull_request.number
✓ github.event.pull_request.head.sha
✓ github.event.pull_request.* (all PR data)

PR Linter (workflow_run trigger):
✗ github.event.pull_request (doesn't exist)
✗ github.event.workflow_run.pull_requests (empty array)
✓ github.event.workflow_run.id (can download artifacts)

ARTIFACT AS BRIDGE:

  Codebuild Context          Artifact           PR Linter Context
  ─────────────────          ────────           ─────────────────

  PR #36049                                     workflow_run event
  pull_request event                            (no PR context)
       │                                              │
       │ Has PR data                                  │ No PR data
       │                                              │
       ▼                                              ▼
  Save to files          ──────────►            Download files
  - pr_number: 36049        Upload               - pr_number: 36049
  - pr_sha: fc4...          artifact             - pr_sha: fc4...
                            pr_info
                                                 ✓ PR context restored!

EXECUTION FLOW WITH FIX:

1. PR opened ──► Codebuild PR Build starts
                 │
                 ├─ github.event.pull_request.number = 36049 ✓
                 ├─ github.event.pull_request.head.sha = fc4... ✓
                 │
                 ├─ echo 36049 > pr/pr_number
                 ├─ echo fc4... > pr/pr_sha
                 └─ upload-artifact: pr_info
                    └─ Artifact ID: 12345

2. Codebuild completes ──► workflow_run event fires
                            │
                            └─ github.event.workflow_run.id = 19342493369

3. PR Linter triggered ──► download-if-workflow-run job
                            │
                            ├─ Download artifact from run 19342493369
                            │  └─ Finds pr_info artifact (ID: 12345) ✓
                            │
                            ├─ Extract files:
                            │  ├─ pr/pr_number = 36049 ✓
                            │  └─ pr/pr_sha = fc4... ✓
                            │
                            └─ Pass to validate-pr job:
                               └─ PR_NUMBER=36049 ✓
                               └─ PR_SHA=fc4... ✓

4. validate-pr job ──► Validates PR #36049 ✓

SUMMARY:

The solution works because it:

  1. Captures PR context when it's available (Codebuild)
  2. Persists it in an artifact (survives context switch)
  3. Restores it when needed (PR Linter)
  4. Bypasses GitHub's pull_requests array limitation

See #36055 for details

How do I validate

Test Environment

Validated on fork repository: pahud#16

Validation Steps

  1. Applied the fix to fork's codebuild-pr-build.yml (artifact upload steps)
  2. Created test PR to trigger workflows
  3. Verified Codebuild workflow uploaded pr_info artifact successfully
  4. Verified PR Linter workflow downloaded artifact and applied label

Results

Codebuild PR Build: Successfully uploaded pr_info artifact containing:

PR Linter: Successfully validated PR and applied label

Evidence

Before fix:

  • PR Linter failed with "Cannot determine PR number"
  • No pr_info artifact available
  • workflow_run.pull_requests array was empty

After fix:

  • PR Linter successfully downloaded pr_info artifact
  • Correctly identified PR number and SHA
  • Applied appropriate review label

Note on Fork Testing

For fork testing only, I added a pull_request_target fallback to pr-linter.yml since workflow_run events don't trigger from fork workflows. This fallback is not needed for aws/aws-cdk as workflows run in the base repository context where workflow_run works correctly.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Added steps to save and upload pull request information.
@aws-cdk-automation aws-cdk-automation requested a review from a team November 14, 2025 04:38
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Nov 14, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 14, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

@pahud pahud changed the title fix: prlinter not triggered when "Codebuild PR Build" completes chore: prlinter not triggered when "Codebuild PR Build" completes Nov 14, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 14, 2025 04:43

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 14, 2025
@abidhasan-aws abidhasan-aws self-assigned this Nov 14, 2025
@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@abidhasan-aws abidhasan-aws added the pr/do-not-merge This PR should not be merged at this time. label Nov 17, 2025
@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #36057 has been dequeued. The pull request rule doesn't match anymore. The following conditions don't match anymore:

  • -label~=(blocked|do-not-merge|no-squash|two-approvers|priority-pr)
  • check-success=build
  • check-success=validate-pr
  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue default-squash]
      • -label~=(blocked|do-not-merge|no-squash|priority-pr)
      • check-success=build
      • check-success=validate-pr
      • any of: [🛡 GitHub branch protection]
        • check-neutral = validate-pr
        • check-skipped = validate-pr
        • check-success = validate-pr
      • any of: [🛡 GitHub branch protection]
        • check-neutral = build
        • check-skipped = build
        • check-success = build.

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 17, 2025
- Extract pull request number and SHA into environment variables
- Use env variables instead of inline GitHub context expressions
- Improves workflow readability and maintainability
- Reduces duplication of GitHub context references in run script
@abidhasan-aws abidhasan-aws removed the pr/do-not-merge This PR should not be merged at this time. label Nov 17, 2025
@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit fa332bc into aws:main Nov 17, 2025
18 of 19 checks passed
@github-actions
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(workflow): PR Linter not triggered when "Codebuild PR Build" completes

4 participants