This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (131 loc) · 5.28 KB
/
rollback.yml
File metadata and controls
148 lines (131 loc) · 5.28 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
name: Rollback Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to rollback (e.g., v1.2.3)'
required: true
type: string
delete_release:
description: 'Delete the GitHub release'
required: false
type: boolean
default: false
reason:
description: 'Reason for rollback'
required: false
type: string
default: 'Manual rollback'
jobs:
rollback:
name: Rollback Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Validate version format
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc))?$ ]]; then
echo "::error::Invalid version format: $VERSION (expected vX.Y.Z or vX.Y.Z-{alpha|beta|rc})"
exit 1
fi
- name: Notify rollback start
id: slack_start
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: ":rewind: *iii-console Rollback Started*\nVersion: `${{ inputs.version }}`\nReason: ${{ inputs.reason }}\nDelete release: ${{ inputs.delete_release }}\nTriggered by: ${{ github.actor }}"
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2
with:
app-id: ${{ secrets.III_CI_APP_ID }}
private-key: ${{ secrets.III_CI_APP_PRIVATE_KEY }}
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
- name: Delete release
if: inputs.delete_release == true
env:
VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
GH_REPO: ${{ github.repository }}
run: |
gh release delete "$VERSION" --repo "$GH_REPO" --yes || true
echo "::notice::Deleted release $VERSION"
- name: Delete tag
env:
VERSION: ${{ inputs.version }}
run: |
git push origin ":refs/tags/$VERSION" || true
git tag -d "$VERSION" || true
echo "::notice::Deleted tag $VERSION"
- name: Calculate previous version
id: prev_version
env:
VERSION: ${{ inputs.version }}
run: |
# Strip v prefix and pre-release suffix
BASE=$(echo "$VERSION" | sed 's/^v//' | sed 's/-.*//')
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE"
if [[ "$PATCH" -gt 0 ]]; then
PREV="${MAJOR}.${MINOR}.$((PATCH - 1))"
elif [[ "$MINOR" -gt 0 ]]; then
PREV="${MAJOR}.$((MINOR - 1)).0"
elif [[ "$MAJOR" -gt 0 ]]; then
PREV="$((MAJOR - 1)).0.0"
else
echo "::error::Cannot calculate previous version for v0.0.0"
exit 1
fi
echo "version=$PREV" >> "$GITHUB_OUTPUT"
echo "::notice::Rolling back Cargo.toml to version $PREV"
- name: Update Cargo.toml version
env:
PREV_VERSION: ${{ steps.prev_version.outputs.version }}
run: |
CARGO_TOML="packages/console-rust/Cargo.toml"
sed -i "s/^version = \".*\"/version = \"${PREV_VERSION}\"/" "$CARGO_TOML"
- name: Commit rollback
env:
PREV_VERSION: ${{ steps.prev_version.outputs.version }}
VERSION: ${{ inputs.version }}
REASON: ${{ inputs.reason }}
run: |
git config user.name "iii-ci[bot]"
git config user.email "iii-ci[bot]@users.noreply.github.com"
git add packages/console-rust/Cargo.toml
git commit -m "$(cat <<COMMIT_MSG
chore: rollback version to ${PREV_VERSION}
Rolled back from ${VERSION}
Reason: ${REASON}
COMMIT_MSG
)"
git push origin main
- name: Notify rollback complete
if: success()
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
method: chat.update
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
ts: ${{ steps.slack_start.outputs.ts }}
text: ":white_check_mark: *iii-console Rollback Complete*\nRolled back: `${{ inputs.version }}` -> `v${{ steps.prev_version.outputs.version }}`\nReason: ${{ inputs.reason }}\nRelease deleted: ${{ inputs.delete_release }}"
- name: Notify rollback failed
if: failure()
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
method: chat.update
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
ts: ${{ steps.slack_start.outputs.ts }}
text: ":x: *iii-console Rollback Failed*\nVersion: `${{ inputs.version }}`\nReason: ${{ inputs.reason }}\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View workflow>"