name: release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "dev[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: write
jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Get the release version from the tag
if: env.VERSION == ''
run: |
echo "VERSION=${{ github.ref_name }}" >>$GITHUB_ENV
echo "VERSION_NUMBER=$(echo ${{ github.ref_name }} | sed -e 's/^v//' -e 's/^dev//')" >>$GITHUB_ENV
- name: Show the version
run: |
echo "VERSION = $VERSION"
echo "VERSION_NUMBER = $VERSION_NUMBER"
- name: Check that tag version and Cargo.toml version are the same
shell: bash
run: |
case "$VERSION" in
dev*)
echo "[dev] Cargo.toml version check skipped" >&2
exit 0
;;
esac
if ! grep -q "package.version = \"$VERSION_NUMBER\"" Cargo.toml
then
echo "version does not match Cargo.toml" >&2
exit 1
fi
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create "$VERSION" --draft --verify-tag --title "$VERSION"
outputs:
version: ${{ env.VERSION }}
version_number: ${{ env.VERSION_NUMBER }}
build-release:
name: build-release
needs: ['create-release']
runs-on: ${{ matrix.os }}
env:
CARGO: cargo
TARGET_FLAGS:
TARGET_DIR: ./target
CROSS_VERSION: v0.2.5
RUST_BACKTRACE: 1
strategy:
fail-fast: false
matrix:
include:
- build: linux
os: ubuntu-latest
rust: nightly
target: x86_64-unknown-linux-musl
strip: x86_64-linux-musl-strip
- build: linux-gui
os: ubuntu-latest
rust: nightly
target: x86_64-unknown-linux-gnu
strip: x86_64-linux-gnu-strip
- build: stable-x86
os: ubuntu-latest
rust: stable
target: i686-unknown-linux-gnu
strip: x86_64-linux-gnu-strip
qemu: i386
- build: stable-aarch64
os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-gnu
strip: aarch64-linux-gnu-strip
qemu: qemu-aarch64
- build: stable-arm-gnueabihf
os: ubuntu-latest
rust: stable
target: armv7-unknown-linux-gnueabihf
strip: arm-linux-gnueabihf-strip
qemu: qemu-arm
- build: stable-arm-musleabihf
os: ubuntu-latest
rust: stable
target: armv7-unknown-linux-musleabihf
strip: arm-linux-musleabihf-strip
qemu: qemu-arm
- build: stable-arm-musleabi
os: ubuntu-latest
rust: stable
target: armv7-unknown-linux-musleabi
strip: arm-linux-musleabi-strip
qemu: qemu-arm
- build: stable-powerpc64
os: ubuntu-latest
rust: stable
target: powerpc64-unknown-linux-gnu
strip: powerpc64-linux-gnu-strip
qemu: qemu-ppc64
- build: stable-s390x
os: ubuntu-latest
rust: stable
target: s390x-unknown-linux-gnu
strip: s390x-linux-gnu-strip
qemu: qemu-s390x
- build: macos-x86_64
os: macos-latest
rust: nightly
target: x86_64-apple-darwin
- build: macos-arm64
os: macos-latest
rust: nightly
target: aarch64-apple-darwin
- build: win-msvc
os: windows-latest
rust: nightly
target: x86_64-pc-windows-msvc
- build: win-gnu
os: windows-latest
rust: nightly-x86_64-gnu
target: x86_64-pc-windows-gnu
- build: win32-msvc
os: windows-latest
rust: nightly
target: i686-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install packages
if: matrix.os == 'ubuntu-latest'
shell: bash
run: sudo apt install coreutils git musl-tools rsync zsh
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Use Cross
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
shell: bash
run: |
# In the past, new releases of 'cross' have broken CI. So for now, we
# pin it. We also use their pre-compiled binary releases because cross
# has over 100 dependencies and takes a bit to compile.
dir="$RUNNER_TEMP/cross-download"
mkdir "$dir"
echo "$dir" >> $GITHUB_PATH
cd "$dir"
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
tar xf cross-x86_64-unknown-linux-musl.tar.gz
echo "CARGO=cross" >> $GITHUB_ENV
- name: Set target variables
shell: bash
run: |
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
shell: bash
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
shell: bash
run: |
${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
if test "${{ matrix.os }}" = "windows-latest"
then
bin="target/${{ matrix.target }}/release/garden.exe"
else
bin="target/${{ matrix.target }}/release/garden"
fi
echo "BIN_CORE=$bin" >>$GITHUB_ENV
- name: Build release GUI binary
shell: bash
if: matrix.build == 'linux-gui'
run: |
${{ env.CARGO }} build --verbose --release --package garden-gui ${{ env.TARGET_FLAGS }}
echo "BIN_GUI=target/${{ matrix.target }}/release/garden-gui" >>$GITHUB_ENV
- name: Strip release binary (macos)
if: matrix.os == 'macos-latest'
shell: bash
run: strip "$BIN_CORE"
- name: Strip release binary (cross)
if: env.CARGO == 'cross'
shell: bash
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.strip }}" \
"/$BIN_CORE"
- name: Strip release binary (gui)
if: matrix.build == 'linux-gui'
shell: bash
run: |
strip "$BIN_GUI"
- name: Determine archive name
shell: bash
run: |
version_number="${{ needs.create-release.outputs.version_number }}"
echo "ARCHIVE_CORE=garden-${version_number}-${{ matrix.target }}" >>$GITHUB_ENV
- name: Determine GUI archive name
if: matrix.build == 'linux-gui'
shell: bash
run: |
version_number="${{ needs.create-release.outputs.version_number }}"
echo "ARCHIVE_GUI=garden-gui-${version_number}-${{ matrix.target }}" >>$GITHUB_ENV
- name: Creating directory for archive
shell: bash
run: |
mkdir -p "$ARCHIVE_CORE"/{completion,doc}
cp "$BIN_CORE" "$ARCHIVE_CORE"/
cp doc/src/changelog.md "$ARCHIVE_CORE"/doc/CHANGELOG.md
cp README.md LICENSE "$ARCHIVE_CORE"/doc
- name: Creating directory for GUI archive
if: matrix.build == 'linux-gui'
shell: bash
run: |
mkdir -p "$ARCHIVE_GUI"
cp "$BIN_GUI" "$ARCHIVE_GUI"/
- name: Generate completions (no emulation)
if: matrix.qemu == '' && matrix.build != 'win-msvc' && matrix.build != 'win-gnu'
shell: bash
run: |
"$BIN_CORE" --version
"$BIN_CORE" --define pkgdir="$ARCHIVE_CORE" pkg/completion -vv
"$BIN_CORE" completion powershell >"$ARCHIVE_CORE/completion/_garden.ps1"
- name: Generate completions (emulation)
if: matrix.qemu != '' && matrix.build != 'win-msvc' && matrix.build != 'win-gnu'
shell: bash
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN_CORE" --version
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN_CORE" \
completion bash >"$ARCHIVE_CORE/completion/garden.bash"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN_CORE" \
completion fish >"$ARCHIVE_CORE/completion/garden.fish"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN_CORE" \
completion powershell >"$ARCHIVE_CORE/completion/_garden.ps1"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN_CORE" \
completion zsh >"$ARCHIVE_CORE/completion/_garden"
- name: Build archive (Windows)
shell: bash
if: matrix.os == 'windows-latest'
run: |
7z a "$ARCHIVE_CORE.zip" "$ARCHIVE_CORE"
certutil -hashfile "$ARCHIVE_CORE.zip" SHA256 > "$ARCHIVE_CORE.zip.sha256"
echo "ASSET_CORE=$ARCHIVE_CORE.zip" >>$GITHUB_ENV
echo "ASSET_CORE_SUM=$ARCHIVE_CORE.zip.sha256" >>$GITHUB_ENV
- name: Build archive (Unix)
shell: bash
if: matrix.os != 'windows-latest'
run: |
tar czf "$ARCHIVE_CORE.tar.gz" "$ARCHIVE_CORE"
if ! type sha256sum >/dev/null
then
sha256sum () {
shasum -a 256 "$@"
}
fi
sha256sum "$ARCHIVE_CORE.tar.gz" >"$ARCHIVE_CORE.tar.gz.sha256"
echo "ASSET_CORE=$ARCHIVE_CORE.tar.gz" >>$GITHUB_ENV
echo "ASSET_CORE_SUM=$ARCHIVE_CORE.tar.gz.sha256" >>$GITHUB_ENV
- name: Build archive (gui)
shell: bash
if: matrix.build == 'linux-gui'
run: |
tar czf "$ARCHIVE_GUI.tar.gz" "$ARCHIVE_GUI"
sha256sum "$ARCHIVE_GUI.tar.gz" >"$ARCHIVE_GUI.tar.gz.sha256"
echo "ASSET_GUI=$ARCHIVE_GUI.tar.gz" >>$GITHUB_ENV
echo "ASSET_GUI_SUM=$ARCHIVE_GUI.tar.gz.sha256" >>$GITHUB_ENV
- name: Upload release archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
version="${{ needs.create-release.outputs.version }}"
gh release upload "$version" ${{ env.ASSET_CORE }} ${{ env.ASSET_CORE_SUM }}
- name: Upload GUI release archive
if: matrix.build == 'linux-gui'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
version="${{ needs.create-release.outputs.version }}"
gh release upload "$version" ${{ env.ASSET_GUI }} ${{ env.ASSET_GUI_SUM }}
build-release-deb:
name: build-release-deb
needs: ['create-release']
runs-on: ubuntu-latest
env:
TARGET_MUSL: x86_64-unknown-linux-musl
TARGET_GNU: x86_64-unknown-linux-gnu
RUST_BACKTRACE: 1
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install packages
shell: bash
run: sudo apt install coreutils git musl-tools rsync zsh
- name: Install Rust
run: |
rustup toolchain install nightly --profile minimal --no-self-update
rustup target add ${{ env.TARGET_MUSL }}
rustup target add ${{ env.TARGET_GNU }}
- name: Install mdbook
shell: bash
run: |
version=v0.5.2
curl -sSL https://github.com/rust-lang/mdBook/releases/download/${version}/mdbook-${version}-x86_64-unknown-linux-gnu.tar.gz |
tar -xz --directory=${HOME}/.cargo/bin
- name: Install cargo-deb
shell: bash
run: cargo install cargo-deb
- name: Build debug binary to create release assets
shell: bash
run: |
cargo build --target ${{ env.TARGET_MUSL }}
echo "BIN_CORE=target/${{ env.TARGET_MUSL }}/debug/garden" >>$GITHUB_ENV
- name: Build Debian release binary
shell: bash
run: |
"$BIN_CORE" pkg/deb -vv
- name: Upload release archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
version="${{ needs.create-release.outputs.version }}"
version_number="${{ needs.create-release.outputs.version_number }}"
DEB_CORE_NAME=garden_${version_number}-1_amd64.deb
DEB_GUI_NAME=garden-gui_${version_number}-1_amd64.deb
cd target/debian
gh release upload "${version}" "$DEB_CORE_NAME" "$DEB_CORE_NAME.sha256"
gh release upload "${version}" "$DEB_GUI_NAME" "$DEB_GUI_NAME.sha256"