|
| 1 | +name: Build RemoveUnicodeCharacters (SE5) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'se5/RemoveUnicodeCharacters/**' |
| 8 | + - 'se5/Plugin-Shared/**' |
| 9 | + - '.github/workflows/remove-unicode-characters.yml' |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - 'se5/RemoveUnicodeCharacters/**' |
| 13 | + - 'se5/Plugin-Shared/**' |
| 14 | + - '.github/workflows/remove-unicode-characters.yml' |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + release: |
| 18 | + description: 'Publish a GitHub release. Bumps the minor in plugin.json and commits it back.' |
| 19 | + type: boolean |
| 20 | + default: false |
| 21 | + version: |
| 22 | + description: 'Optional explicit version (e.g. 1.2.0). Overrides the auto-minor-bump.' |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: write |
| 28 | + |
| 29 | +jobs: |
| 30 | + prepare: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + outputs: |
| 33 | + version: ${{ steps.set.outputs.version }} |
| 34 | + tag: ${{ steps.set.outputs.tag }} |
| 35 | + ref: ${{ steps.set.outputs.ref }} |
| 36 | + release: ${{ steps.set.outputs.release }} |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Resolve version (and bump on release) |
| 42 | + id: set |
| 43 | + run: | |
| 44 | + set -e |
| 45 | + current=$(jq -r .version se5/RemoveUnicodeCharacters/plugin.json) |
| 46 | + release_flag="false" |
| 47 | + ref="${{ github.sha }}" |
| 48 | + version="$current" |
| 49 | + tag="" |
| 50 | +
|
| 51 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.release }}" = "true" ]; then |
| 52 | + release_flag="true" |
| 53 | + if [ -n "${{ inputs.version }}" ]; then |
| 54 | + version="${{ inputs.version }}" |
| 55 | + else |
| 56 | + IFS=. read -r major minor patch <<< "$current" |
| 57 | + version="$major.$((minor + 1)).0" |
| 58 | + fi |
| 59 | +
|
| 60 | + tmp=$(mktemp) |
| 61 | + jq --arg v "$version" '.version = $v' se5/RemoveUnicodeCharacters/plugin.json > "$tmp" |
| 62 | + mv "$tmp" se5/RemoveUnicodeCharacters/plugin.json |
| 63 | +
|
| 64 | + git config user.name "github-actions[bot]" |
| 65 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 66 | + git add se5/RemoveUnicodeCharacters/plugin.json |
| 67 | + git commit -m "Bump RemoveUnicodeCharacters to $version [skip ci]" |
| 68 | +
|
| 69 | + # Retry-with-rebase: if a concurrent release dispatched for a different |
| 70 | + # plugin won the push first, pull --rebase and try again. |
| 71 | + attempts=0 |
| 72 | + while ! git push 2>/tmp/push.err; do |
| 73 | + attempts=$((attempts + 1)) |
| 74 | + if [ "$attempts" -ge 5 ]; then |
| 75 | + echo "Failed to push after $attempts attempts:" >&2 |
| 76 | + cat /tmp/push.err >&2 |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + echo "Push rejected (attempt $attempts), pulling --rebase and retrying..." |
| 80 | + git pull --rebase --no-edit |
| 81 | + done |
| 82 | + ref=$(git rev-parse HEAD) |
| 83 | +
|
| 84 | + IFS=. read -r major minor patch <<< "$version" |
| 85 | + tag="se5-remove-unicode-characters-v$major.$minor" |
| 86 | + fi |
| 87 | +
|
| 88 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 89 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 90 | + echo "ref=$ref" >> "$GITHUB_OUTPUT" |
| 91 | + echo "release=$release_flag" >> "$GITHUB_OUTPUT" |
| 92 | +
|
| 93 | + build: |
| 94 | + needs: prepare |
| 95 | + runs-on: ubuntu-latest |
| 96 | + strategy: |
| 97 | + fail-fast: false |
| 98 | + matrix: |
| 99 | + include: |
| 100 | + - rid: win-x64 |
| 101 | + os: windows |
| 102 | + exe: RemoveUnicodeCharacters.exe |
| 103 | + - rid: win-arm64 |
| 104 | + os: windows |
| 105 | + exe: RemoveUnicodeCharacters.exe |
| 106 | + - rid: linux-x64 |
| 107 | + os: linux |
| 108 | + exe: RemoveUnicodeCharacters |
| 109 | + - rid: linux-arm64 |
| 110 | + os: linux |
| 111 | + exe: RemoveUnicodeCharacters |
| 112 | + - rid: osx-x64 |
| 113 | + os: macos |
| 114 | + exe: RemoveUnicodeCharacters |
| 115 | + - rid: osx-arm64 |
| 116 | + os: macos |
| 117 | + exe: RemoveUnicodeCharacters |
| 118 | + |
| 119 | + steps: |
| 120 | + - name: Checkout |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + ref: ${{ needs.prepare.outputs.ref }} |
| 124 | + |
| 125 | + - name: Setup .NET 8 |
| 126 | + uses: actions/setup-dotnet@v4 |
| 127 | + with: |
| 128 | + dotnet-version: '8.0.x' |
| 129 | + |
| 130 | + - name: Publish self-contained (${{ matrix.rid }}) |
| 131 | + working-directory: se5/RemoveUnicodeCharacters |
| 132 | + run: | |
| 133 | + dotnet publish RemoveUnicodeCharacters.csproj \ |
| 134 | + -c Release \ |
| 135 | + -r ${{ matrix.rid }} \ |
| 136 | + --self-contained true \ |
| 137 | + -p:DebugType=None \ |
| 138 | + -p:DebugSymbols=false \ |
| 139 | + -o staging/RemoveUnicodeCharacters |
| 140 | +
|
| 141 | + - name: Rewrite plugin.json for ${{ matrix.os }} |
| 142 | + working-directory: se5/RemoveUnicodeCharacters |
| 143 | + run: | |
| 144 | + jq ' |
| 145 | + del(.runtime, .entry) | |
| 146 | + .executables = { "${{ matrix.os }}": "${{ matrix.exe }}" } |
| 147 | + ' plugin.json > staging/RemoveUnicodeCharacters/plugin.json |
| 148 | +
|
| 149 | + - name: Package zip |
| 150 | + working-directory: se5/RemoveUnicodeCharacters/staging |
| 151 | + run: zip -r "$GITHUB_WORKSPACE/RemoveUnicodeCharacters-${{ matrix.rid }}.zip" RemoveUnicodeCharacters |
| 152 | + |
| 153 | + - name: Upload artifact |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: RemoveUnicodeCharacters-${{ matrix.rid }} |
| 157 | + path: RemoveUnicodeCharacters-${{ matrix.rid }}.zip |
| 158 | + |
| 159 | + release: |
| 160 | + name: Publish GitHub Release |
| 161 | + needs: [prepare, build] |
| 162 | + if: needs.prepare.outputs.release == 'true' |
| 163 | + runs-on: ubuntu-latest |
| 164 | + steps: |
| 165 | + - name: Download all zips |
| 166 | + uses: actions/download-artifact@v4 |
| 167 | + with: |
| 168 | + path: dist |
| 169 | + pattern: RemoveUnicodeCharacters-* |
| 170 | + merge-multiple: true |
| 171 | + |
| 172 | + - name: Create release and upload zips |
| 173 | + env: |
| 174 | + GH_TOKEN: ${{ github.token }} |
| 175 | + run: | |
| 176 | + gh release create "${{ needs.prepare.outputs.tag }}" dist/RemoveUnicodeCharacters-*.zip \ |
| 177 | + --repo "${{ github.repository }}" \ |
| 178 | + --target "${{ needs.prepare.outputs.ref }}" \ |
| 179 | + --title "RemoveUnicodeCharacters v${{ needs.prepare.outputs.version }}" \ |
| 180 | + --notes "Self-contained RemoveUnicodeCharacters plugin builds for win/linux/osx (x64 + arm64)." |
0 commit comments