Build and release #29
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: Build and release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: "Tag name" | |
| required: true | |
| type: string | |
| targets: | |
| description: 'JSON array of target platforms to build [{"os": "ubuntu-latest", "target": "x86_64-unknown-linux-gnu"}, ...]' | |
| required: true | |
| default: '[{"os": "ubuntu-latest", "target": "x86_64-unknown-linux-gnu"}, {"os": "ubuntu-latest", "target": "aarch64-unknown-linux-gnu"}, {"os": "macos-latest", "target": "x86_64-apple-darwin"}]' | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(inputs.targets) }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get Release Upload URL | |
| id: get_upload_url | |
| run: | | |
| tag_info=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ inputs.tag_name }}") | |
| echo "tag_info: ${tag_info}" | |
| upload_url=$(echo $tag_info | jq -r '.upload_url') | |
| echo "upload_url: ${upload_url}" | |
| if [ -z "$upload_url" ] || [ "$upload_url" == "null" ]; then | |
| echo "Upload URL is null or empty. Exiting workflow." | |
| exit 1 | |
| fi | |
| echo "UPLOAD_URL=${upload_url}" >> $GITHUB_ENV | |
| - name: Set up Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install cross | |
| if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'x86_64-pc-windows-gnu' | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: cross | |
| # Build linux targets by cross, otherwise there may be runtime errors when running on other linux versions: | |
| # ./ape-dts: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.38' not found (required by ./ape-dts) | |
| # ./ape-dts: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found (required by ./ape-dts) | |
| - name: Cross build | |
| if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'x86_64-pc-windows-gnu' | |
| run: | | |
| cargo install cross --git https://github.com/cross-rs/cross | |
| cross build --release --target=${{ matrix.target }} | |
| - name: Local build | |
| if: matrix.target == 'x86_64-apple-darwin' | |
| run: | | |
| rustup target add ${{ matrix.target }} | |
| cargo build --release --features metrics --target=${{ matrix.target }} | |
| - name: Create release artifact | |
| run: | | |
| mkdir -p artifacts | |
| cp target/${{ matrix.target }}/release/dt-main artifacts/ape-dts | |
| cp log4rs.yaml artifacts/log4rs.yaml | |
| tar -czvf ape-dts-${{ github.run_id }}-${{ matrix.target }}.tar.gz -C artifacts . | |
| - name: Upload Release Asset | |
| id: upload_release_asset | |
| uses: actions/upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ env.UPLOAD_URL }} | |
| asset_path: ape-dts-${{ github.run_id }}-${{ matrix.target }}.tar.gz | |
| asset_name: ape-dts-${{ github.run_id }}-${{ matrix.target }}.tar.gz | |
| asset_content_type: application/gzip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload CHANGELOG | |
| if: matrix.target == 'x86_64-unknown-linux-gnu' | |
| uses: actions/upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ env.UPLOAD_URL }} | |
| asset_path: CHANGELOG.md | |
| asset_name: CHANGELOG.md | |
| asset_content_type: text/markdown | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |