]> code.octet-stream.net Git - hashgood/commitdiff
Build scripts
authorThomas Karpiniec <tom.karpiniec@outlook.com>
Mon, 16 Dec 2024 08:59:41 +0000 (19:59 +1100)
committerThomas Karpiniec <tom.karpiniec@outlook.com>
Mon, 16 Dec 2024 08:59:41 +0000 (19:59 +1100)
.github/workflows/release.yml [deleted file]
.github/workflows/rust.yml [deleted file]
buildscripts/build.sh [new file with mode: 0755]
buildscripts/dist-generic.sh [new file with mode: 0755]
buildscripts/dist.sh [new file with mode: 0755]
buildscripts/init.sh [new file with mode: 0644]
buildscripts/lint.sh [new file with mode: 0755]
buildscripts/test.sh [new file with mode: 0755]
src/calculate.rs
src/verify.rs

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
deleted file mode 100644 (file)
index d3af78c..0000000
+++ /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 (file)
index 26ecad9..0000000
+++ /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 (executable)
index 0000000..469dff2
--- /dev/null
@@ -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 (executable)
index 0000000..844201e
--- /dev/null
@@ -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 (executable)
index 0000000..4ad4649
--- /dev/null
@@ -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 (file)
index 0000000..ed73ec8
--- /dev/null
@@ -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 (executable)
index 0000000..bf9fc8f
--- /dev/null
@@ -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 (executable)
index 0000000..a02b370
--- /dev/null
@@ -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}"
index 3ba5a7d0538be39b45a5616386e8082aebbb566f..955016dae59fe6139f97553cb9e7cef071dae415 100644 (file)
@@ -157,7 +157,7 @@ mod tests {
         "b9193853f7798e92e2f6b82eda336fa7d6fc0fa90fdefe665f372b0bad8cdf8c";
 
     fn verify_digest(alg: Algorithm, data: &'static [u8], hash: &str) {
         "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()));
         let digests = create_digests(&[alg], Box::new(reader)).unwrap();
         assert_eq!(digests.len(), 1);
         assert_eq!(digests[0], (alg, hex::decode(hash).unwrap()));
index 77120da502a441d7d3ca656f4cf26c2b50e80f0c..c3d0147507df69c66633295da2a17e1739f745e9 100644 (file)
@@ -23,7 +23,7 @@ pub fn get_candidate_hashes(opt: &Opt) -> Result<Option<CandidateHashes>, String
 /// Generate a candidate hash from the provided command line parameter, or throw an error.
 fn get_by_parameter(param: &str) -> Result<CandidateHashes, String> {
     let bytes =
 /// Generate a candidate hash from the provided command line parameter, or throw an error.
 fn get_by_parameter(param: &str) -> Result<CandidateHashes, String> {
     let bytes =
-        hex::decode(&param).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,
     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] {
         ));
 
         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());
         }
     }
 
         }
     }