-
Notifications
You must be signed in to change notification settings - Fork 712
136 lines (115 loc) · 5.23 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
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.0'
- name: Install CocoaPods
run: gem install cocoapods
- name: Use Latest Stable Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Install visionOS Platform
shell: bash
run: |
# See https://github.com/actions/runner-images/issues/8144#issuecomment-1902072070
defaults write com.apple.dt.Xcode AllowUnsupportedVisionOSHost -bool YES
defaults write com.apple.CoreSimulator AllowUnsupportedVisionOSHost -bool YES
xcodebuild -downloadPlatform visionOS
- 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 .
git commit -m "Update version to ${{ github.event.inputs.version }}"
git push
- name: Create git tag
id: create_tag
run: |
git tag ${{ github.event.inputs.version }}
git push origin ${{ github.event.inputs.version }}
- name: Publish to CocoaPods
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_PASSWORD }}
run: pod trunk push KSCrash.podspec --verbose
rollback:
runs-on: macos-latest
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: |
echo "Attempting to delete local tag ${{ github.event.inputs.version }}..."
git tag -d ${{ github.event.inputs.version }} || echo "Tag not found locally"
echo "Local tag deletion process completed."
- name: Delete git tag remotely
run: |
echo "Attempting to delete remote tag ${{ github.event.inputs.version }}..."
git push --delete origin ${{ github.event.inputs.version }} || 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: Revert version commit
run: |
echo "Identifying the last commit..."
previous_commit=$(git rev-list -n 1 HEAD)
echo "Last commit identified: $previous_commit"
echo "Attempting to revert commit $previous_commit..."
git revert --no-commit $previous_commit
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
run: |
echo "Pushing reverted changes to remote..."
git push || { echo "Push failed. Checking remote status..."; git status; exit 1; }
echo "Push completed."