Skip to content

Publish Release Artifacts #7

Publish Release Artifacts

Publish Release Artifacts #7

Workflow file for this run

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 }}
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"