-
Notifications
You must be signed in to change notification settings - Fork 46
180 lines (161 loc) · 5.97 KB
/
Copy pathremove-unicode-characters.yml
File metadata and controls
180 lines (161 loc) · 5.97 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
name: Build RemoveUnicodeCharacters (SE5)
on:
push:
branches: [main]
paths:
- 'se5/RemoveUnicodeCharacters/**'
- 'se5/Plugin-Shared/**'
- '.github/workflows/remove-unicode-characters.yml'
pull_request:
paths:
- 'se5/RemoveUnicodeCharacters/**'
- 'se5/Plugin-Shared/**'
- '.github/workflows/remove-unicode-characters.yml'
workflow_dispatch:
inputs:
release:
description: 'Publish a GitHub release. Bumps the minor in plugin.json and commits it back.'
type: boolean
default: false
version:
description: 'Optional explicit version (e.g. 1.2.0). Overrides the auto-minor-bump.'
required: false
type: string
permissions:
contents: write
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set.outputs.version }}
tag: ${{ steps.set.outputs.tag }}
ref: ${{ steps.set.outputs.ref }}
release: ${{ steps.set.outputs.release }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve version (and bump on release)
id: set
run: |
set -e
current=$(jq -r .version se5/RemoveUnicodeCharacters/plugin.json)
release_flag="false"
ref="${{ github.sha }}"
version="$current"
tag=""
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.release }}" = "true" ]; then
release_flag="true"
if [ -n "${{ inputs.version }}" ]; then
version="${{ inputs.version }}"
else
IFS=. read -r major minor patch <<< "$current"
version="$major.$((minor + 1)).0"
fi
tmp=$(mktemp)
jq --arg v "$version" '.version = $v' se5/RemoveUnicodeCharacters/plugin.json > "$tmp"
mv "$tmp" se5/RemoveUnicodeCharacters/plugin.json
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add se5/RemoveUnicodeCharacters/plugin.json
git commit -m "Bump RemoveUnicodeCharacters to $version [skip ci]"
# Retry-with-rebase: if a concurrent release dispatched for a different
# plugin won the push first, pull --rebase and try again.
attempts=0
while ! git push 2>/tmp/push.err; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 5 ]; then
echo "Failed to push after $attempts attempts:" >&2
cat /tmp/push.err >&2
exit 1
fi
echo "Push rejected (attempt $attempts), pulling --rebase and retrying..."
git pull --rebase --no-edit
done
ref=$(git rev-parse HEAD)
IFS=. read -r major minor patch <<< "$version"
tag="se5-remove-unicode-characters-v$major.$minor"
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "ref=$ref" >> "$GITHUB_OUTPUT"
echo "release=$release_flag" >> "$GITHUB_OUTPUT"
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- rid: win-x64
os: windows
exe: RemoveUnicodeCharacters.exe
- rid: win-arm64
os: windows
exe: RemoveUnicodeCharacters.exe
- rid: linux-x64
os: linux
exe: RemoveUnicodeCharacters
- rid: linux-arm64
os: linux
exe: RemoveUnicodeCharacters
- rid: osx-x64
os: macos
exe: RemoveUnicodeCharacters
- rid: osx-arm64
os: macos
exe: RemoveUnicodeCharacters
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.ref }}
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Publish self-contained (${{ matrix.rid }})
working-directory: se5/RemoveUnicodeCharacters
run: |
dotnet publish RemoveUnicodeCharacters.csproj \
-c Release \
-r ${{ matrix.rid }} \
--self-contained true \
-p:DebugType=None \
-p:DebugSymbols=false \
-o staging/RemoveUnicodeCharacters
- name: Rewrite plugin.json for ${{ matrix.os }}
working-directory: se5/RemoveUnicodeCharacters
run: |
jq '
del(.runtime, .entry) |
.executables = { "${{ matrix.os }}": "${{ matrix.exe }}" }
' plugin.json > staging/RemoveUnicodeCharacters/plugin.json
- name: Package zip
working-directory: se5/RemoveUnicodeCharacters/staging
run: zip -r "$GITHUB_WORKSPACE/RemoveUnicodeCharacters-${{ matrix.rid }}.zip" RemoveUnicodeCharacters
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: RemoveUnicodeCharacters-${{ matrix.rid }}
path: RemoveUnicodeCharacters-${{ matrix.rid }}.zip
release:
name: Publish GitHub Release
needs: [prepare, build]
if: needs.prepare.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
- name: Download all zips
uses: actions/download-artifact@v4
with:
path: dist
pattern: RemoveUnicodeCharacters-*
merge-multiple: true
- name: Create release and upload zips
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ needs.prepare.outputs.tag }}" dist/RemoveUnicodeCharacters-*.zip \
--repo "${{ github.repository }}" \
--target "${{ needs.prepare.outputs.ref }}" \
--title "RemoveUnicodeCharacters v${{ needs.prepare.outputs.version }}" \
--notes "Self-contained RemoveUnicodeCharacters plugin builds for win/linux/osx (x64 + arm64)."