Release Build (Linux & macOS) #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Build (Linux & macOS) | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build-and-upload: | |
| name: Build ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-musl | |
| os: ubuntu-latest | |
| use_cross: true | |
| - target: aarch64-unknown-linux-musl | |
| os: ubuntu-latest | |
| use_cross: true | |
| - target: armv7-unknown-linux-musleabihf | |
| os: ubuntu-latest | |
| use_cross: true | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| use_cross: false | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| use_cross: false | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust Toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Get Version | |
| id: get_version | |
| shell: bash | |
| run: | | |
| VERSION=$(grep "^version" Cargo.toml | head -1 | awk -F '"' '{print $2}') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build Binary | |
| shell: bash | |
| run: | | |
| if [ "${{ matrix.use_cross }}" == "true" ]; then | |
| curl -L --proto '=https' --tlsv1.2 -sSf https://github.com/cross-rs/cross/releases/download/v0.2.5/cross-x86_64-unknown-linux-gnu.tar.gz | tar xz | |
| sudo mv cross /usr/local/bin/ | |
| cross build --release --features update --target ${{ matrix.target }} | |
| else | |
| cargo build --release --features update --target ${{ matrix.target }} | |
| fi | |
| - name: Package Artifacts | |
| shell: bash | |
| run: | | |
| VERSION=${{ steps.get_version.outputs.version }} | |
| TARGET=${{ matrix.target }} | |
| BINARY_NAME="mpv-music" | |
| BIN_PATH="target/$TARGET/release/$BINARY_NAME" | |
| ARCHIVE_NAME="$BINARY_NAME-v$VERSION-$TARGET.tar.gz" | |
| mkdir -p dist | |
| cp $BIN_PATH dist/ | |
| cd dist && tar -czvf ../$ARCHIVE_NAME $BINARY_NAME && cd .. | |
| echo "ASSET=$ARCHIVE_NAME" >> $GITHUB_ENV | |
| - name: Upload Release Assets | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| TAG_NAME="${GITHUB_REF#refs/tags/}" | |
| else | |
| TAG_NAME=$(gh release list --limit 1 --json tagName --jq '.[0].tagName') | |
| fi | |
| gh release upload "$TAG_NAME" ${{ env.ASSET }} --clobber |