|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Unified release script for WASI releases |
| 4 | +# |
| 5 | +# This script automates the release process for both patch (0.2.x) and RC (0.3.0-rc) releases: |
| 6 | +# 1. Triggers the release.yml workflow to update versions and create PR |
| 7 | +# 2. Waits for PR to be filed and CI to pass |
| 8 | +# 3. Waits for manual PR review and merge |
| 9 | +# 4. Creates a GitHub release to trigger publishing |
| 10 | +# 5. Waits for publish workflow to complete (validates packages in CI) |
| 11 | +# |
| 12 | +# Usage: |
| 13 | +# Patch release: ./release.sh --type patch --prev 0.2.8 --next 0.2.9 |
| 14 | +# RC release: ./release.sh --type rc [--prev-rc-date 2025-09-16] |
| 15 | + |
| 16 | +set -e |
| 17 | +set -x |
| 18 | + |
| 19 | +# Parse arguments |
| 20 | +RELEASE_TYPE="" |
| 21 | +PREV_VERSION="" |
| 22 | +NEXT_VERSION="" |
| 23 | +PREV_RC_DATE="" |
| 24 | + |
| 25 | +while [[ $# -gt 0 ]]; do |
| 26 | + case $1 in |
| 27 | + --type) RELEASE_TYPE="$2"; shift 2 ;; |
| 28 | + --prev) PREV_VERSION="$2"; shift 2 ;; |
| 29 | + --next) NEXT_VERSION="$2"; shift 2 ;; |
| 30 | + --prev-rc-date) PREV_RC_DATE="$2"; shift 2 ;; |
| 31 | + -h|--help) |
| 32 | + echo "Usage:" |
| 33 | + echo " Patch release: $0 --type patch --prev <prev_version> --next <next_version>" |
| 34 | + echo " RC release: $0 --type rc [--prev-rc-date <YYYY-MM-DD>]" |
| 35 | + echo "" |
| 36 | + echo "Examples:" |
| 37 | + echo " $0 --type patch --prev 0.2.8 --next 0.2.9" |
| 38 | + echo " $0 --type rc --prev-rc-date 2025-09-16" |
| 39 | + echo " $0 --type rc # First RC, no previous date" |
| 40 | + exit 0 |
| 41 | + ;; |
| 42 | + *) |
| 43 | + echo "Unknown option: $1" |
| 44 | + echo "Use --help for usage information" |
| 45 | + exit 1 |
| 46 | + ;; |
| 47 | + esac |
| 48 | +done |
| 49 | + |
| 50 | +# Configuration |
| 51 | +DATE="$(date +'%Y-%m-%d')" |
| 52 | +REPO="WebAssembly/WASI" |
| 53 | + |
| 54 | +# Configure based on release type |
| 55 | +if [ "$RELEASE_TYPE" == "patch" ]; then |
| 56 | + if [ -z "$PREV_VERSION" ] || [ -z "$NEXT_VERSION" ]; then |
| 57 | + echo "Error: Patch release requires --prev and --next" |
| 58 | + echo "Example: $0 --type patch --prev 0.2.8 --next 0.2.9" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + TAG="v$NEXT_VERSION" |
| 62 | + PRERELEASE_FLAG="" |
| 63 | + RELEASE_LABEL="Patch" |
| 64 | +elif [ "$RELEASE_TYPE" == "rc" ]; then |
| 65 | + NEXT_VERSION="0.3.0-rc-$DATE" |
| 66 | + TAG="v$NEXT_VERSION" |
| 67 | + PRERELEASE_FLAG="--prerelease" |
| 68 | + RELEASE_LABEL="RC" |
| 69 | +else |
| 70 | + echo "Error: --type must be 'patch' or 'rc'" |
| 71 | + echo "Use --help for usage information" |
| 72 | + exit 1 |
| 73 | +fi |
| 74 | + |
| 75 | +echo "============================================" |
| 76 | +echo "WASI $RELEASE_LABEL Release" |
| 77 | +echo "============================================" |
| 78 | +if [ "$RELEASE_TYPE" == "patch" ]; then |
| 79 | + echo "Previous version: $PREV_VERSION" |
| 80 | +else |
| 81 | + echo "Previous RC date: ${PREV_RC_DATE:-'(none/first RC)'}" |
| 82 | +fi |
| 83 | +echo "Next version: $NEXT_VERSION" |
| 84 | +echo "Tag: $TAG" |
| 85 | +echo "Repository: $REPO" |
| 86 | +echo "============================================" |
| 87 | + |
| 88 | +# Ensure we're operating on the correct repo |
| 89 | +gh repo set-default "$REPO" |
| 90 | + |
| 91 | +# Check if release already exists |
| 92 | +if gh release view "$TAG" &>/dev/null; then |
| 93 | + echo "Error: Release $TAG already exists!" |
| 94 | + echo "If you need to re-run, delete the release first:" |
| 95 | + echo " gh release delete $TAG --yes" |
| 96 | + exit 1 |
| 97 | +fi |
| 98 | + |
| 99 | +# Step 1: Trigger the release workflow |
| 100 | +echo "" |
| 101 | +echo "Step 1: Triggering release.yml workflow..." |
| 102 | + |
| 103 | +if [ "$RELEASE_TYPE" == "patch" ]; then |
| 104 | + gh workflow run "release.yml" \ |
| 105 | + -f release_type="patch" \ |
| 106 | + -f prev_version="$PREV_VERSION" \ |
| 107 | + -f next_version="$NEXT_VERSION" |
| 108 | +else |
| 109 | + if [ -n "$PREV_RC_DATE" ]; then |
| 110 | + gh workflow run "release.yml" \ |
| 111 | + -f release_type="rc" \ |
| 112 | + -f prev_rc_date="$PREV_RC_DATE" |
| 113 | + else |
| 114 | + gh workflow run "release.yml" \ |
| 115 | + -f release_type="rc" |
| 116 | + fi |
| 117 | +fi |
| 118 | + |
| 119 | +# Wait for workflow to start |
| 120 | +echo "Waiting for workflow to start..." |
| 121 | +sleep 10 |
| 122 | + |
| 123 | +# Get the run ID |
| 124 | +RUN_ID="$(gh run list --workflow "release.yml" --created "$DATE" --json databaseId --limit 1 | jq -r '.[0].databaseId')" |
| 125 | +if [ -z "$RUN_ID" ] || [ "$RUN_ID" == "null" ]; then |
| 126 | + echo "Error: Could not find workflow run" |
| 127 | + exit 1 |
| 128 | +fi |
| 129 | + |
| 130 | +echo "Workflow run ID: $RUN_ID" |
| 131 | +echo "Waiting for workflow to complete..." |
| 132 | +gh run watch "$RUN_ID" --exit-status || { |
| 133 | + echo "Error: Workflow failed!" |
| 134 | + gh run view "$RUN_ID" --log-failed |
| 135 | + exit 1 |
| 136 | +} |
| 137 | + |
| 138 | +# Step 2: Wait for PR and CI |
| 139 | +echo "" |
| 140 | +echo "Step 2: Waiting for PR..." |
| 141 | +sleep 5 |
| 142 | + |
| 143 | +PR_NUMBER="$(gh pr list --head "release-v$NEXT_VERSION" --json number --limit 1 | jq -r '.[0].number')" |
| 144 | +if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" == "null" ]; then |
| 145 | + echo "Error: Could not find PR for release-v$NEXT_VERSION" |
| 146 | + exit 1 |
| 147 | +fi |
| 148 | + |
| 149 | +echo "PR #$PR_NUMBER created" |
| 150 | + |
| 151 | +# Close and reopen to trigger CI (workaround for some CI configurations) |
| 152 | +echo "Retriggering CI..." |
| 153 | +gh pr close "$PR_NUMBER" |
| 154 | +gh pr reopen "$PR_NUMBER" |
| 155 | + |
| 156 | +echo "Waiting for CI checks to pass..." |
| 157 | +sleep 10 |
| 158 | +gh pr checks "$PR_NUMBER" --watch || { |
| 159 | + echo "Warning: Some checks may have failed. Continuing anyway..." |
| 160 | +} |
| 161 | + |
| 162 | +# Step 3: Wait for manual PR review and merge |
| 163 | +echo "" |
| 164 | +echo "Step 3: PR ready for review" |
| 165 | +echo "============================================" |
| 166 | +echo "PR #$PR_NUMBER: https://github.com/$REPO/pull/$PR_NUMBER" |
| 167 | +echo "============================================" |
| 168 | +echo "" |
| 169 | +read -r -p "Press Enter after the PR has been reviewed and merged..." |
| 170 | + |
| 171 | +# Verify PR was actually merged |
| 172 | +STATE="$(gh pr view "$PR_NUMBER" --json state --jq '.state')" |
| 173 | +if [ "$STATE" != "MERGED" ]; then |
| 174 | + echo "Error: PR #$PR_NUMBER is not merged (state: $STATE)" |
| 175 | + exit 1 |
| 176 | +fi |
| 177 | + |
| 178 | +# Step 4: Create GitHub release |
| 179 | +echo "" |
| 180 | +echo "Step 4: Creating GitHub release $TAG..." |
| 181 | +sleep 5 |
| 182 | + |
| 183 | +gh release create "$TAG" --generate-notes $PRERELEASE_FLAG |
| 184 | +gh release view "$TAG" |
| 185 | + |
| 186 | +# Step 5: Wait for publish workflow |
| 187 | +echo "" |
| 188 | +echo "Step 5: Waiting for publish workflow to complete..." |
| 189 | +sleep 10 |
| 190 | + |
| 191 | +PUBLISH_RUN_ID="$(gh run list --workflow "publish.yml" --created "$DATE" --json databaseId --limit 1 | jq -r '.[0].databaseId')" |
| 192 | +if [ -z "$PUBLISH_RUN_ID" ] || [ "$PUBLISH_RUN_ID" == "null" ]; then |
| 193 | + echo "Warning: Could not find publish workflow run. It may not have started yet." |
| 194 | + sleep 30 |
| 195 | + PUBLISH_RUN_ID="$(gh run list --workflow "publish.yml" --created "$DATE" --json databaseId --limit 1 | jq -r '.[0].databaseId')" |
| 196 | +fi |
| 197 | + |
| 198 | +if [ -n "$PUBLISH_RUN_ID" ] && [ "$PUBLISH_RUN_ID" != "null" ]; then |
| 199 | + echo "Publish workflow run ID: $PUBLISH_RUN_ID" |
| 200 | + gh run watch "$PUBLISH_RUN_ID" --exit-status || { |
| 201 | + echo "Error: Publish workflow failed!" |
| 202 | + gh run view "$PUBLISH_RUN_ID" --log-failed |
| 203 | + exit 1 |
| 204 | + } |
| 205 | +fi |
| 206 | + |
| 207 | +echo "" |
| 208 | +echo "============================================" |
| 209 | +echo "✓ Release $NEXT_VERSION ($RELEASE_LABEL) completed successfully!" |
| 210 | +echo "============================================" |
0 commit comments