-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): refactor release pipeline
This is a refactor of the release pipeline scripts and includes a number of changes: - Scripts have been reorganised into independent functions for each target being built. This should, hopefully, help maintain these scripts going forward. - The scripts allow for arguments to be passed directly to `cargo`, thereby allowing for non-release builds as well. - The release pipeline now also runs on PRs. If being run on PRs, a non-release build done as it is faster. - The publishing steps of the pipeline have been separated into a distinct job (which only runs on releases) - A concurrency group is set up, which will cancel existing builds if a new build is triggered on the same PR or on master. - Some actions in the pipeline have been updated. - The macOS SDK target has been upgraded to version 12 as version 11 is no longer maintained. - Cache dependencies to try and reduce the runtime Signed-off-by: JP-Ellis <josh@jpellis.me>
- Loading branch information
Showing
11 changed files
with
614 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,124 @@ | ||
#!/bin/bash -x | ||
#!/bin/bash | ||
|
||
set -e | ||
set -x | ||
|
||
echo -- Setup directories -- | ||
cargo clean | ||
mkdir -p ../release_artifacts | ||
|
||
echo -- Build the Docker build image -- | ||
docker build -f Dockerfile.linux-build -t pact-ffi-build . | ||
|
||
echo -- Build the release artifacts -- | ||
docker run -t --rm --user "$(id -u)":"$(id -g)" -v $(pwd)/..:/workspace -w /workspace/pact_ffi pact-ffi-build -c 'cargo build --release' | ||
gzip -c ../target/release/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-x86_64.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64.so.gz > ../release_artifacts/libpact_ffi-linux-x86_64.so.gz.sha256 | ||
gzip -c ../target/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-x86_64.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64.a.gz > ../release_artifacts/libpact_ffi-linux-x86_64.a.gz.sha256 | ||
|
||
echo -- Generate the header files -- | ||
rustup toolchain install nightly | ||
rustup component add rustfmt --toolchain nightly | ||
rustup run nightly cbindgen \ | ||
--config cbindgen.toml \ | ||
--crate pact_ffi \ | ||
--output include/pact.h | ||
rustup run nightly cbindgen \ | ||
--config cbindgen-c++.toml \ | ||
--crate pact_ffi \ | ||
--output include/pact-cpp.h | ||
cp include/*.h ../release_artifacts | ||
|
||
echo -- Build the musl release artifacts -- | ||
cargo install cross@0.2.5 | ||
cross build --release --target=x86_64-unknown-linux-musl | ||
gzip -c ../target/x86_64-unknown-linux-musl/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-x86_64-musl.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64-musl.a.gz > ../release_artifacts/libpact_ffi-linux-x86_64-musl.a.gz.sha256 | ||
|
||
mkdir tmp | ||
cp ../target/x86_64-unknown-linux-musl/release/libpact_ffi.a tmp/ | ||
docker run --platform=linux/amd64 --rm -v $PWD/tmp:/scratch alpine /bin/sh -c 'apk add --no-cache musl-dev gcc && \ | ||
RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd )" | ||
|
||
source "$RUST_DIR/scripts/gzip-and-sum.sh" | ||
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"} | ||
mkdir -p "$ARTIFACTS_DIR" | ||
export CARGO_TARGET_DIR=${CARO_TARGET_DIR:-"$RUST_DIR/target"} | ||
|
||
# All flags passed to this script are passed to cargo. | ||
cargo_flags=( "$@" ) | ||
|
||
# Build the x86_64 GNU linux release | ||
build_x86_64_gnu() { | ||
cargo build --target x86_64-unknown-linux-gnu "${cargo_flags[@]}" | ||
|
||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/libpact_ffi.a" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64.a.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/libpact_ffi.so" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64.so.gz" | ||
fi | ||
} | ||
|
||
build_x86_64_musl() { | ||
sudo apt-get install -y musl-tools | ||
cargo build --target x86_64-unknown-linux-musl "${cargo_flags[@]}" | ||
|
||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
BUILD_SCRIPT=$(cat <<EOM | ||
apk add --no-cache musl-dev gcc && \ | ||
cd /scratch && \ | ||
ar -x libpact_ffi.a && \ | ||
gcc -shared *.o -o libpact_ffi.so && \ | ||
rm -f *.o' | ||
ar -x libpact_ffi.a && \ | ||
gcc -shared *.o -o libpact_ffi.so && \ | ||
rm -f *.o | ||
EOM | ||
) | ||
|
||
docker run \ | ||
--platform=linux/amd64 \ | ||
--rm \ | ||
-v "$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release:/scratch" \ | ||
alpine \ | ||
/bin/sh -c "$BUILD_SCRIPT" | ||
|
||
gzip -c tmp/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-x86_64-musl.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64-musl.so.gz > ../release_artifacts/libpact_ffi-linux-x86_64-musl.so.gz.sha256 | ||
rm -rf tmp | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/libpact_ffi.a" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64-musl.a.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/libpact_ffi.so" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64-musl.so.gz" | ||
fi | ||
} | ||
|
||
install_cross() { | ||
cargo install cross@0.2.5 | ||
} | ||
|
||
echo -- Build the musl aarch64 release artifacts -- | ||
cargo clean | ||
cross build --release --target=aarch64-unknown-linux-musl | ||
gzip -c ../target/aarch64-unknown-linux-musl/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-aarch64-musl.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64-musl.a.gz > ../release_artifacts/libpact_ffi-linux-aarch64-musl.a.gz.sha256 | ||
build_aarch64_gnu() { | ||
install_cross | ||
cross build --target aarch64-unknown-linux-gnu "${cargo_flags[@]}" | ||
|
||
mkdir tmp | ||
cp ../target/aarch64-unknown-linux-musl/release/libpact_ffi.a tmp/ | ||
docker run --platform=linux/arm64 --rm -v $PWD/tmp:/scratch alpine /bin/sh -c 'apk add --no-cache musl-dev gcc && \ | ||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/libpact_ffi.a" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64.a.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/libpact_ffi.so" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64.so.gz" | ||
fi | ||
} | ||
|
||
build_aarch64_musl() { | ||
install_cross | ||
cross build --target aarch64-unknown-linux-musl "${cargo_flags[@]}" | ||
|
||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
BUILD_SCRIPT=$(cat <<EOM | ||
apk add --no-cache musl-dev gcc && \ | ||
cd /scratch && \ | ||
ar -x libpact_ffi.a && \ | ||
gcc -shared *.o -o libpact_ffi.so && \ | ||
rm -f *.o' | ||
|
||
gzip -c tmp/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-aarch64-musl.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64-musl.so.gz > ../release_artifacts/libpact_ffi-linux-aarch64-musl.so.gz.sha256 | ||
rm -rf tmp | ||
|
||
echo -- Build the aarch64 release artifacts -- | ||
cargo clean | ||
cross build --target aarch64-unknown-linux-gnu --release | ||
gzip -c ../target/aarch64-unknown-linux-gnu/release/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-aarch64.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64.so.gz > ../release_artifacts/libpact_ffi-linux-aarch64.so.gz.sha256 | ||
gzip -c ../target/aarch64-unknown-linux-gnu/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-aarch64.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64.a.gz > ../release_artifacts/libpact_ffi-linux-aarch64.a.gz.sha256 | ||
ar -x libpact_ffi.a && \ | ||
gcc -shared *.o -o libpact_ffi.so && \ | ||
rm -f *.o | ||
EOM | ||
) | ||
|
||
docker run \ | ||
--platform=linux/arm64 \ | ||
--rm \ | ||
-v "$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release:/scratch" \ | ||
alpine \ | ||
/bin/sh -c "$BUILD_SCRIPT" | ||
|
||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/libpact_ffi.a" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64-musl.a.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/libpact_ffi.so" \ | ||
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64-musl.so.gz" | ||
fi | ||
} | ||
|
||
build_header() { | ||
rustup toolchain install nightly | ||
rustup run nightly cbindgen \ | ||
--config cbindgen.toml \ | ||
--crate pact_ffi \ | ||
--output "$ARTIFACTS_DIR/pact.h" | ||
rustup run nightly cbindgen \ | ||
--config cbindgen-c++.toml \ | ||
--crate pact_ffi \ | ||
--output "$ARTIFACTS_DIR/pact-cpp.h" | ||
} | ||
|
||
build_x86_64_gnu | ||
build_x86_64_musl | ||
build_aarch64_gnu | ||
build_aarch64_musl | ||
build_header |
Oops, something went wrong.