-
Notifications
You must be signed in to change notification settings - Fork 0
261 lines (228 loc) · 8.6 KB
/
Copy pathrelease.yml
File metadata and controls
261 lines (228 loc) · 8.6 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: Release
on:
workflow_call:
inputs:
action-runs-on:
description: 'The type of runner to run the job on'
required: false
default: 'ubuntu-latest'
type: string
ref:
description: 'Git ref to checkout (branch or SHA)'
required: false
type: string
default: 'release'
build:
required: false
type: string
default: 'false'
commit:
required: false
type: string
default: 'true'
git_config_user:
required: false
type: string
description: 'User name to use for git commits'
default: 'FacsimiLab Bot'
git_config_email:
required: false
type: string
default: '195262995+facsimilab-bot@users.noreply.github.com'
tag:
required: false
type: string
default: 'true'
changelog:
required: false
type: string
default: 'true'
vcs_release:
required: false
type: string
default: 'true'
push:
required: false
type: string
default: 'true'
secrets:
SSH_PRIVATE_KEY:
required: false
SSH_PUBLIC_KEY:
required: false
permissions:
id-token: write
contents: write
pull-requests: read
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
jobs:
release:
runs-on: ${{ inputs.action-runs-on }}
env:
LOG_FILE: ${{ github.workspace }}/.github/log/ci.log
steps:
- name: Checkout Repository at workflow SHA
uses: actions/checkout@v6.0.1
with:
fetch-depth: 0
ref: ${{ inputs.ref }}
- name: Force correct release branch on workflow SHA
run: git checkout -B ${{ inputs.ref }}
- name: Checkout central workflows
uses: actions/checkout@v6.0.1
with:
repository: FacsimiLab/central-workflows
path: .central-workflows
- name: Detect SSH key
id: ssh_key_present
uses: ./.github/actions/secret-present
with:
value: ${{ secrets.SSH_PRIVATE_KEY || '' }}
- name: Set up SSH agent
if: ${{ steps.ssh_key_present.outputs.present == 'true' }}
uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Setup Git Config
run: |
git config --global user.name "${{ inputs.git_config_user }}"
git config --global user.email "${{ inputs.git_config_email }}"
git config include.path "${{ github.workspace }}/.central-workflows/scripts/git/addon-git-config.toml"
- name: Convert HTTPS remote to SSH
if: ${{ steps.ssh_key_present.outputs.present == 'true' }}
run: |
HTTPS_URL=$(git remote get-url origin)
if [[ "$HTTPS_URL" == https://github.com/* ]]; then
SSH_URL=$(echo "$HTTPS_URL" | sed -E 's#https://github.com/#git@github.com:#')
git remote set-url origin "$SSH_URL"
fi
git remote -v
- name: Add github host keys
if: ${{ steps.ssh_key_present.outputs.present == 'true' }}
run: |
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Get the latest CHANGELOG from the `log` branch or initialize it
env:
LOG_FILE: ${{ github.workspace }}/.github/log/ci.log
run: |
bash ./.central-workflows/scripts/git/log-worktree.sh
- name: List and delete pre-release tags
id: list_tags
run: |
echo "Searching for tags containing 'rc', 'main', 'beta', or 'alpha'."
TAGS=$(git tag -l "*-rc*" "*-main*" "*-beta*" "*-alpha*")
echo "Found tags:"
echo "$TAGS"
if [ -z "$TAGS" ]; then
echo "No pre-release tags found."
echo "tags_to_delete=" > tags.log
else
echo "tags_to_delete=$TAGS" > tags.log
echo "Deleting local tags..."
echo $TAGS | xargs -n 1 git tag -d
echo "Deleting remote tags..."
for TAG in $TAGS; do
git push origin --delete $TAG || echo "Failed to delete $TAG from remote."
done
fi
echo "Completed deleting all tags containing 'rc', 'main', 'beta', or 'alpha'."
echo "Completed deleting all tags containing 'rc', 'main', 'beta', or 'alpha'." >> $GITHUB_STEP_SUMMARY
- name: Check for PSR config file
id: psr-config-file
run: |
if [ -f pyproject.toml ]; then
echo "path=pyproject.toml" >> $GITHUB_OUTPUT
echo "Found pyproject.toml"
elif [ -f releaserc.toml ]; then
echo "path=releaserc.toml" >> $GITHUB_OUTPUT
echo "Found releaserc.toml"
else
echo "No config file found"
fi
- name: Define PSR root options
id: psr-root-options
run: |
if [ -n "${{ steps.psr-config-file.outputs.path }}" ]; then
echo "root_options='-v -c ${{ steps.psr-config-file.outputs.path }}'" >> $GITHUB_STEP_SUMMARY
else
echo "root_options='-v'" >> $GITHUB_STEP_SUMMARY
fi
- name: Display PSR root options
run: |
echo "Using PSR root options: ${{ steps.psr-root-options.outputs.root_options }}"
- name: Python Semantic Release
id: psr-ci
uses: pranavmishra90/semvar-docker@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_email: ${{ inputs.git_config_email }}
ssh_private_signing_key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh_public_signing_key: ${{ secrets.SSH_PUBLIC_KEY }}
build: ${{ inputs.build }}
changelog: ${{ inputs.changelog }}
commit: ${{ inputs.commit }}
tag: ${{ inputs.tag }}
vcs_release: ${{ inputs.vcs_release }}
push: ${{ inputs.push }}
root_options: ${{ steps.psr-root-options.outputs.root_options }}
- name: Add logger to workflow summary
run: |
echo "## Logger Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat $LOG_FILE >> $GITHUB_STEP_SUMMARY || echo "No log output available." >> $GITHUB_STEP_SUMMARY
- name: Workflow Status
run: |
echo "## Python Semantic Release - GitHub Action" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ steps.psr-ci.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
printf "Tags: \n$(git tag -l)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Released: ${{ steps.psr-ci.outputs.released }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat CHANGELOG.md >> $GITHUB_STEP_SUMMARY
# update-main:
# runs-on: ${{ inputs.action-runs-on }}
# if: startsWith(github.ref_name, 'release')
# needs: continuous-delivery
# permissions:
# contents: write
# steps:
# - name: Checkout Repository at workflow SHA
# uses: actions/checkout@v6.0.1
# with:
# fetch-depth: 0
# ref: ${{ inputs.ref }}
# - name: Force correct release branch on workflow SHA
# run: git checkout -B ${{ inputs.ref }}
# - name: Set up SSH agent
# uses: webfactory/ssh-agent@v0.9.1
# with:
# ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
# - name: Convert HTTPS remote to SSH
# run: |
# HTTPS_URL=$(git remote get-url origin)
# if [[ "$HTTPS_URL" == https://github.com/* ]]; then
# SSH_URL=$(echo "$HTTPS_URL" | sed -E 's#https://github.com/#git@github.com:#')
# git remote set-url origin "$SSH_URL"
# fi
# git remote -v
# - name: Update main branch
# run: |
# BRANCH=$(git rev-parse --abbrev-ref HEAD)
# if [ "$BRANCH" != "release" ]; then
# echo "Not on release branch ($BRANCH), skipping merge to main."
# exit 0
# fi
# # Ensure main is up to date
# git fetch origin main:main
# git checkout main || git checkout -b main origin/main
# if git merge release -v -m "ci: merge release into main"; then
# git push origin main
# echo "Successfully merged 'release' into 'main' and pushed." >> $GITHUB_STEP_SUMMARY
# else
# echo "Merge failed — possible conflicts. Manual resolution required." >> $GITHUB_STEP_SUMMARY
# exit 1
# fi