Skip to content

Commit

Permalink
Add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Sep 3, 2024
1 parent fc8c45c commit a76e7c9
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Release

on:
push:
tags:
- '*'

defaults:
run:
shell: bash

jobs:
release:
strategy:
matrix:
target:
- aarch64-apple-darwin
- aarch64-pc-windows-msvc
- aarch64-unknown-linux-musl
- arm-unknown-linux-musleabihf
- armv7-unknown-linux-musleabihf
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
- x86_64-unknown-linux-musl
include:
- target: aarch64-apple-darwin
os: macos-latest
target_rustflags: ''
- target: aarch64-pc-windows-msvc
os: windows-latest
target_rustflags: ''
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
target_rustflags: '--codegen linker=aarch64-linux-gnu-gcc'
- target: arm-unknown-linux-musleabihf
os: ubuntu-latest
target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc'
- target: armv7-unknown-linux-musleabihf
os: ubuntu-latest
target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc'
- target: x86_64-apple-darwin
os: macos-latest
target_rustflags: ''
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
target_rustflags: ''

runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4

- name: Install AArch64 Toolchain
if: ${{ matrix.target == 'aarch64-unknown-linux-musl' }}
run: |
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu libc6-dev-i386
- name: Install ARM Toolchain
if: ${{ matrix.target == 'arm-unknown-linux-musleabihf' || matrix.target == 'armv7-unknown-linux-musleabihf' }}
run: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf
- name: Install AArch64 Toolchain (Windows)
if: ${{ matrix.target == 'aarch64-pc-windows-msvc' }}
run: |
rustup target add aarch64-pc-windows-msvc
- name: Release Type
id: release-type
run: |
if [[ ${{ github.ref }} =~ ^refs/tags/[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
echo ::set-output name=value::release
else
echo ::set-output name=value::prerelease
fi
- name: Package
id: package
env:
TARGET: ${{ matrix.target }}
REF: ${{ github.ref }}
OS: ${{ matrix.os }}
TARGET_RUSTFLAGS: ${{ matrix.target_rustflags }}
run: ./bin/package
shell: bash

- name: Publish Archive
uses: softprops/[email protected]
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
draft: false
files: |
${{ steps.package.outputs.archive }}
${{ steps.package.outputs.archive }}.sha256sum
prerelease: ${{ steps.release-type.outputs.value == 'prerelease' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Changelog
uses: softprops/[email protected]
if: >-
${{
startsWith(github.ref, 'refs/tags/')
&& matrix.target == 'x86_64-unknown-linux-musl'
}}
with:
draft: false
files: CHANGELOG.md
prerelease: ${{ steps.ref-type.outputs.value != 'release' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54 changes: 54 additions & 0 deletions bin/package
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

set -euxo pipefail

VERSION=${REF#"refs/tags/"}
DIST=`pwd`/dist

echo "Packaging filepack $VERSION for $TARGET..."

test -f Cargo.lock || cargo generate-lockfile

echo "Installing rust toolchain for $TARGET..."
rustup target add $TARGET

if [[ $TARGET == aarch64-unknown-linux-musl ]]; then
export CC=aarch64-linux-gnu-gcc
fi

echo "Building filepack..."
RUSTFLAGS="--deny warnings --codegen target-feature=+crt-static $TARGET_RUSTFLAGS" \
cargo build --bin just --target $TARGET --release
EXECUTABLE=target/$TARGET/release/filepack

if [[ $OS == windows-latest ]]; then
EXECUTABLE=$EXECUTABLE.exe
fi

echo "Copying release files..."
mkdir dist
cp -r \
$EXECUTABLE \
Cargo.lock \
Cargo.toml \
LICENSE \
CONTRIBUTING \
README.md \
$DIST

cd $DIST
echo "Creating release archive..."
case $OS in
ubuntu-latest | macos-latest)
ARCHIVE=$DIST/filepack-$VERSION-$TARGET.tar.gz
tar czf $ARCHIVE *
echo "archive=$ARCHIVE" >> $GITHUB_OUTPUT
shasum -a 256 $ARCHIVE > $ARCHIVE.sha256sum
;;
windows-latest)
ARCHIVE=$DIST/filepack-$VERSION-$TARGET.zip
7z a $ARCHIVE *
echo "archive=`pwd -W`/just-$VERSION-$TARGET.zip" >> $GITHUB_OUTPUT
sha256sum $ARCHIVE > $ARCHIVE.sha256sum
;;
esac

0 comments on commit a76e7c9

Please sign in to comment.