Release #32
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to release' | |
| required: true | |
| dry_run: | |
| description: 'Run in dry-run mode (do not push to CocoaPods)' | |
| type: boolean | |
| default: false | |
| required: false | |
| jobs: | |
| release: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.2.2' | |
| - name: Install Ruby Gems | |
| run: sudo bundle install | |
| - name: Use Latest Stable Xcode | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: latest-stable | |
| - name: Ensure Platforms are Downloaded | |
| run: | | |
| xcodebuild -runFirstLaunch | |
| xcrun simctl list | |
| for platform in iOS watchOS tvOS visionOS; do | |
| echo "Downloading $platform platform..." | |
| xcodebuild -downloadPlatform $platform | |
| xcodebuild -runFirstLaunch | |
| done | |
| - name: Update version in podspec | |
| run: sed -i '' 's/s.version = "[^"]*"/s.version = "${{ github.event.inputs.version }}"/' KSCrash.podspec | |
| - name: Update version in source code | |
| run: | | |
| formatted_version_number=$(echo "${{ github.event.inputs.version }}" | awk -F. '{printf("%d.%02d%02d\n", $1, $2, $3)}') | |
| sed -i '' 's/const double KSCrashFrameworkVersionNumber = [^;]*/const double KSCrashFrameworkVersionNumber = '"$formatted_version_number"'/' Sources/KSCrashRecording/KSCrash.m | |
| sed -i '' 's/const unsigned char KSCrashFrameworkVersionString\[\] = "[^"]*"/const unsigned char KSCrashFrameworkVersionString[] = "${{ github.event.inputs.version }}"/' Sources/KSCrashRecording/KSCrash.m | |
| - name: Update README | |
| run: | | |
| # Update SPM version | |
| sed -i '' "s/\.package(url: \"https:\/\/github.com\/kstenerud\/KSCrash.git\", .upToNextMajor(from: \"[^\"]*\"))/\.package(url: \"https:\/\/github.com\/kstenerud\/KSCrash.git\", .upToNextMajor(from: \"${{ github.event.inputs.version }}\"))/" README.md | |
| # Update CocoaPods version | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [[ "$VERSION" == *"-"* ]]; then | |
| # It's a pre-release version, use the full version | |
| sed -i '' "s/pod 'KSCrash'.*$/pod 'KSCrash', '~> $VERSION'/" README.md | |
| else | |
| # It's a release version, use major.minor | |
| sed -i '' "s/pod 'KSCrash'.*$/pod 'KSCrash', '~> ${VERSION%.*}'/" README.md | |
| fi | |
| echo "README.md updated with version ${{ github.event.inputs.version }}" | |
| - name: Commit version update | |
| id: commit_version | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add . | |
| # Include [dry-run] in commit message if in dry run mode | |
| if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then | |
| git commit -m "[dry-run] Update version to ${{ github.event.inputs.version }}" | |
| else | |
| git commit -m "Update version to ${{ github.event.inputs.version }}" | |
| fi | |
| git push | |
| # Store commit SHA for potential rollback | |
| echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
| - name: Create git tag | |
| id: create_tag | |
| run: | | |
| # Include dry-run prefix in tag if in dry run mode | |
| if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then | |
| TAG_NAME="dry-run-${{ github.event.inputs.version }}" | |
| echo "Using dry-run tag: $TAG_NAME" | |
| else | |
| TAG_NAME="${{ github.event.inputs.version }}" | |
| fi | |
| git tag $TAG_NAME | |
| git push origin $TAG_NAME | |
| echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
| - name: Publish to CocoaPods | |
| if: ${{ !github.event.inputs.dry_run }} | |
| env: | |
| COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_PASSWORD }} | |
| run: pod trunk push KSCrash.podspec --verbose | |
| - name: Skip publishing (dry run) | |
| if: ${{ github.event.inputs.dry_run }} | |
| run: | | |
| echo "Dry run mode enabled - skipping CocoaPods publishing" | |
| echo "Version would have been published: ${{ github.event.inputs.version }}" | |
| rollback: | |
| runs-on: macos-15 | |
| needs: release | |
| if: failure() | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch all tags | |
| run: | | |
| echo "Fetching all tags..." | |
| git fetch --tags | |
| echo "Tags fetched successfully." | |
| - name: Delete git tag locally | |
| run: | | |
| # Determine which tag name to use | |
| if [[ -n "${{ env.TAG_NAME }}" ]]; then | |
| TAG_TO_DELETE="${{ env.TAG_NAME }}" | |
| elif [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then | |
| TAG_TO_DELETE="dry-run-${{ github.event.inputs.version }}" | |
| else | |
| TAG_TO_DELETE="${{ github.event.inputs.version }}" | |
| fi | |
| echo "Attempting to delete local tag $TAG_TO_DELETE..." | |
| git tag -d $TAG_TO_DELETE || echo "Tag not found locally" | |
| echo "Local tag deletion process completed." | |
| echo "TAG_TO_DELETE=$TAG_TO_DELETE" >> $GITHUB_ENV | |
| - name: Delete git tag remotely | |
| run: | | |
| echo "Attempting to delete remote tag ${{ env.TAG_TO_DELETE }}..." | |
| git push --delete origin ${{ env.TAG_TO_DELETE }} || echo "Tag not found on remote" | |
| echo "Remote tag deletion process completed." | |
| - name: Pull latest changes | |
| run: | | |
| echo "Pulling latest changes for the current branch..." | |
| git pull origin "$(git branch --show-current)" | |
| echo "Latest changes pulled successfully." | |
| - name: Check for version commit | |
| id: check_commit | |
| run: | | |
| # Check if we have a commit SHA from the release job | |
| if [[ -n "${{ env.COMMIT_SHA }}" ]]; then | |
| echo "Version commit found, will revert." | |
| echo "SHOULD_REVERT=true" >> $GITHUB_ENV | |
| else | |
| echo "No version commit found, nothing to revert." | |
| echo "SHOULD_REVERT=false" >> $GITHUB_ENV | |
| fi | |
| - name: Revert version commit | |
| if: env.SHOULD_REVERT == 'true' | |
| run: | | |
| echo "Attempting to revert commit ${{ env.COMMIT_SHA }}..." | |
| git revert --no-commit ${{ env.COMMIT_SHA }} | |
| echo "Revert command executed." | |
| echo "Committing the revert with a message..." | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git commit -m "Revert version update due to failed release" | |
| echo "Revert commit completed." | |
| - name: Push revert | |
| if: env.SHOULD_REVERT == 'true' | |
| run: | | |
| echo "Pushing reverted changes to remote..." | |
| git push || { echo "Push failed. Checking remote status..."; git status; exit 1; } | |
| echo "Push completed." |