Bump actions/cache from 3.3.1 to 4.0.0 (#90) #169
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: | |
- "main" | |
- "master" | |
- "dev" | |
paths-ignore: | |
- "README.md" | |
- "LICENSE" | |
pull_request: | |
branches: | |
- "main" | |
- "master" | |
- "dev" | |
paths-ignore: | |
- "README.md" | |
- "LICENSE" | |
release: | |
types: | |
- "prereleased" | |
- "published" | |
- "released" | |
# For test | |
workflow_dispatch: | |
env: | |
RUST_BACKTRACE: 1 | |
jobs: | |
init: | |
runs-on: ubuntu-latest | |
outputs: | |
SOURCE_OWNER: ${{ steps.repo_info.outputs.SOURCE_OWNER }} | |
SOURCE_REPO: ${{ steps.repo_info.outputs.SOURCE_REPO }} | |
BINARY_NAME: ${{ steps.binary.outputs.NAME }} | |
steps: | |
- name: 源代码仓库信息 | |
id: repo_info | |
shell: bash | |
env: | |
SOURCE_URL: ${{ github.repository }} | |
run: | | |
export SOURCE_OWNER="$(echo $SOURCE_URL | awk -F '/' '{print $(NF-1)}')" | |
echo "SOURCE_OWNER=$SOURCE_OWNER" >> $GITHUB_ENV | |
echo "SOURCE_OWNER=${SOURCE_OWNER}" >> $GITHUB_OUTPUT | |
export SOURCE_REPO="$(echo $SOURCE_URL | awk -F '/' '{print $(NF)}')" | |
echo "SOURCE_REPO=$SOURCE_REPO" >> $GITHUB_ENV | |
echo "SOURCE_REPO=${SOURCE_REPO}" >> $GITHUB_OUTPUT | |
- name: 生成文件名 | |
id: binary | |
run: | | |
echo "NAME=${SOURCE_REPO}" >> $GITHUB_OUTPUT | |
build: | |
env: | |
CARGO_TERM_COLOR: always | |
name: ${{ matrix.config.target_triple }} | |
needs: [init] | |
runs-on: ${{ matrix.config.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
- { | |
name: "Windows-x86_64", | |
artifact: "Windows-x86_64", | |
os: windows-latest, | |
has_release: true, | |
rust: stable, | |
target_triple: x86_64-pc-windows-msvc, | |
} | |
- { | |
name: "Linux", | |
artifact: "Linux-x86_64", | |
os: ubuntu-latest, | |
has_release: true, | |
rust: stable, | |
target_triple: x86_64-unknown-linux-musl, | |
} | |
- { | |
name: "Linux", | |
artifact: "Linux-arm64", | |
os: ubuntu-latest, | |
has_release: true, | |
rust: stable, | |
target_triple: aarch64-unknown-linux-musl, | |
} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: macOS - Build preparation - Install Packages | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
brew install coreutils | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: ${{ matrix.config.rust }} | |
target: ${{ matrix.config.target_triple }} | |
override: true | |
profile: minimal | |
- name: Get rust version | |
id: rust-version | |
run: | | |
echo "version=$(rustc --version)" >> $GITHUB_OUTPUT | |
- name: Cache cargo index | |
uses: actions/[email protected] | |
with: | |
path: ~/.cargo/registry/index | |
key: index-${{ runner.os }}-${{ matrix.config.target_triple }}-${{ github.run_number }} | |
restore-keys: | | |
index-${{ runner.os }}-${{ matrix.config.target_triple }}- | |
- name: Cache cargo registry | |
uses: actions/[email protected] | |
with: | |
path: ~/.cargo/registry/cache | |
key: registry-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ matrix.config.target_triple }}-${{ hashFiles('Cargo.lock') }} | |
- name: Fetch dependencies | |
run: cargo fetch | |
- name: Cache target directory | |
uses: actions/[email protected] | |
with: | |
path: target | |
key: cache-target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }} | |
- name: Build | |
shell: bash | |
run: | | |
if [[ ${{ matrix.config.target_triple }} != x86_64* ]]; then | |
docker run --rm -v "$(pwd)":/home/rust/src -v "$HOME/.cargo/registry":/root/.cargo/registry ghcr.io/messense/rust-musl-cross:aarch64-musl cargo build --release | |
else | |
cargo build --release --target=${{ matrix.config.target_triple }} | |
fi | |
- name: Run tests | |
shell: bash | |
run: | | |
if [[ ${{ matrix.config.target_triple }} != x86_64* ]]; then | |
echo "skip" | |
else | |
cargo test --release --target=${{ matrix.config.target_triple }} | |
fi | |
- name: 整理 | |
shell: bash | |
run: | | |
mkdir release-tmp | |
cp ./target/${{matrix.config.target_triple}}/release/${{ needs.init.outputs.BINARY_NAME}} ./release-tmp/ | |
- name: Upload a Build Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ needs.init.outputs.BINARY_NAME}}-${{ github.sha }}-${{ matrix.config.artifact }} | |
path: release-tmp | |
- name: Get the version | |
if: github.event_name == 'release' && matrix.config.has_release | |
id: get_version | |
run: | | |
echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT | |
- name: Upload to GitHub Release | |
uses: svenstaro/upload-release-action@v2 | |
if: github.event_name == 'release' && matrix.config.has_release | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ${{ needs.init.outputs.BINARY_NAME}} | |
asset_name: ${{ needs.init.outputs.BINARY_NAME}}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.config.artifact }} | |
tag: ${{ github.ref }} | |
overwrite: true | |
deploy: | |
needs: [init, build] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Download artifact | |
id: download-artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
if_no_artifact_found: warn | |
- name: 显示下载的内容 | |
run: | | |
ls -lha | |
- name: 压缩文件 | |
run: | | |
system_type=$(uname) | |
system_arch=$(uname -m) | |
lujin="$(find "$PWD" -maxdepth 1 -type d -name "*${system_type}*${system_arch}")" | |
chmod +x ./*/* | |
sudo cp -f "${lujin}/${{ needs.init.outputs.BINARY_NAME}}" /usr/local/bin/ | |
nomino -p -r "(.*)-.*-(.*)-(.*)" "{}-{}-{}" | |
current_path_folder=$(find . -type d -print) | |
for i in ${current_path_folder}; do | |
echo "${i}" | |
filename=$(basename "${i}") | |
if ! mv "${i}"/${{ needs.init.outputs.BINARY_NAME}} "${filename,,}";then | |
if ! mv "${i}"/${{ needs.init.outputs.BINARY_NAME}}.exe "${filename,,}";then | |
continue | |
fi | |
fi | |
rm -r "${i}" | |
done | |
f_files=$(find . -name "${{ needs.init.outputs.BINARY_NAME}}*" -type f -print) | |
for i in ${f_files}; do | |
zstd --rm -T0 --ultra -22 "${i}" & | |
done | |
wait | |
- name: 显示下载的内容 | |
run: | | |
ls -lha | |
sudo apt install -y b3sum | |
b3sum * >> b3sum | |
- uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "${{ needs.init.outputs.BINARY_NAME}}*" | |
bodyFile: "b3sum" | |
tag: "dev" | |
allowUpdates: true |