|
1 | 1 | name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - "*" |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Marketing version and tag (for example: 0.3.0)" |
| 8 | + required: true |
| 9 | + type: string |
7 | 10 |
|
8 | 11 | permissions: |
9 | 12 | contents: write |
10 | 13 |
|
| 14 | +concurrency: |
| 15 | + group: release |
| 16 | + cancel-in-progress: false |
| 17 | + |
11 | 18 | jobs: |
12 | 19 | release: |
13 | 20 | runs-on: macos-26 |
14 | 21 | timeout-minutes: 30 |
15 | 22 |
|
16 | 23 | steps: |
17 | 24 | - uses: actions/checkout@v6 |
| 25 | + with: |
| 26 | + ref: main |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Validate version |
| 30 | + env: |
| 31 | + VERSION: ${{ inputs.version }} |
| 32 | + run: | |
| 33 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 34 | + echo "::error::Version must use the x.y.z format." |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +
|
| 38 | + if git rev-parse --verify --quiet "refs/tags/$VERSION"; then |
| 39 | + echo "::error::Tag $VERSION already exists." |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Update marketing version |
| 44 | + env: |
| 45 | + VERSION: ${{ inputs.version }} |
| 46 | + run: | |
| 47 | + ruby <<'RUBY' |
| 48 | + path = "TrackpadAir.xcodeproj/project.pbxproj" |
| 49 | + project = File.read(path) |
| 50 | + version = ENV.fetch("VERSION") |
| 51 | + updated_configurations = 0 |
| 52 | +
|
| 53 | + updated_project = project.gsub( |
| 54 | + /(\w+ \/\* (?:Debug|Release) \*\/ = \{\n\s+isa = XCBuildConfiguration;.*?\n\s+\};)/m |
| 55 | + ) do |configuration| |
| 56 | + unless configuration.include?("PRODUCT_BUNDLE_IDENTIFIER = com.TrackpadAir;") |
| 57 | + next configuration |
| 58 | + end |
| 59 | +
|
| 60 | + updated_configuration = configuration.sub( |
| 61 | + /MARKETING_VERSION = [^;]+;/, |
| 62 | + "MARKETING_VERSION = #{version};" |
| 63 | + ) |
| 64 | +
|
| 65 | + if updated_configuration == configuration |
| 66 | + abort "MARKETING_VERSION was not found in an app build configuration" |
| 67 | + end |
| 68 | +
|
| 69 | + updated_configurations += 1 |
| 70 | + updated_configuration |
| 71 | + end |
| 72 | +
|
| 73 | + unless updated_configurations == 2 |
| 74 | + abort "Expected to update 2 app build configurations, updated #{updated_configurations}" |
| 75 | + end |
| 76 | +
|
| 77 | + File.write(path, updated_project) |
| 78 | + RUBY |
| 79 | +
|
| 80 | + - name: Push version and tag |
| 81 | + env: |
| 82 | + VERSION: ${{ inputs.version }} |
| 83 | + run: | |
| 84 | + if git diff --quiet -- TrackpadAir.xcodeproj/project.pbxproj; then |
| 85 | + echo "::error::Marketing version is already $VERSION." |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | +
|
| 89 | + git config user.name "github-actions[bot]" |
| 90 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 91 | + git add TrackpadAir.xcodeproj/project.pbxproj |
| 92 | + git commit -m "Bump version to $VERSION" |
| 93 | + git push origin HEAD:main |
| 94 | + git tag "$VERSION" |
| 95 | + git push origin "$VERSION" |
18 | 96 |
|
19 | 97 | - name: Import signing certificate |
20 | 98 | env: |
|
63 | 141 | - name: Create GitHub release |
64 | 142 | env: |
65 | 143 | GH_TOKEN: ${{ github.token }} |
| 144 | + VERSION: ${{ inputs.version }} |
66 | 145 | run: | |
67 | | - gh release create "$GITHUB_REF_NAME" \ |
| 146 | + gh release create "$VERSION" \ |
68 | 147 | TrackpadAir.app.zip \ |
69 | 148 | --generate-notes \ |
70 | 149 | --verify-tag |
|
0 commit comments