|
| 1 | +name: Release Pre-release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_base: |
| 7 | + description: 'Version base (e.g., 3.5.0)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + prerelease_type: |
| 11 | + description: 'Pre-release type' |
| 12 | + required: true |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - alpha |
| 16 | + - beta |
| 17 | + - rc |
| 18 | + default: 'alpha' |
| 19 | + prerelease_number: |
| 20 | + description: 'Pre-release number (e.g., 1)' |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + branch: |
| 24 | + description: 'Branch to create release from' |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + default: 'main' |
| 28 | + dry_run: |
| 29 | + description: 'Dry run (validate only, do not create tag/release)' |
| 30 | + required: false |
| 31 | + type: boolean |
| 32 | + default: false |
| 33 | + |
| 34 | +jobs: |
| 35 | + validate-and-release: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Construct and validate version |
| 40 | + id: version |
| 41 | + run: | |
| 42 | + VERSION_BASE="${{ github.event.inputs.version_base }}" |
| 43 | + PRERELEASE_TYPE="${{ github.event.inputs.prerelease_type }}" |
| 44 | + PRERELEASE_NUMBER="${{ github.event.inputs.prerelease_number }}" |
| 45 | +
|
| 46 | + if [[ ! "$VERSION_BASE" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 47 | + echo "Invalid version base: $VERSION_BASE (expected X.Y.Z)" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + if [[ ! "$PRERELEASE_NUMBER" =~ ^[0-9]+$ ]]; then |
| 52 | + echo "Invalid pre-release number: $PRERELEASE_NUMBER" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + FULL_VERSION="${VERSION_BASE}-${PRERELEASE_TYPE}.${PRERELEASE_NUMBER}" |
| 57 | + echo "version=${FULL_VERSION}" >> $GITHUB_OUTPUT |
| 58 | + echo "Version: $FULL_VERSION" |
| 59 | +
|
| 60 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 61 | + with: |
| 62 | + ref: ${{ github.event.inputs.branch }} |
| 63 | + fetch-depth: 0 |
| 64 | + |
| 65 | + - name: Check if tag already exists |
| 66 | + run: | |
| 67 | + VERSION="${{ steps.version.outputs.version }}" |
| 68 | + if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then |
| 69 | + echo "Tag $VERSION already exists" |
| 70 | + git tag -l "${{ github.event.inputs.version_base }}-*" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Setup |
| 75 | + uses: ./.github/actions/setup |
| 76 | + |
| 77 | + - name: Verify pre-release version format |
| 78 | + run: | |
| 79 | + VERSION="${{ steps.version.outputs.version }}" |
| 80 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-(alpha|beta|rc)\.[0-9]+$ ]]; then |
| 81 | + echo "ERROR: Version $VERSION does not match pre-release format" |
| 82 | + echo "Expected format: X.Y.Z-{alpha|beta|rc}.N" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + echo "✅ Version format verified: $VERSION" |
| 86 | +
|
| 87 | + - name: Update package.json version |
| 88 | + run: | |
| 89 | + VERSION="${{ steps.version.outputs.version }}" |
| 90 | + cd modules/@shopify/checkout-sheet-kit |
| 91 | + npm version "$VERSION" --no-git-tag-version |
| 92 | + echo "Updated package.json to version: $VERSION" |
| 93 | + cat package.json | grep '"version"' |
| 94 | +
|
| 95 | + - name: Validate build |
| 96 | + run: | |
| 97 | + set -eo pipefail |
| 98 | + yarn module build |
| 99 | + echo "Build successful" |
| 100 | +
|
| 101 | + - name: Dry Run Summary |
| 102 | + if: github.event.inputs.dry_run == 'true' |
| 103 | + run: | |
| 104 | + VERSION="${{ steps.version.outputs.version }}" |
| 105 | + BRANCH="${{ github.event.inputs.branch }}" |
| 106 | + echo "DRY RUN - Would create $VERSION from $BRANCH" |
| 107 | + echo "All validations passed" |
| 108 | + echo "" |
| 109 | + echo "Next steps (not executed in dry run):" |
| 110 | + echo " 1. Commit package.json changes" |
| 111 | + echo " 2. Create and push git tag" |
| 112 | + echo " 3. Create GitHub pre-release" |
| 113 | + echo " 4. NPM publish will be triggered automatically with 'next' dist-tag" |
| 114 | +
|
| 115 | + - name: Commit package.json changes |
| 116 | + if: github.event.inputs.dry_run != 'true' |
| 117 | + run: | |
| 118 | + set -e |
| 119 | + VERSION="${{ steps.version.outputs.version }}" |
| 120 | + BRANCH="${{ github.event.inputs.branch }}" |
| 121 | + git config user.name "github-actions[bot]" |
| 122 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 123 | + git add modules/@shopify/checkout-sheet-kit/package.json |
| 124 | + git commit -m "Bump version to $VERSION" |
| 125 | +
|
| 126 | + if ! git push origin "$BRANCH"; then |
| 127 | + echo "ERROR: Failed to push version bump to $BRANCH" |
| 128 | + echo "This could be due to branch protection rules or conflicts" |
| 129 | + exit 1 |
| 130 | + fi |
| 131 | + echo "✅ Successfully pushed version bump to $BRANCH" |
| 132 | +
|
| 133 | + - name: Create and push tag |
| 134 | + if: github.event.inputs.dry_run != 'true' |
| 135 | + run: | |
| 136 | + set -e |
| 137 | + VERSION="${{ steps.version.outputs.version }}" |
| 138 | + BRANCH="${{ github.event.inputs.branch }}" |
| 139 | + PRERELEASE_TYPE="${{ github.event.inputs.prerelease_type }}" |
| 140 | + git config user.name "github-actions[bot]" |
| 141 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 142 | + git tag -a "$VERSION" -m "$PRERELEASE_TYPE release $VERSION from branch $BRANCH" |
| 143 | +
|
| 144 | + if ! git push origin "$VERSION"; then |
| 145 | + echo "ERROR: Failed to push tag $VERSION" |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + echo "✅ Successfully pushed tag $VERSION" |
| 149 | +
|
| 150 | + - name: Create GitHub Pre-release |
| 151 | + if: github.event.inputs.dry_run != 'true' |
| 152 | + env: |
| 153 | + GH_TOKEN: ${{ github.token }} |
| 154 | + run: | |
| 155 | + VERSION="${{ steps.version.outputs.version }}" |
| 156 | + BRANCH="${{ github.event.inputs.branch }}" |
| 157 | + PRERELEASE_TYPE="${{ github.event.inputs.prerelease_type }}" |
| 158 | +
|
| 159 | + case "$PRERELEASE_TYPE" in |
| 160 | + alpha) EMOJI="🧪"; LABEL="Alpha" ;; |
| 161 | + beta) EMOJI="🚧"; LABEL="Beta" ;; |
| 162 | + rc) EMOJI="🎯"; LABEL="Release Candidate" ;; |
| 163 | + esac |
| 164 | +
|
| 165 | + RELEASE_NOTES=$(cat <<EOF |
| 166 | + Pre-release from branch: $BRANCH |
| 167 | +
|
| 168 | + ⚠️ This pre-release will be published to NPM with the \`next\` dist-tag. |
| 169 | + ⚠️ The \`latest\` tag will NOT be affected. |
| 170 | + EOF |
| 171 | + ) |
| 172 | +
|
| 173 | + gh release create "$VERSION" \ |
| 174 | + --title "$EMOJI $LABEL $VERSION" \ |
| 175 | + --notes "$RELEASE_NOTES" \ |
| 176 | + --prerelease \ |
| 177 | + --target "$BRANCH" |
| 178 | +
|
| 179 | + echo "" |
| 180 | + echo "📦 Pre-release created successfully!" |
| 181 | + echo "🔗 View release: https://github.com/Shopify/checkout-sheet-kit-react-native/releases/tag/$VERSION" |
| 182 | + echo "📋 NPM publish will be triggered automatically by the publish workflow" |
| 183 | + echo "🏷️ Package will be available with 'next' dist-tag (NOT 'latest')" |
0 commit comments