|
| 1 | +name: Test Public Release Finalizer Action |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - test-main |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: test-public-release-finalizer-action-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + test-public-release-finalizer-action: |
| 17 | + name: Create public test release refs |
| 18 | + if: ${{ contains(github.event.head_commit.message, '[test-public-finalizer-workflow]') }} |
| 19 | + runs-on: ubuntu-24.04 |
| 20 | + timeout-minutes: 10 |
| 21 | + steps: |
| 22 | + - name: Checkout public test-main |
| 23 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 24 | + with: |
| 25 | + ref: test-main |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Prepare test release metadata |
| 29 | + id: release |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | +
|
| 33 | + tag="test/v0.8.0" |
| 34 | + release_branch="test-release/0.8" |
| 35 | + base_ref="test-main" |
| 36 | + head_ref="sync/copybara-export-test-main-test-v0_8_0-public-workflow-${GITHUB_RUN_ID}" |
| 37 | + body=$'Release tag: test/v0.8.0\nRelease branch: test-release/0.8\nRelease kind: minor' |
| 38 | +
|
| 39 | + [[ "${base_ref}" == "test-main" ]] |
| 40 | + [[ "${release_branch}" == test-release/* ]] |
| 41 | + [[ "${tag}" == test/v* ]] |
| 42 | +
|
| 43 | + { |
| 44 | + echo "tag=${tag}" |
| 45 | + echo "release_branch=${release_branch}" |
| 46 | + echo "base_ref=${base_ref}" |
| 47 | + echo "head_ref=${head_ref}" |
| 48 | + echo "body<<PUBLIC_RELEASE_BODY" |
| 49 | + printf '%s\n' "${body}" |
| 50 | + echo "PUBLIC_RELEASE_BODY" |
| 51 | + } >> "${GITHUB_OUTPUT}" |
| 52 | +
|
| 53 | + - name: Snapshot production refs |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + { |
| 57 | + git ls-remote origin "refs/heads/main" || true |
| 58 | + git ls-remote origin "refs/heads/release/*" || true |
| 59 | + git ls-remote origin "refs/tags/v*" || true |
| 60 | + } | sort > "${RUNNER_TEMP}/production-before.txt" |
| 61 | +
|
| 62 | + - name: Reset public test refs |
| 63 | + env: |
| 64 | + RELEASE_BRANCH: ${{ steps.release.outputs.release_branch }} |
| 65 | + RELEASE_TAG: ${{ steps.release.outputs.tag }} |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | +
|
| 69 | + delete_ref() { |
| 70 | + local ref="$1" |
| 71 | + case "${ref}" in |
| 72 | + refs/heads/test-release/*|refs/tags/test/v*) ;; |
| 73 | + *) echo "::error::Ref is outside the public test namespace: ${ref}"; exit 1 ;; |
| 74 | + esac |
| 75 | +
|
| 76 | + if git ls-remote --exit-code origin "${ref}" >/dev/null 2>&1; then |
| 77 | + git push origin ":${ref}" |
| 78 | + echo "Deleted ${ref}" |
| 79 | + fi |
| 80 | + } |
| 81 | +
|
| 82 | + delete_ref "refs/heads/${RELEASE_BRANCH}" |
| 83 | + delete_ref "refs/tags/${RELEASE_TAG}" |
| 84 | + git tag -d "${RELEASE_TAG}" >/dev/null 2>&1 || true |
| 85 | +
|
| 86 | + - name: Validate public release action |
| 87 | + uses: ./.github/actions/finalize-release |
| 88 | + with: |
| 89 | + mode: validate |
| 90 | + release-namespace: auto |
| 91 | + pr-title: ${{ github.event.head_commit.message }} |
| 92 | + pr-body: ${{ steps.release.outputs.body }} |
| 93 | + pr-base-ref: ${{ steps.release.outputs.base_ref }} |
| 94 | + pr-head-ref: ${{ steps.release.outputs.head_ref }} |
| 95 | + |
| 96 | + - name: Finalize public release action |
| 97 | + uses: ./.github/actions/finalize-release |
| 98 | + with: |
| 99 | + mode: finalize |
| 100 | + release-namespace: auto |
| 101 | + pr-title: ${{ github.event.head_commit.message }} |
| 102 | + pr-body: ${{ steps.release.outputs.body }} |
| 103 | + pr-base-ref: ${{ steps.release.outputs.base_ref }} |
| 104 | + pr-head-ref: ${{ steps.release.outputs.head_ref }} |
| 105 | + merge-commit-sha: ${{ github.sha }} |
| 106 | + |
| 107 | + - name: Verify public test refs |
| 108 | + env: |
| 109 | + RELEASE_BRANCH: ${{ steps.release.outputs.release_branch }} |
| 110 | + RELEASE_TAG: ${{ steps.release.outputs.tag }} |
| 111 | + EXPECTED_SHA: ${{ github.sha }} |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | +
|
| 115 | + branch_sha="$(git ls-remote origin "refs/heads/${RELEASE_BRANCH}" | awk '{print $1}')" |
| 116 | + tag_commit="$(git rev-list -n 1 "${RELEASE_TAG}")" |
| 117 | +
|
| 118 | + [[ "${branch_sha}" == "${EXPECTED_SHA}" ]] || { |
| 119 | + echo "::error::${RELEASE_BRANCH} points at ${branch_sha}, expected ${EXPECTED_SHA}" |
| 120 | + exit 1 |
| 121 | + } |
| 122 | + [[ "${tag_commit}" == "${EXPECTED_SHA}" ]] || { |
| 123 | + echo "::error::${RELEASE_TAG} points at ${tag_commit}, expected ${EXPECTED_SHA}" |
| 124 | + exit 1 |
| 125 | + } |
| 126 | +
|
| 127 | + { |
| 128 | + git ls-remote origin "refs/heads/main" || true |
| 129 | + git ls-remote origin "refs/heads/release/*" || true |
| 130 | + git ls-remote origin "refs/tags/v*" || true |
| 131 | + } | sort > "${RUNNER_TEMP}/production-after.txt" |
| 132 | + diff -u "${RUNNER_TEMP}/production-before.txt" "${RUNNER_TEMP}/production-after.txt" |
| 133 | +
|
| 134 | + echo "${RELEASE_BRANCH} and ${RELEASE_TAG} point at ${EXPECTED_SHA}" |
0 commit comments