From 585a245dd6e90efc545dbd68f928da9e03086cb9 Mon Sep 17 00:00:00 2001 From: Thomas Karpiniec Date: Mon, 16 Dec 2024 19:59:41 +1100 Subject: [PATCH] Build scripts --- .github/workflows/release.yml | 39 ------------------------------- .github/workflows/rust.yml | 23 ------------------ buildscripts/build.sh | 6 +++++ buildscripts/dist-generic.sh | 13 +++++++++++ buildscripts/dist.sh | 44 +++++++++++++++++++++++++++++++++++ buildscripts/init.sh | 32 +++++++++++++++++++++++++ buildscripts/lint.sh | 7 ++++++ buildscripts/test.sh | 6 +++++ src/calculate.rs | 2 +- src/verify.rs | 4 ++-- 10 files changed, 111 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/rust.yml create mode 100755 buildscripts/build.sh create mode 100755 buildscripts/dist-generic.sh create mode 100755 buildscripts/dist.sh create mode 100644 buildscripts/init.sh create mode 100755 buildscripts/lint.sh create mode 100755 buildscripts/test.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d3af78c..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Release - -on: - push: - tags: - - v[0-9]+.* - -jobs: - create-release: - name: Create GitHub release - if: github.repository_owner == 'thombles' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: taiki-e/create-gh-release-action@v1 - with: - changelog: CHANGELOG.md - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - upload-assets: - needs: create-release - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - include: - - os: windows-latest - features: paste - - os: macos-latest - features: paste - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - uses: taiki-e/upload-rust-binary-action@v1 - with: - bin: hashgood - features: ${{ matrix.features || '' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 26ecad9..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Rust - -on: [push] - -jobs: - build: - - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - include: - - os: windows-latest - features: "--features paste" - - os: macos-latest - features: "--features paste" - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v1 - - name: Build - run: cargo build ${{ matrix.features || '' }} - - name: Run tests - run: cargo test ${{ matrix.features || '' }} diff --git a/buildscripts/build.sh b/buildscripts/build.sh new file mode 100755 index 0000000..469dff2 --- /dev/null +++ b/buildscripts/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euxo pipefail +cd "$(git rev-parse --show-toplevel)" +source buildscripts/init.sh "$1" + +cargo build --target "${RUST_TARGET}" diff --git a/buildscripts/dist-generic.sh b/buildscripts/dist-generic.sh new file mode 100755 index 0000000..844201e --- /dev/null +++ b/buildscripts/dist-generic.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euxo pipefail +cd "$(git rev-parse --show-toplevel)" + +TAG=$1 + +BASENAME="hashgood-${TAG}" +FILENAME="${BASENAME}.tar.xz" + +git archive "${TAG}" -o "${FILENAME}" --prefix="${BASENAME}/" + +echo "GENERIC_ARTIFACT|${FILENAME}|Source Code" +echo "URL|Git Tag|https://code.octet-stream.net/hashgood/shortlog/refs/tags/${TAG}|${TAG}" diff --git a/buildscripts/dist.sh b/buildscripts/dist.sh new file mode 100755 index 0000000..4ad4649 --- /dev/null +++ b/buildscripts/dist.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -euxo pipefail +cd "$(git rev-parse --show-toplevel)" + +APP=hashgood + +PLATFORM=$1 +TAG=$2 +source buildscripts/init.sh "${PLATFORM}" + +BASENAME="${APP}-${TAG}-${PLATFORM}" + +case $PLATFORM in +windows-x86_64) + FILENAME="${BASENAME}.zip" + TARCMD="/c/Windows/System32/tar.exe -acf ${FILENAME} ${BASENAME}" + ;; +mac-x86_64|mac-arm64) + FILENAME="${BASENAME}.pkg" + TARCMD="pkgbuild --identifier net.octet-stream.${APP} --install-location /usr/local/bin/ --root ./${BASENAME} ${FILENAME}" + ;; +*) + FILENAME="${BASENAME}.tar.xz" + TARCMD="tar -Jcf ${FILENAME} ${BASENAME}" + ;; +esac + + +cargo build --target "${RUST_TARGET}" --release + +if [[ ${CODESIGNCMD:-"unset"} != "unset" ]]; then + "${CODESIGNCMD}" "target/${RUST_TARGET}/release/${APP}" +fi + +cd target +mkdir "${BASENAME}" +mv "${RUST_TARGET}/release/${APP}" "${BASENAME}" +${TARCMD} + +if [[ ${NOTARISECMD:-"unset"} != "unset" ]]; then + "${NOTARISECMD}" "target/${FILENAME}" +fi + +echo "PLATFORM_ARTIFACT|target/${FILENAME}" diff --git a/buildscripts/init.sh b/buildscripts/init.sh new file mode 100644 index 0000000..ed73ec8 --- /dev/null +++ b/buildscripts/init.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -euxo pipefail +cd "$(git rev-parse --show-toplevel)" + +PLATFORM=$1 + +case $PLATFORM in +mac-x86_64) + RUST_TARGET=x86_64-apple-darwin + ;; +mac-arm64) + RUST_TARGET=aarch64-apple-darwin + ;; +linux-x86_64) + RUST_TARGET=x86_64-unknown-linux-gnu + ;; +linux-armhf) + RUST_TARGET=armv7-unknown-linux-gnueabihf + ;; +linux-arm64) + RUST_TARGET=aarch64-unknown-linux-gnu + ;; +windows-x86_64) + RUST_TARGET=x86_64-pc-windows-msvc + ;; +*) + echo "Unrecognised platform" + exit 1 + ;; +esac + +export RUST_TARGET diff --git a/buildscripts/lint.sh b/buildscripts/lint.sh new file mode 100755 index 0000000..bf9fc8f --- /dev/null +++ b/buildscripts/lint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euxo pipefail +cd "$(git rev-parse --show-toplevel)" +source buildscripts/init.sh "$1" + +cargo clippy --all-targets --target "${RUST_TARGET}" -- -D warnings +cargo fmt --all --check diff --git a/buildscripts/test.sh b/buildscripts/test.sh new file mode 100755 index 0000000..a02b370 --- /dev/null +++ b/buildscripts/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euxo pipefail +cd "$(git rev-parse --show-toplevel)" +source buildscripts/init.sh "$1" + +cargo test --target "${RUST_TARGET}" diff --git a/src/calculate.rs b/src/calculate.rs index 3ba5a7d..955016d 100644 --- a/src/calculate.rs +++ b/src/calculate.rs @@ -157,7 +157,7 @@ mod tests { "b9193853f7798e92e2f6b82eda336fa7d6fc0fa90fdefe665f372b0bad8cdf8c"; fn verify_digest(alg: Algorithm, data: &'static [u8], hash: &str) { - let reader = Cursor::new(&*data); + let reader = Cursor::new(data); let digests = create_digests(&[alg], Box::new(reader)).unwrap(); assert_eq!(digests.len(), 1); assert_eq!(digests[0], (alg, hex::decode(hash).unwrap())); diff --git a/src/verify.rs b/src/verify.rs index 77120da..c3d0147 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -23,7 +23,7 @@ pub fn get_candidate_hashes(opt: &Opt) -> Result, String /// Generate a candidate hash from the provided command line parameter, or throw an error. fn get_by_parameter(param: &str) -> Result { let bytes = - hex::decode(¶m).map_err(|_| "Provided hash is invalid or truncated hex".to_owned())?; + hex::decode(param).map_err(|_| "Provided hash is invalid or truncated hex".to_owned())?; let alg = Algorithm::from_len(bytes.len())?; let candidate = CandidateHash { filename: None, @@ -299,7 +299,7 @@ mod tests { )); for i in &[invalid1, invalid2, invalid3, invalid4, invalid5] { - assert!(read_raw_candidate_from_file(*i, example_path).is_none()); + assert!(read_raw_candidate_from_file(i, example_path).is_none()); } } -- 2.39.5