ci: make tar robust to 'file changed' during archiving #10
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: | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| runner: ubuntu-latest | |
| - target: aarch64-unknown-linux-gnu | |
| runner: ubuntu-latest | |
| - target: x86_64-apple-darwin | |
| runner: macos-latest | |
| - target: aarch64-apple-darwin | |
| runner: macos-latest | |
| - target: x86_64-pc-windows-msvc | |
| runner: ubuntu-latest | |
| runs-on: ${{ matrix.runner }} | |
| 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) | |
| run: | | |
| rustup target list --installed || true | |
| # Add the target toolchain if missing; for native runners this is harmless. | |
| rustup target add ${{ matrix.target }} || true | |
| - 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 | |
| # Avoid failing if files change during archiving | |
| (cd "$OUTDIR" && tar --warning=no-file-changed -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 }} | |
| publish-crates: | |
| needs: publish-release | |
| runs-on: ubuntu-latest | |
| # only run publish when triggered by a semantic version tag | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| override: true | |
| - name: Publish to crates.io | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: | | |
| set -e | |
| # ensure the token is present | |
| if [ -z "$CARGO_REGISTRY_TOKEN" ]; then | |
| echo "CARGO_REGISTRY_TOKEN is not set. Add it to repository secrets to enable automated publish." >&2 | |
| exit 1 | |
| fi | |
| cargo publish --token "$CARGO_REGISTRY_TOKEN" |