Skip to content

Sets up automated releases (#3) #12

Sets up automated releases (#3)

Sets up automated releases (#3) #12

Workflow file for this run

# Inspired from https://github.com/SpectralOps/rust-ci-release-template/blob/master/.github/workflows/release.yml
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
env:
BIN_NAME: freezer
PROJECT_NAME: freezer
jobs:
dist:
name: Dist
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [x86_64-linux, aarch64-linux, x86_64-windows, x86_64-macos]
include:
- build: x86_64-linux
os: ubuntu-24.04
rust: stable
target: x86_64-unknown-linux-gnu
cross: false
- build: aarch64-linux
os: ubuntu-24.04
rust: stable
target: aarch64-unknown-linux-gnu
cross: true
- build: x86_64-windows
os: windows-2019
rust: stable
target: x86_64-pc-windows-msvc
cross: false
- build: x86_64-macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
cross: false
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install ${{ matrix.rust }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- name: Build release binary
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.cross }}
command: build
args: --release --target ${{ matrix.target }} --locked
- name: Build archive
shell: bash
run: |
mkdir -p dist
if [ "${{ matrix.os }}" == "windows-2019" ]; then
cp target/${{ matrix.target }}/release/$BIN_NAME.exe dist/
else
cp target/${{ matrix.target }}/release/$BIN_NAME dist/
fi
- uses: actions/[email protected]
with:
name: bins-${{ matrix.build }}
path: dist
publish:
name: Publish
runs-on: ubuntu-latest
needs: dist
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Download artifacts
uses: actions/[email protected]
- run: ls -al bins-*
- name: Calculate tag name
run: |
name=dev
if [[ $GITHUB_REF == refs/tags/v* ]]; then
name=${GITHUB_REF:10}
fi
echo ::set-output name=val::$name
echo TAG=$name >> $GITHUB_ENV
id: tagname
- name: Build archive
shell: bash
run: |
set -ex
rm -rf tmp
mkdir tmp
mkdir dist
for dir in bins-* ; do
platform=${dir#"bins-"}
unset exe
if [[ $platform =~ "windows" ]]; then
exe=".exe"
fi
pkgname=$PROJECT_NAME-$TAG-$platform
mkdir tmp/$pkgname
mv bins-$platform/$BIN_NAME$exe tmp/$pkgname
chmod +x tmp/$pkgname/$BIN_NAME$exe
if [ "$exe" = "" ]; then
tar cJf dist/$pkgname.tar.xz -C tmp $pkgname
else
(cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname)
fi
done
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
gh release create ${{ steps.tagname.outputs.val }} dist/* --title ${{ steps.tagname.outputs.val }} --notes "Release ${{ steps.tagname.outputs.val }}"