Skip to content

Commit

Permalink
release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
c3b2a7 committed Sep 13, 2024
1 parent 99c5ca6 commit 576b08c
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 5 deletions.
140 changes: 140 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Build and release
on:
push:
tags:
- v*
workflow_dispatch:
inputs:
tag:
description: 'Release Tag'
required: true
type: string

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full

jobs:
build-cross:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- i686-unknown-linux-musl
- x86_64-pc-windows-gnu
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- armv7-unknown-linux-musleabihf
- armv7-unknown-linux-gnueabihf
- arm-unknown-linux-gnueabi
- arm-unknown-linux-gnueabihf
- arm-unknown-linux-musleabi
- arm-unknown-linux-musleabihf
- aarch64-unknown-linux-gnu
- aarch64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install stable
rustup default stable
rustup override set stable
rustup target add --toolchain stable ${{ matrix.target }}
- name: Install cross
run: cargo install cross

- name: Build ${{ matrix.target }}
timeout-minutes: 120
run: |
compile_target=${{ matrix.target }}
# compile_features="-f full"
if [[ "$compile_target" == "mips-"* || "$compile_target" == "mipsel-"* \
|| "$compile_target" == "mips64-"* || "$compile_target" == "mips64el-"* ]]; then
sudo apt-get update -y && sudo apt-get install -y upx;
if [[ "$?" == "0" ]]; then
compile_compress="-u"
fi
fi
chmod +x ./build/build-release.sh
./build/build-release.sh -t ${{ matrix.target }} $compile_features $compile_compress
- name: Upload Github Assets
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: build/release/*
prerelease: ${{ contains(github.ref_name, '-') }}
tag_name: ${{ inputs.tag || github.ref_name }}

build-unix:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-apple-darwin
- aarch64-apple-darwin
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install stable
rustup default stable
rustup override set stable
rustup target add --toolchain stable ${{ matrix.target }}
- name: Build release
shell: bash
run: |
chmod +x ./build/build-host-release.sh
./build/build-host-release.sh -t ${{ matrix.target }}
- name: Upload Github Assets
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: build/release/*
prerelease: ${{ contains(github.ref_name, '-') }}
tag_name: ${{ inputs.tag || github.ref_name }}

build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install stable
rustup default stable
rustup override set stable
- name: Build release
shell: bash
run: |
chmod +x ./build/build-host-release.sh
./build/build-host-release.sh -t x86_64-pc-windows-msvc
- name: Upload Github Assets
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: build/release/*
prerelease: ${{ contains(github.ref_name, '-') }}
tag_name: ${{ inputs.tag || github.ref_name }}
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "smmstools"
authors = ["萌面喵喵侠<[email protected]"]
homepage = "https://lolico.me"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[[bin]]
Expand All @@ -11,14 +11,16 @@ path = "src/bin/main.rs"

[dependencies]
reqwest = { version = "0.12", features = ["json", "multipart", "stream"] }
tokio = { version = "1.40", features = ["full"] }
clap = { version = "4.5", features = ["derive", "env"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
mime_guess = { version = "2" }
tokio = { version = "1.40", features = ["full"] }
thiserror = "1.0"
clap = { version = "4.5", features = ["derive", "env"] }
anyhow = "1.0"
[target.'cfg(not(any(target_os = "windows")))'.dependencies]
openssl = { version = "0.10", features = ["vendored"] }

[dev-dependencies]
assert_matches = "1.5.0"
Expand All @@ -29,4 +31,4 @@ tokio = { version = "1.40", features = ["test-util"] }
lto = true # Enable link-time optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations
panic = 'abort' # Abort on panic
strip = true # Strip symbols from binary*
strip = true # Strip symbols from binary*
9 changes: 9 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build]
dockerfile = "./docker/linux-cross/Dockerfile"
pre-build = [
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable",
". $HOME/.cargo/env",
]

[build.env]
passthrough = ["RUSTFLAGS"]
99 changes: 99 additions & 0 deletions build/build-host-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash

BUILD_TARGET=""
BUILD_FEATURES=()
while getopts "t:f:" opt; do
case $opt in
t)
BUILD_TARGET=$OPTARG
;;
f)
BUILD_FEATURES+=($OPTARG)
;;
?)
echo "Usage: $(basename $0) [-t <target-triple>] [-f <feature>]"
;;
esac
done

BUILD_FEATURES+=${EXTRA_FEATURES}

ROOT_DIR=$(cd $(dirname $0) && pwd)
VERSION=$(grep -E '^version' "${ROOT_DIR}/../Cargo.toml" | awk '{print $3}' | sed 's/"//g')
HOST_TRIPLE=$(rustc -Vv | grep 'host:' | awk '{print $2}')

echo "Started build release ${VERSION} for ${HOST_TRIPLE} (target: ${BUILD_TARGET}) with features \"${BUILD_FEATURES}\"..."

CARGO_RELEASE_OPTS="--release"
if [[ "${BUILD_TARGET}" != "" ]]; then
CARGO_RELEASE_OPTS+=" --target ${BUILD_TARGET}"
if [[ "${BUILD_FEATURES}" != "" ]]; then
CARGO_RELEASE_OPTS+=" --features ${BUILD_FEATURES}"
fi
fi

cargo build ${CARGO_RELEASE_OPTS}
if [[ "$?" != "0" ]]; then
exit 1
fi

if [[ "${BUILD_TARGET}" == "" ]]; then
BUILD_TARGET=$HOST_TRIPLE
fi

TARGET_SUFFIX=""
if [[ "${BUILD_TARGET}" == *"-windows-"* ]]; then
TARGET_SUFFIX=".exe"
fi

TARGETS=("smmstools${TARGET_SUFFIX}")


RELEASE_FOLDER="${ROOT_DIR}/release"
RELEASE_PACKAGE_NAME="smmstools-v${VERSION}.${BUILD_TARGET}"

mkdir -p "${RELEASE_FOLDER}"

# Into release folder
if [[ "${BUILD_TARGET}" != "" ]]; then
cd "${ROOT_DIR}/../target/${BUILD_TARGET}/release"
else
cd "${ROOT_DIR}/../target/release"
fi

if [[ "${BUILD_TARGET}" == *"-windows-"* ]]; then
# For Windows, use zip

RELEASE_PACKAGE_FILE_NAME="${RELEASE_PACKAGE_NAME}.zip"
RELEASE_PACKAGE_FILE_PATH="${RELEASE_FOLDER}/${RELEASE_PACKAGE_FILE_NAME}"
7z a "${RELEASE_PACKAGE_FILE_PATH}" "${TARGETS[@]}"

if [[ $? != "0" ]]; then
exit 1
fi

# Checksum
cd "${RELEASE_FOLDER}"
sha256sum "${RELEASE_PACKAGE_FILE_NAME}" >"${RELEASE_PACKAGE_FILE_NAME}.sha256"
else
# For others, Linux, OS X, uses tar.gz

# For Darwin, .DS_Store and other related files should be ignored
if [[ "$(uname -s)" == "Darwin" ]]; then
export COPYFILE_DISABLE=1
fi

RELEASE_PACKAGE_FILE_NAME="${RELEASE_PACKAGE_NAME}.tar.gz"
RELEASE_PACKAGE_FILE_PATH="${RELEASE_FOLDER}/${RELEASE_PACKAGE_FILE_NAME}"
tar -czf "${RELEASE_PACKAGE_FILE_PATH}" "${TARGETS[@]}"

if [[ $? != "0" ]]; then
exit 1
fi

# Checksum
cd "${RELEASE_FOLDER}"
shasum -a 256 "${RELEASE_PACKAGE_FILE_NAME}" >"${RELEASE_PACKAGE_FILE_NAME}.sha256"
fi

echo "Finished build release ${RELEASE_PACKAGE_FILE_PATH}"
Loading

0 comments on commit 576b08c

Please sign in to comment.