From afbadeb4782ae70e3c11986b9c164c7b14adcd0a Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Tue, 31 Mar 2026 10:21:54 +0200 Subject: [PATCH] Test with Bazel 8.x and 9.x --- .github/scripts/locate_bcr_pr.sh | 27 ++++++++++++++++++++++ .github/scripts/post_bcr_skip_comment.sh | 24 ++++++++++++++++++++ .github/workflows/publish.yaml | 29 +++++++++++++++++++++++- .github/workflows/test.yml | 6 +++-- 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/locate_bcr_pr.sh create mode 100644 .github/scripts/post_bcr_skip_comment.sh diff --git a/.github/scripts/locate_bcr_pr.sh b/.github/scripts/locate_bcr_pr.sh new file mode 100644 index 000000000..0582d3ca6 --- /dev/null +++ b/.github/scripts/locate_bcr_pr.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euo pipefail + +FORK_OWNER="${REGISTRY_FORK%%/*}" +HEAD_REF="${FORK_OWNER}:periphery-${TAG_NAME}" + +for attempt in 1 2 3 4 5; do + RESPONSE=$(curl --silent --show-error --location --get \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer ${GITHUB_TOKEN}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + --data-urlencode "state=open" \ + --data-urlencode "head=${HEAD_REF}" \ + "https://api.github.com/repos/${REGISTRY}/pulls") + + PR_NUMBER=$(jq --raw-output '.[0].number // empty' <<<"${RESPONSE}") + if [[ -n "${PR_NUMBER}" ]]; then + echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" + exit 0 + fi + + sleep 5 +done + +echo "Could not find an open pull request for ${HEAD_REF}" +exit 1 diff --git a/.github/scripts/post_bcr_skip_comment.sh b/.github/scripts/post_bcr_skip_comment.sh new file mode 100644 index 000000000..141e166f3 --- /dev/null +++ b/.github/scripts/post_bcr_skip_comment.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -euo pipefail + +COMMENTS=$(curl --silent --show-error --location \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer ${GITHUB_TOKEN}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${REGISTRY}/issues/${PR_NUMBER}/comments") + +if jq -e --arg body "${COMMENT_BODY}" '.[] | select(.body == $body)' <<<"${COMMENTS}" >/dev/null; then + echo "Comment already exists on PR #${PR_NUMBER}" + exit 0 +fi + +PAYLOAD=$(jq --null-input --arg body "${COMMENT_BODY}" '{body: $body}') + +curl --silent --show-error --location \ + --request POST \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer ${GITHUB_TOKEN}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + --data "${PAYLOAD}" \ + "https://api.github.com/repos/${REGISTRY}/issues/${PR_NUMBER}/comments" >/dev/null diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index ada1a49c7..3fbc7e300 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -21,4 +21,31 @@ jobs: permissions: contents: write secrets: - publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }} \ No newline at end of file + publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }} + + skip-unstable-url: + needs: publish + if: ${{ needs.publish.result == 'success' }} + runs-on: ubuntu-latest + permissions: + contents: read + env: + REGISTRY: bazelbuild/bazel-central-registry + REGISTRY_FORK: peripheryapp/bazel-central-registry + TAG_NAME: ${{ inputs.tag_name || github.ref_name }} + COMMENT_BODY: "@bazel-io skip_check unstable_url" + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Locate BCR pull request + id: pr + env: + GITHUB_TOKEN: ${{ secrets.BCR_PUBLISH_TOKEN }} + run: bash .github/scripts/locate_bcr_pr.sh + + - name: Post unstable URL skip comment + env: + GITHUB_TOKEN: ${{ secrets.BCR_PUBLISH_TOKEN }} + PR_NUMBER: ${{ steps.pr.outputs.number }} + run: bash .github/scripts/post_bcr_skip_comment.sh \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c98daf112..2c138ca25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,10 +27,11 @@ jobs: - name: Check generated Bazel rules run: mise r gen-bazel-rules && git diff --quiet --exit-code bazel: - name: Bazel (${{ matrix.os }}) + name: Bazel (${{ matrix.bazel }}, ${{ matrix.os }}) strategy: fail-fast: false matrix: + bazel: [8.x, 9.x] os: [macOS, Linux] include: - os: macOS @@ -44,6 +45,7 @@ jobs: runs-on: ${{ matrix.runs-on }} container: ${{ matrix.container }} env: + USE_BAZEL_VERSION: ${{ matrix.bazel }} CC: ${{ matrix.cc }} steps: - uses: actions/checkout@master @@ -51,7 +53,7 @@ jobs: with: bazelisk-version: 1.x bazelisk-cache: true - disk-cache: bazel-${{ matrix.os }} + disk-cache: bazel-${{ matrix.os }}-${{ matrix.bazel }} repository-cache: true - name: Scan run: bazel run //:periphery -- scan --bazel --quiet --strict --baseline baselines/${{ matrix.baseline }}