|
| 1 | +# Copyright (C) 2026 The Android Open Source Project |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Promotes canary to stable and tags the release. |
| 16 | +# |
| 17 | +# Creates a merge commit on `stable` whose tree equals the current tip of |
| 18 | +# `canary` (same tree-replacing merge pattern as cut-canary.yml), reads |
| 19 | +# the target version from the top of CHANGELOG (which must already have |
| 20 | +# been updated from 'Unreleased:' to 'vX.Y - YYYY-MM-DD:' before running), |
| 21 | +# then creates and pushes the vX.Y git tag at the new stable HEAD. |
| 22 | +# |
| 23 | +# The tag push is the single event that fans out to LUCI, Cloud Build, |
| 24 | +# and draft-release.yml. See RFC-0022. |
| 25 | + |
| 26 | +name: Promote canary to stable |
| 27 | + |
| 28 | +on: |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +permissions: |
| 32 | + contents: write # Required to push stable and the tag |
| 33 | + |
| 34 | +jobs: |
| 35 | + promote-stable: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + environment: stable |
| 38 | + steps: |
| 39 | + - name: Checkout stable |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + ref: stable |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Fetch canary |
| 46 | + run: git fetch origin canary |
| 47 | + |
| 48 | + - name: Short-circuit if stable already matches canary |
| 49 | + run: | |
| 50 | + if [[ "$(git rev-parse HEAD^{tree})" == \ |
| 51 | + "$(git rev-parse origin/canary^{tree})" ]]; then |
| 52 | + echo "::error::stable tree already matches canary; nothing to \ |
| 53 | +promote. Cut canary first." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + |
| 57 | + - name: Extract version from CHANGELOG |
| 58 | + id: version |
| 59 | + run: | |
| 60 | + # First non-whitespace line must be a released version header. |
| 61 | + # Anything else (e.g. still 'Unreleased:') means the release |
| 62 | + # hasn't been marked ready. Update CHANGELOG on main, re-cut |
| 63 | + # canary, and retry. |
| 64 | + FIRST=$(git show "origin/canary:CHANGELOG" \ |
| 65 | + | grep -m1 -E '^[^[:space:]]' || true) |
| 66 | + if ! [[ "$FIRST" =~ ^(v[0-9]+\.[0-9]+)[[:space:]]+-[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}: ]]; then |
| 67 | + echo "::error::CHANGELOG top entry is not a released version \ |
| 68 | +header (got: '$FIRST'). Update CHANGELOG to 'vX.Y - YYYY-MM-DD:' on main, \ |
| 69 | +re-cut canary, and retry." |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + VERSION="${BASH_REMATCH[1]}" |
| 73 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 74 | + echo "::notice::Promoting as $VERSION" |
| 75 | + |
| 76 | + - name: Verify tag does not already exist |
| 77 | + run: | |
| 78 | + VERSION="${{ steps.version.outputs.version }}" |
| 79 | + if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then |
| 80 | + echo "::error::Tag $VERSION already exists. Bump CHANGELOG to \ |
| 81 | +the next version on main and re-cut canary." |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + |
| 85 | + - name: Configure git |
| 86 | + run: | |
| 87 | + git config user.name "github-actions[bot]" |
| 88 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 89 | +
|
| 90 | + - name: Merge canary into stable (replace tree with canary) |
| 91 | + run: | |
| 92 | + git merge -s ours origin/canary --no-commit |
| 93 | + git read-tree -m -u origin/canary |
| 94 | + git commit -m "Promote canary to stable (${{ steps.version.outputs.version }}, automated)" |
| 95 | +
|
| 96 | + - name: Push stable |
| 97 | + run: | |
| 98 | + git push origin HEAD:stable |
| 99 | +
|
| 100 | + - name: Create and push tag |
| 101 | + run: | |
| 102 | + VERSION="${{ steps.version.outputs.version }}" |
| 103 | + git tag -a "$VERSION" HEAD -m "Perfetto $VERSION" |
| 104 | + git push origin "refs/tags/$VERSION" |
| 105 | + echo "::notice::Tagged $VERSION at $(git rev-parse HEAD). \ |
| 106 | +LUCI, Cloud Build, and draft-release.yml have been triggered." |
0 commit comments