From 72e652f679325aa9a2efc3d54d582619004d672b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Thu, 10 Jul 2025 19:39:36 +0200 Subject: [PATCH] ci: test both push and pull_request events I think we have a bug with pull_request events so... --- .forgejo/workflows/check.yml | 9 ++++----- .forgejo/workflows/test-pr.yml | 33 +++++++++++++++++++++++++++++++++ action.yml | 13 +++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .forgejo/workflows/test-pr.yml diff --git a/.forgejo/workflows/check.yml b/.forgejo/workflows/check.yml index 14a13b1..1c90cbe 100644 --- a/.forgejo/workflows/check.yml +++ b/.forgejo/workflows/check.yml @@ -24,18 +24,17 @@ jobs: uses: ./ with: # Create a comment on the associated PR - comment-on-pr: ${{ github.ref_name != 'main' }} + comment-on-pr: 'false' # Generate artifacts on main (to speed up comparisons) # generate-artifact: ${{ github.ref_name == 'main' }} # Always generate artifacts for testing purposes generate-artifact: 'true' - # Generate comparisons to main - do-comparison: 'true' - # This job's name (so we can find the artifacts) + # This job's name (so we can find the previous artifacts) job-name: report-size report-download-check: runs-on: nixos - needs: report-size + needs: report-size-push + if: github.event_name == 'push' steps: - name: Download previous report uses: https://git.salame.cl/actions/download-artifact@d8d0a99033603453ad2255e58720b460a0555e1e # v4 diff --git a/.forgejo/workflows/test-pr.yml b/.forgejo/workflows/test-pr.yml new file mode 100644 index 0000000..43fb880 --- /dev/null +++ b/.forgejo/workflows/test-pr.yml @@ -0,0 +1,33 @@ +on: + pull_request: +jobs: + report-size-pr: + runs-on: nixos + steps: + - uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4 + - run: nix --version + - name: Create Size Report + uses: ./ + with: + # Create a comment on the associated PR + comment-on-pr: 'true' + # Generate artifacts on main (to speed up comparisons) + # generate-artifact: ${{ github.ref_name == 'main' }} + # Always generate artifacts for testing purposes + generate-artifact: 'true' + # Generate comparisons to main + do-comparison: 'true' + # Get the previous artifacts from report-size-push (since those run on main) + job-name: report-size + artifact-name: report.json + report-download-check-pr: + runs-on: nixos + needs: report-size-pr + steps: + - name: Download previous report + uses: https://git.salame.cl/actions/download-artifact@d8d0a99033603453ad2255e58720b460a0555e1e # v4 + with: + name: report.json + - name: Verify report exists + run: | + cat report.json diff --git a/action.yml b/action.yml index 46431b7..b129693 100644 --- a/action.yml +++ b/action.yml @@ -73,6 +73,17 @@ runs: run: | . "$GITHUB_ACTION_PATH/utils.sh" + # If we were triggered by a PR then this is easy + if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then + # shellcheck disable=SC2016 + # expanded by the runner + pr_number='${{ github.event.number }}' + log "Triggered by a pull request with index: $pr_number" + log "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number" + echo "pr-number=$pr_number" >> "$GIHUB_OUTPUT" + exit 0 + fi + log 'Determine head_ref' # For push & tag events it'll bet GITHUB_REF_NAME, for pull_request events it'll be GITHUB_HEAD_REF head_ref=${GITHUB_REF_NAME:-$GITHUB_HEAD_REF} @@ -83,6 +94,8 @@ runs: -H "Authorization: token $GITHUB_TOKEN" \ -H 'Accept: application/json') + log "Open PRs: $(echo "$prs" | jq --compact output 'map(.number)')" + pr_number=$(echo "$prs" | jq --arg head_ref "$head_ref" '.[] | select(.head.ref == $head_ref) | .number')