Publish Release Artifacts #6
Workflow file for this run
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: Publish Release Artifacts | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' # trigger on semantic version tags like v1.2.3 | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| target: | |
| - x86_64-unknown-linux-gnu | |
| - aarch64-unknown-linux-gnu | |
| - x86_64-apple-darwin | |
| - aarch64-apple-darwin | |
| - x86_64-pc-windows-msvc | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| components: clippy, rustfmt | |
| override: true | |
| - name: Run tests | |
| uses: actions-rs/cargo@v1 | |
| with: | |
| command: test | |
| args: --verbose | |
| - name: Add target for cross builds (if needed) | |
| if: matrix.target != 'x86_64-apple-darwin' && matrix.target != 'aarch64-apple-darwin' | |
| run: rustup target add ${{ matrix.target }} | |
| - name: Build release | |
| env: | |
| CARGO_HOME: ${{ runner.temp }}/cargo | |
| run: | | |
| set -e | |
| rustup target list --installed || true | |
| # Build release for the target | |
| cargo build --release --target "${{ matrix.target }}" | |
| - name: Package binary | |
| run: | | |
| set -e | |
| TAG=${GITHUB_REF##*/} | |
| VERSION=${TAG#v} | |
| OUTDIR=release-artifacts/${{ matrix.target }} | |
| mkdir -p "$OUTDIR" | |
| case "${{ matrix.target }}" in | |
| *windows*) | |
| BIN_PATH=target/${{ matrix.target }}/release/devspace-sweeper.exe | |
| ARCHIVE_NAME=devspace-sweeper-${VERSION}-${{ matrix.target }}.zip | |
| cp "$BIN_PATH" "$OUTDIR/" | |
| cp README.md LICENSE "$OUTDIR/" || true | |
| (cd "$OUTDIR" && zip -r "../${ARCHIVE_NAME}" .) | |
| ;; | |
| *) | |
| BIN_PATH=target/${{ matrix.target }}/release/devspace-sweeper | |
| ARCHIVE_NAME=devspace-sweeper-${VERSION}-${{ matrix.target }}.tar.gz | |
| cp "$BIN_PATH" "$OUTDIR/" | |
| cp README.md LICENSE "$OUTDIR/" || true | |
| (cd "$OUTDIR" && tar -czf "../${ARCHIVE_NAME}" .) | |
| ;; | |
| esac | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-${{ matrix.target }} | |
| path: release-artifacts/${{ matrix.target }}/.. | |
| publish-release: | |
| needs: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create Release (if not exists) and upload assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload release assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: artifacts/*.tar.gz, artifacts/*.zip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |