|
| 1 | +name: Release-plz PR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: {} |
| 10 | + |
| 11 | +jobs: |
| 12 | + release-plz-pr: |
| 13 | + name: Release-plz PR |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: ${{ github.repository_owner == 'LeagueToolkit' }} |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: write |
| 19 | + concurrency: |
| 20 | + group: release-plz-${{ github.ref }} |
| 21 | + cancel-in-progress: false |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + fetch-tags: true |
| 28 | + persist-credentials: false |
| 29 | + - name: Install Rust toolchain |
| 30 | + uses: dtolnay/rust-toolchain@stable |
| 31 | + - name: Run release-plz |
| 32 | + uses: release-plz/[email protected] |
| 33 | + with: |
| 34 | + command: release-pr |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + release-plz-release: |
| 39 | + name: Release-plz release |
| 40 | + runs-on: ubuntu-latest |
| 41 | + if: ${{ github.repository_owner == 'LeagueToolkit' }} |
| 42 | + needs: release-plz-pr |
| 43 | + permissions: |
| 44 | + contents: write |
| 45 | + concurrency: |
| 46 | + group: release-plz-release-${{ github.ref }} |
| 47 | + cancel-in-progress: false |
| 48 | + outputs: |
| 49 | + releases_created: ${{ steps.release.outputs.releases_created }} |
| 50 | + releases: ${{ steps.release.outputs.releases }} |
| 51 | + steps: |
| 52 | + - name: Checkout repository |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + fetch-tags: true |
| 57 | + persist-credentials: false |
| 58 | + - name: Install Rust toolchain |
| 59 | + uses: dtolnay/rust-toolchain@stable |
| 60 | + - name: Run release-plz release |
| 61 | + id: release |
| 62 | + uses: release-plz/[email protected] |
| 63 | + with: |
| 64 | + command: release |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + build-and-upload: |
| 69 | + name: Build and Upload Binaries |
| 70 | + needs: release-plz-release |
| 71 | + if: needs.release-plz-release.outputs.releases_created == 'true' |
| 72 | + runs-on: ${{ matrix.os }} |
| 73 | + permissions: |
| 74 | + contents: write |
| 75 | + strategy: |
| 76 | + matrix: |
| 77 | + include: |
| 78 | + - os: ubuntu-latest |
| 79 | + target: x86_64-unknown-linux-gnu |
| 80 | + artifact_name: ritobin-tools |
| 81 | + ext: "" |
| 82 | + asset_suffix: linux-x64 |
| 83 | + shell: bash |
| 84 | + - os: macos-latest |
| 85 | + target: x86_64-apple-darwin |
| 86 | + artifact_name: ritobin-tools |
| 87 | + ext: "" |
| 88 | + asset_suffix: macos-x64 |
| 89 | + shell: bash |
| 90 | + - os: windows-latest |
| 91 | + target: x86_64-pc-windows-msvc |
| 92 | + artifact_name: ritobin-tools.exe |
| 93 | + ext: .exe |
| 94 | + asset_suffix: windows-x64 |
| 95 | + shell: powershell |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Checkout repository |
| 99 | + uses: actions/checkout@v4 |
| 100 | + with: |
| 101 | + fetch-depth: 0 |
| 102 | + |
| 103 | + - name: Install Rust toolchain |
| 104 | + uses: dtolnay/rust-toolchain@stable |
| 105 | + with: |
| 106 | + targets: ${{ matrix.target }} |
| 107 | + |
| 108 | + - name: Cache cargo |
| 109 | + uses: Swatinem/rust-cache@v2 |
| 110 | + |
| 111 | + - name: Extract release info (Unix) |
| 112 | + id: release_info |
| 113 | + if: runner.os != 'Windows' |
| 114 | + shell: bash |
| 115 | + run: | |
| 116 | + set -euo pipefail |
| 117 | + RELEASES='${{ needs.release-plz-release.outputs.releases }}' |
| 118 | + VERSION=$(echo "$RELEASES" | jq -r '.[] | select(.package_name=="ritobin-tools") | .version') |
| 119 | + TAG=$(echo "$RELEASES" | jq -r '.[] | select(.package_name=="ritobin-tools") | .tag') |
| 120 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 121 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 122 | +
|
| 123 | + - name: Extract release info (Windows) |
| 124 | + if: runner.os == 'Windows' |
| 125 | + id: release_info_win |
| 126 | + shell: powershell |
| 127 | + run: | |
| 128 | + $releases = '${{ needs.release-plz-release.outputs.releases }}' | ConvertFrom-Json |
| 129 | + $rel = $releases | Where-Object { $_.package_name -eq 'ritobin-tools' } |
| 130 | + if (-not $rel) { Write-Error 'No ritobin-tools release found' } |
| 131 | + echo "version=$($rel.version)" >> $env:GITHUB_OUTPUT |
| 132 | + echo "tag=$($rel.tag)" >> $env:GITHUB_OUTPUT |
| 133 | +
|
| 134 | + - name: Build release binary |
| 135 | + run: cargo build --release --target ${{ matrix.target }} -p ritobin-tools --bin ritobin-tools |
| 136 | + |
| 137 | + - name: Prepare and archive (Unix) |
| 138 | + if: runner.os != 'Windows' |
| 139 | + shell: bash |
| 140 | + run: | |
| 141 | + set -euo pipefail |
| 142 | + VERSION='${{ steps.release_info.outputs.version }}' |
| 143 | + BIN_PATH="target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" |
| 144 | + mkdir -p release |
| 145 | + cp "$BIN_PATH" "release/ritobin-tools${{ matrix.ext }}" |
| 146 | + cp README.md LICENSE release/ |
| 147 | + ARCHIVE="ritobin-tools-${VERSION}-${{ matrix.asset_suffix }}.zip" |
| 148 | + (cd release && zip -r "../$ARCHIVE" .) |
| 149 | + if [ "$(uname)" = "Darwin" ]; then |
| 150 | + shasum -a 256 "$ARCHIVE" | awk '{print $1}' > "$ARCHIVE.sha256" |
| 151 | + else |
| 152 | + sha256sum "$ARCHIVE" | awk '{print $1}' > "$ARCHIVE.sha256" |
| 153 | + fi |
| 154 | +
|
| 155 | + - name: Prepare and archive (Windows) |
| 156 | + if: runner.os == 'Windows' |
| 157 | + shell: powershell |
| 158 | + run: | |
| 159 | + $version = '${{ steps.release_info_win.outputs.version }}' |
| 160 | + New-Item -ItemType Directory -Force -Path release | Out-Null |
| 161 | + Copy-Item "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" "release/ritobin-tools${{ matrix.ext }}" |
| 162 | + Copy-Item README.md release/ |
| 163 | + Copy-Item LICENSE release/ |
| 164 | + $archive = "ritobin-tools-$version-${{ matrix.asset_suffix }}.zip" |
| 165 | + Compress-Archive -Path release/* -DestinationPath $archive -Force |
| 166 | + $hash = Get-FileHash $archive -Algorithm SHA256 |
| 167 | + $hash.Hash | Out-File "$archive.sha256" -Encoding ASCII |
| 168 | +
|
| 169 | + - name: Upload assets to existing release |
| 170 | + uses: softprops/action-gh-release@v2 |
| 171 | + with: |
| 172 | + tag_name: ${{ steps.release_info.outputs.tag || steps.release_info_win.outputs.tag }} |
| 173 | + files: | |
| 174 | + ritobin-tools-${{ steps.release_info.outputs.version || steps.release_info_win.outputs.version }}-${{ matrix.asset_suffix }}.zip |
| 175 | + ritobin-tools-${{ steps.release_info.outputs.version || steps.release_info_win.outputs.version }}-${{ matrix.asset_suffix }}.zip.sha256 |
| 176 | + env: |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments