Skip to content

Commit

Permalink
github actions for building releases
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Mar 22, 2024
1 parent 8152918 commit 3495597
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .ci/pack-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

fail() {
printf "%s\n" "$1" >&2
exit 1
}

not_empty() {
test -z "$1" && fail "expected $2"
}


not_empty "$GITHUB_REF" GITHUB_REF
not_empty "$OS_NAME" OS_NAME


if [ "$OS_NAME" = "ubuntu" ]; then
OS_NAME=linux
exe=""
elif [ "$OS_NAME" == "linux-aarch64" ]; then
OS_NAME=linux_aarch64
exe=""
elif [ "$OS_NAME" == "macos" ]; then
OS_NAME=osx
elif [ "$OS_NAME" == "windows" ]; then
exe=".exe"
else
fail "unknown os name: $OS_NAME"
fi

TAG_NAME="${GITHUB_REF##*/}"

generate_asset() {
local asset_type=$1
local bins="$2"
local non_exe="$3"
local TARGET_DIR=releases/${asset_type}-${OS_NAME}-${TAG_NAME}
mkdir -p "$TARGET_DIR"
for component in $bins; do
strip -x target/release/${component}${exe}
done
for bin in $bins; do
cp "target/release/${bin}${exe}" "$TARGET_DIR/"
done
if test -n "$non_exe"; then
for bin in $non_exe; do
cp "target/release/${bin}" "$TARGET_DIR/"
done
fi
if [ "$OS_NAME" = "windows" ]; then
echo "::set-output name=${asset_type}Artifact::${asset_type}-${OS_NAME}-${TAG_NAME}.zip"
echo "::set-output name=${asset_type}Media::application/zip"
(cd "$TARGET_DIR" && 7z a "../${asset_type}-${OS_NAME}-${TAG_NAME}.zip" * )
else
echo "::set-output name=${asset_type}Artifact::${asset_type}-${OS_NAME}-${TAG_NAME}.tar.gz"
echo "::set-output name=${asset_type}Media::application/tar+gzip"
(cd releases && tar czf "${asset_type}-${OS_NAME}-${TAG_NAME}.tar.gz" "${asset_type}-${OS_NAME}-${TAG_NAME}")
du -h "releases/${asset_type}-${OS_NAME}-${TAG_NAME}.tar.gz"
fi
}

generate_asset "golem-certificate-cli" "golem-certificate-cli"
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build Release

on:
push:
tags:
- v*
- pre-rel-*
env:
CARGO_TERM_COLOR: always
rust_stable: 1.76.0

jobs:
release:
name: CI
runs-on: ${{ matrix.os }}-latest
if: startsWith(github.ref, 'refs/tags/')
strategy:
fail-fast: true
matrix:
os:
- ubuntu
- windows
- macos

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
components: clippy, rustfmt

- uses: Swatinem/rust-cache@v2
- run: cargo tree --locked

- name: Install smartcard libraries ( Linux only )
if: runner.os == 'Linux'
run: |
sudo apt install -y libpcsclite-dev
- name: Build
if: runner.os != 'Linux'
run: cargo build --workspace --release

- name: Build cli with smartcard ( Linux only )
if: runner.os == 'Linux'
uses: actions-rs/cargo@v1
with:
command: build
args: -p golem-certificate-cli --features smartcard

- name: Pack
id: pack
shell: bash
env:
OS_NAME: ${{ matrix.os }}
GITHUB_REF: ${{ github.ref }}
run: |
bash .ci/pack-build.sh
- name: Release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
releases/golem-certificate-cli-*
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-rel-v') }}
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

env:
rust_stable: 1.68.2
rust_stable: 1.76.0

jobs:
build:
Expand Down

0 comments on commit 3495597

Please sign in to comment.