|
| 1 | +name: Installer Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + tags: |
| 9 | + - installer-v* |
| 10 | + paths: |
| 11 | + - installer/Cargo.toml |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + prepare: |
| 19 | + name: Prepare Installer Release |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + should_release: ${{ steps.release_check.outputs.should_release }} |
| 23 | + version: ${{ steps.version.outputs.version }} |
| 24 | + tag: ${{ steps.version.outputs.tag }} |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 2 |
| 30 | + |
| 31 | + - name: Read version from installer/Cargo.toml |
| 32 | + id: version |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + version="$(sed -nE 's/^version = "(.*)"/\1/p' installer/Cargo.toml | head -n1)" |
| 36 | + if [[ -z "${version}" ]]; then |
| 37 | + echo "Failed to read version from installer/Cargo.toml" >&2 |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + echo "version=${version}" >> "${GITHUB_OUTPUT}" |
| 42 | + echo "tag=installer-v${version}" >> "${GITHUB_OUTPUT}" |
| 43 | +
|
| 44 | + - name: Check whether this push changed the installer package version |
| 45 | + id: release_check |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 49 | + echo "should_release=true" >> "${GITHUB_OUTPUT}" |
| 50 | + exit 0 |
| 51 | + fi |
| 52 | +
|
| 53 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 54 | + expected_tag="installer-v${{ steps.version.outputs.version }}" |
| 55 | + if [[ "${{ github.ref_name }}" != "${expected_tag}" ]]; then |
| 56 | + echo "Tag ${{ github.ref_name }} does not match installer/Cargo.toml version ${expected_tag}" >&2 |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + echo "should_release=true" >> "${GITHUB_OUTPUT}" |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | +
|
| 63 | + if ! git cat-file -e HEAD^ 2>/dev/null; then |
| 64 | + echo "No parent commit available; skipping automatic installer release." |
| 65 | + echo "should_release=false" >> "${GITHUB_OUTPUT}" |
| 66 | + exit 0 |
| 67 | + fi |
| 68 | +
|
| 69 | + current_version="$(sed -nE 's/^version = "(.*)"/\1/p' installer/Cargo.toml | head -n1)" |
| 70 | + previous_version="$(git show HEAD^:installer/Cargo.toml | sed -nE 's/^version = "(.*)"/\1/p' | head -n1)" |
| 71 | +
|
| 72 | + echo "Previous installer version: ${previous_version}" |
| 73 | + echo "Current installer version: ${current_version}" |
| 74 | +
|
| 75 | + if [[ -n "${previous_version}" && "${current_version}" != "${previous_version}" ]]; then |
| 76 | + echo "should_release=true" >> "${GITHUB_OUTPUT}" |
| 77 | + else |
| 78 | + echo "should_release=false" >> "${GITHUB_OUTPUT}" |
| 79 | + fi |
| 80 | +
|
| 81 | + build: |
| 82 | + name: Build Installer ${{ matrix.label }} |
| 83 | + needs: prepare |
| 84 | + if: needs.prepare.outputs.should_release == 'true' |
| 85 | + runs-on: ${{ matrix.runner }} |
| 86 | + defaults: |
| 87 | + run: |
| 88 | + working-directory: installer |
| 89 | + strategy: |
| 90 | + fail-fast: false |
| 91 | + matrix: |
| 92 | + include: |
| 93 | + - label: linux-x64 |
| 94 | + runner: ubuntu-latest |
| 95 | + binary_name: audiobookshelf-discord-rpc-installer |
| 96 | + asset_name: audiobookshelf-discord-rpc-installer |
| 97 | + - label: macos-arm64 |
| 98 | + runner: macos-latest |
| 99 | + binary_name: audiobookshelf-discord-rpc-installer |
| 100 | + asset_name: audiobookshelf-discord-rpc-installer-macos-arm64 |
| 101 | + - label: windows-x64 |
| 102 | + runner: windows-latest |
| 103 | + binary_name: audiobookshelf-discord-rpc-installer.exe |
| 104 | + asset_name: audiobookshelf-discord-rpc-installer.exe |
| 105 | + steps: |
| 106 | + - name: Checkout |
| 107 | + uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Install Rust |
| 110 | + uses: dtolnay/rust-toolchain@stable |
| 111 | + |
| 112 | + - name: Cache cargo |
| 113 | + uses: Swatinem/rust-cache@v2 |
| 114 | + with: |
| 115 | + workspaces: installer |
| 116 | + |
| 117 | + - name: Build release binary |
| 118 | + shell: bash |
| 119 | + run: cargo build --release --locked |
| 120 | + |
| 121 | + - name: Stage release artifact |
| 122 | + shell: bash |
| 123 | + run: | |
| 124 | + mkdir -p release-assets |
| 125 | + cp "target/release/${{ matrix.binary_name }}" "release-assets/${{ matrix.asset_name }}" |
| 126 | +
|
| 127 | + - name: Upload artifact |
| 128 | + uses: actions/upload-artifact@v4 |
| 129 | + with: |
| 130 | + name: installer-${{ matrix.label }} |
| 131 | + path: installer/release-assets/${{ matrix.asset_name }} |
| 132 | + if-no-files-found: error |
| 133 | + |
| 134 | + release: |
| 135 | + name: Create Installer GitHub Release |
| 136 | + needs: |
| 137 | + - prepare |
| 138 | + - build |
| 139 | + if: needs.prepare.outputs.should_release == 'true' |
| 140 | + runs-on: ubuntu-latest |
| 141 | + steps: |
| 142 | + - name: Download build artifacts |
| 143 | + uses: actions/download-artifact@v4 |
| 144 | + with: |
| 145 | + path: dist |
| 146 | + |
| 147 | + - name: Show staged files |
| 148 | + shell: bash |
| 149 | + run: find dist -maxdepth 2 -type f | sort |
| 150 | + |
| 151 | + - name: Create or update installer release |
| 152 | + uses: softprops/action-gh-release@v2 |
| 153 | + with: |
| 154 | + tag_name: ${{ needs.prepare.outputs.tag }} |
| 155 | + name: ${{ needs.prepare.outputs.tag }} |
| 156 | + generate_release_notes: true |
| 157 | + make_latest: false |
| 158 | + fail_on_unmatched_files: true |
| 159 | + files: | |
| 160 | + dist/installer-linux-x64/audiobookshelf-discord-rpc-installer |
| 161 | + dist/installer-macos-arm64/audiobookshelf-discord-rpc-installer-macos-arm64 |
| 162 | + dist/installer-windows-x64/audiobookshelf-discord-rpc-installer.exe |
0 commit comments