Skip to content

Commit

Permalink
Build package for multiple OS on every release.
Browse files Browse the repository at this point in the history
  • Loading branch information
ayosec committed Aug 26, 2021
1 parent e4503e2 commit f84c793
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 42 deletions.
73 changes: 35 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,51 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}

build:
name: Binary for ${{ matrix.os }}
name: Package for ${{ matrix.os }}
needs: release_draft
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ ubuntu-18.04 ]
include:
- os: ubuntu-18.04
package: timehistory-bash-linux-ARCH.tar.gz
os:
- tarball
- debian:bullseye
- ubuntu:21.10
- fedora
- opensuse/tumbleweed
steps:
- uses: actions/checkout@v2

- name: Rust ${{ matrix.rust }}.
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Build shared object.
uses: actions-rs/cargo@v1
with:
command: build
args: --release

- name: Test the shared object.
run: |
set -xe
strip --strip-debug ./target/release/libtimehistory_bash.so
enable -f ./target/release/libtimehistory_bash.so timehistory
uname -a
timehistory
- name: Package.
id: package
run: |
set -xe
tar -czf ${{ matrix.package }} -C target/release libtimehistory_bash.so
IMAGE="${{ matrix.os }}"
if [ "$IMAGE" = tarball ]
then
IMAGE=debian:stable
MAKE_TARBALL=1
fi
- id: asset_name_generator
name: Set asset name
shell: bash
run: |
echo "::set-output name=name::${{ matrix.package }}" | sed "s/ARCH/$(uname -m)/g"
docker run --rm \
-v "$PWD:/source" \
-e MAKE_TARBALL="${MAKE_TARBALL:-0}" \
-w /source \
"$IMAGE" \
pkg/build-release.sh
- uses: actions/upload-release-asset@v1
with:
upload_url: ${{ needs.release_draft.outputs.upload_url }}
asset_path: ${{ matrix.package }}
asset_name: ${{ steps.asset_name_generator.outputs.name }}
asset_content_type: application/octet-stream
- name: Upload asset.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ needs.release_draft.outputs.upload_url }}
run: |
set -ex
for ASSET in ASSETS/*
do
ASSET_NAME=$(basename "$ASSET")
curl \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$ASSET" \
"${UPLOAD_URL/{*}?name=$ASSET_NAME"
done
98 changes: 98 additions & 0 deletions pkg/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
#
# This script build a release asset. It is expected to be invoked in a GitHub
# Actions runner.

set -xeuo pipefail

mkdir -p ASSETS

# Install the Rust compiler.

if command -v apt-get
then
apt-get update
apt-get install -y \
build-essential \
curl \
debhelper \
git

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal -y
source ~/.cargo/env

elif command -v yum
then
yum install -y \
cargo \
gettext \
git \
rpm-build

elif command -v zypper
then
zypper install -y \
cargo \
gettext-runtime \
git \
rpm-build

else
echo "Unsupported system"
exit 1
fi

# Test the builtin in this system.
cargo test

# If MAKE_TARBALL is 1, create two packages (with and without debug info).
#
# Otherwise, build and test a package for the current OS.
if [ "${MAKE_TARBALL:-0}" -eq 1 ]
then
source <(pkg/common/metadata)

# With debug.
RUSTFLAGS="-g" cargo build --release

tar \
-czf "ASSETS/$PACKAGE_NAME-$PACKAGE_VERSION-debug.tar.gz" \
-C target/release \
libtimehistory_bash.so

# Without debug.
cargo clean
cargo build --release
strip target/release/libtimehistory_bash.so

tar \
-czf "ASSETS/$PACKAGE_NAME-$PACKAGE_VERSION.tar.gz" \
-C target/release \
libtimehistory_bash.so

exit 0

elif command -v apt-get
then
./pkg/debian/build.sh

rm -f target/packages/*-dbgsym*deb
dpkg -i target/packages/*.deb

else
./pkg/rpm/build.sh

rpm -i target/packages/*.rpm

fi

enable -f /usr/lib/bash/libtimehistory_bash.so timehistory
trap timehistory EXIT

source /etc/os-release
for PKG in target/packages/*
do
mv -vn \
"$PKG" \
"ASSETS/$ID-$VERSION_ID-$(basename "$PKG")"
done
1 change: 0 additions & 1 deletion pkg/debian/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ find target/release -maxdepth 1 -name '*.so' -exec cp -a {} "$DEST_BIN" \;

mkdir -p "$DEST_DOC"
cp -a ./*.md "$DEST_DOC"
rename.ul .md .txt "$DEST_DOC"/*.md

mkdir -p "$DEST_DEB"

Expand Down
8 changes: 5 additions & 3 deletions pkg/rpm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ DEST=$(mktemp -d)
envsubst < timehistory.spec > "$DEST/timehistory.spec"

cd "$(git rev-parse --show-toplevel)"
HOME="$DEST" rpmbuild --build-in-place -bb "$DEST/timehistory.spec"
rpmbuild -bb --build-in-place \
--define "_rpmdir $PWD/target/packages" \
"$DEST/timehistory.spec"

mkdir -p target/packages
find "$DEST/rpmbuild/RPMS" -type f -name '*.rpm' -exec cp -t target/packages {} +
cd target/packages
mv */*.rpm .

0 comments on commit f84c793

Please sign in to comment.