chore: add release script and test ci

Signed-off-by: zu1k <i@zu1k.com>
pull/26/head
zu1k 2022-12-01 11:46:48 +08:00
parent 4257180dea
commit 8d42701f9b
No known key found for this signature in database
GPG Key ID: AE381A8FB1EF2CC8
8 changed files with 194 additions and 10 deletions

View File

@ -1,6 +1,7 @@
index
.github
target
/release
.vscode/*
.idea

57
.github/workflows/test.yaml vendored 100644
View File

@ -0,0 +1,57 @@
name: Build Test
on: [push, pull_request_target, workflow_dispatch]
jobs:
build:
name: Build Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: |
make frontend_preinstall
- name: Build dist
run: |
make frontend
- uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build Debug App
run: make build
- name: Archive App File
uses: actions/upload-artifact@v2
with:
name: zlib-sercher
path: target/debug/zlib-sercher

1
.gitignore vendored
View File

@ -2,4 +2,5 @@
/index
*.csv
/release
/zlib-searcher

10
Cross.yaml 100644
View File

@ -0,0 +1,10 @@
[build.env]
passthrough = [
"RUSTFLAGS"
]
[target.mips-unknown-linux-musl]
image = "rustembedded/cross:mips-unknown-linux-musl-0.2.1"
[target.mipsel-unknown-linux-musl]
image = "rustembedded/cross:mipsel-unknown-linux-musl-0.2.1"

24
Makefile 100644
View File

@ -0,0 +1,24 @@
NAME=zlib-searcher
PREFIX ?= /usr/local/bin
TARGET ?= debug
.PHONY: all frontend_preinstall frontend build clean
all: build
frontend_preinstall:
pnpm -C frontend install
frontend:
pnpm -C frontend run build
build:
ifeq (${TARGET}, release)
cargo build -p zlib-searcher --release
else
cargo build -p zlib-searcher
endif
clean:
cargo clean
rm -rf release

View File

@ -75,15 +75,13 @@ Examples:
First build frontend
```bash
pushd frontend
pnpm install && pnpm run build
popd
make frontend_preinstall frontend
```
Then build zlib-searcher
```bash
cargo build --release -p zlib-searcher
TARGET=release make
# move the compiled binary to the project root directory
mv target/release/zlib-searcher .

View File

@ -1,6 +0,0 @@
#!/bin/bash
pushd frontend
pnpm install
pnpm run build
popd

View File

@ -0,0 +1,99 @@
#!/bin/bash
CUR_DIR=$( cd $( dirname $0 ) && pwd )
project=zlib-searcher
targets=()
features=()
while getopts "t:f:u" opt; do
case $opt in
p)
project=($OPTARG)
;;
t)
targets+=($OPTARG)
;;
f)
features+=($OPTARG)
;;
?)
echo "Usage: $(basename $0) [-t <target-triple>] [-f features]"
;;
esac
done
features+=${EXTRA_FEATURES}
if [[ "${#targets[@]}" == "0" ]]; then
echo "Specifying compile target with -t <target-triple>"
exit 1
fi
function build() {
cd "$CUR_DIR/.."
TARGET=$1
RELEASE_DIR="target/${TARGET}/release"
TARGET_FEATURES="${features[@]}"
if [[ "${TARGET_FEATURES}" != "" ]]; then
echo "* Building ${project} package for ${TARGET} with features \"${TARGET_FEATURES}\" ..."
cross build --target "${TARGET}" \
--default-features=false
--features "${TARGET_FEATURES}" \
--release
else
echo "* Building ${project} package for ${TARGET} ..."
cross build --target "${TARGET}" \
--release
fi
if [[ $? != "0" ]]; then
exit 1
fi
PKG_DIR="${CUR_DIR}/../release"
mkdir -p "${PKG_DIR}"
if [[ "$TARGET" == *"-linux-"* ]]; then
PKG_NAME="${project}-${TARGET}.tar.gz"
PKG_PATH="${PKG_DIR}/${PKG_NAME}"
cd ${RELEASE_DIR}
echo "* Packaging gz in ${PKG_PATH} ..."
tar -czf ${PKG_PATH} ${project}
if [[ $? != "0" ]]; then
exit 1
fi
cd "${PKG_DIR}"
shasum -a 256 "${PKG_NAME}" > "${PKG_NAME}.sha256"
elif [[ "$TARGET" == *"-windows-"* ]]; then
PKG_NAME="${project}-${TARGET}.zip"
PKG_PATH="${PKG_DIR}/${PKG_NAME}"
echo "* Packaging ZIP in ${PKG_PATH} ..."
cd ${RELEASE_DIR}
zip ${PKG_PATH} ${project}.exe
if [[ $? != "0" ]]; then
exit 1
fi
cd "${PKG_DIR}"
shasum -a 256 "${PKG_NAME}" > "${PKG_NAME}.sha256"
fi
echo "* Done build package ${PKG_NAME}"
}
for target in "${targets[@]}"; do
cargo clean;
build "$target";
done