Skip to content

Commit

Permalink
ci: add begin_group / end_group utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Apr 16, 2024
1 parent d4498c4 commit 46a33bb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
18 changes: 10 additions & 8 deletions ci/build-dist-linux.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

echo "::group::Install dependencies"
. ci/utils.sh

begin_group "Install dependencies"
yum install -y glibc-devel.i686 libgcc.i686
echo "::endgroup::"
end_group

echo "::group::Install Rust"
begin_group "Install Rust"

rust_version="$(cat "ci/rust-versions/stable.txt")"

Expand All @@ -17,15 +19,15 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
# shellcheck disable=SC1090
. "$HOME/.cargo/env"

echo "::endgroup::"
end_group

export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_CODEGEN_PANIC=abort
export CARGO_PROFILE_RELEASE_STRIP=debuginfo

echo "::group::Fetch Rust dependencies"
begin_group "Fetch Rust dependencies"
cargo fetch --locked
echo "::endgroup::"
end_group

mkdir output

Expand All @@ -34,12 +36,12 @@ build_and_compress() {
target="$2"
full_name="rsjsonnet-$name"

echo "::group::Build $name"
begin_group "Build $name"
cargo build -p rsjsonnet --target "$target" --release --frozen
mkdir "output/$full_name"
cp -t "output/$full_name" "target/$target/release/rsjsonnet"
(cd output; tar -czf "$full_name.tar.gz" "$full_name")
echo "::endgroup::"
end_group
}

build_and_compress linux-x86_64 x86_64-unknown-linux-gnu
Expand Down
18 changes: 10 additions & 8 deletions ci/build-dist-windows.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

echo "::group::Install dependencies"
. ci/utils.sh

begin_group "Install dependencies"
apt-get update
apt-get install -y --no-install-recommends \
curl \
Expand All @@ -11,9 +13,9 @@ apt-get install -y --no-install-recommends \
libc6-dev \
gcc-mingw-w64-x86-64 \
gcc-mingw-w64-i686
echo "::endgroup::"
end_group

echo "::group::Install Rust"
begin_group "Install Rust"

rust_version="$(cat "ci/rust-versions/stable.txt")"

Expand All @@ -25,15 +27,15 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
# shellcheck disable=SC1090
. "$HOME/.cargo/env"

echo "::endgroup::"
end_group

export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_CODEGEN_PANIC=abort
export CARGO_PROFILE_RELEASE_STRIP=debuginfo

echo "::group::Fetch Rust dependencies"
begin_group "Fetch Rust dependencies"
cargo fetch --locked
echo "::endgroup::"
end_group

mkdir output

Expand All @@ -42,12 +44,12 @@ build_and_compress() {
target="$2"
full_name="rsjsonnet-$name"

echo "::group::Build $name"
begin_group "Build $name"
cargo build -p rsjsonnet --target "$target" --release --frozen
mkdir "output/$full_name"
cp -t "output/$full_name" "target/$target/release/rsjsonnet.exe"
(cd output; zip -r "$full_name.zip" "$full_name")
echo "::endgroup::"
end_group
}

build_and_compress windows-x86_64 x86_64-pc-windows-gnu
Expand Down
10 changes: 7 additions & 3 deletions ci/lint-aux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail

. ci/utils.sh

echo "Checking MSRV consistency"
begin_group "Check MSRV consistency"

msrv="$(cat ci/rust-versions/msrv.txt)"
msrv="${msrv%.*}"
Expand Down Expand Up @@ -35,8 +35,12 @@ for crate in "${crates[@]}"; do
fi
done

echo "Checking shell scripts with shellcheck"
end_group

begin_group "Check shell scripts with shellcheck"
find . -type f -name "*.sh" -not -path "./.git/*" -print0 | xargs -0 shellcheck
end_group

echo "Checking markdown documents with markdownlint"
begin_group "Check markdown documents with markdownlint"
find . -type f -name "*.md" -not -path "./.git/*" -print0 | xargs -0 markdownlint
end_group
12 changes: 6 additions & 6 deletions ci/package-crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ if [ -e "$pkgs_dir" ]; then
exit 1
fi

echo "::group::Fetch dependencies"
begin_group "Fetch dependencies"
cargo fetch --locked
echo "::endgroup::"
end_group

echo "::group::Vendor dependencies"
begin_group "Vendor dependencies"
mkdir .cargo
cargo vendor --frozen "$pkgs_dir" > .cargo/config.toml
echo "::endgroup::"
end_group

crates=(
rsjsonnet-lang
Expand All @@ -25,13 +25,13 @@ crates=(
)

for crate in "${crates[@]}"; do
echo "::group::Package $crate"
begin_group "Package $crate"
version="$(crate_metadata "$crate" | jq -r ".version")"
cargo package -p "$crate" --frozen
tar -xf "target/package/$crate-$version.crate" -C "$pkgs_dir"
pkg_checksum="$(sha256sum "target/package/$crate-$version.crate" | awk '{print $1}')"
echo "{\"files\":{},\"package\":\"$pkg_checksum\"}" > "$pkgs_dir/$crate-$version/.cargo-checksum.json"
echo "::endgroup::"
end_group
done

mkdir output
Expand Down
18 changes: 17 additions & 1 deletion ci/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@ echo_stderr() {
echo "$@" >&2
}

begin_group() {
if [ $# -ne 1 ]; then
echo_stderr "Invalid use of $0"
exit 1
fi
echo "::group::$1"
}

end_group() {
if [ $# -ne 0 ]; then
echo_stderr "Invalid use of $0"
exit 1
fi
echo "::endgroup::"
}

crate_metadata() {
if [ $# -ne 1 ]; then
echo_stderr "Invalid use of crate_metadata"
echo_stderr "Invalid use of $0"
exit 1
fi
crate="$1"
Expand Down

0 comments on commit 46a33bb

Please sign in to comment.