Skip to content

Fix release package version check #2

Fix release package version check

Fix release package version check #2

Workflow file for this run

name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
tag:
description: "Release tag to build and upload assets for (for example, v1.0.0)"
required: true
type: string
permissions:
contents: read
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
jobs:
rust-tests:
name: Rust tests - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ env.RELEASE_TAG }}
persist-credentials: false
- uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
with:
toolchain: stable
components: rustfmt, clippy
- uses: Swatinem/rust-cache@49a0bdc70d2e1b713ca9e2869b211fcce03d3c1c # v2
- name: Run tests
run: cargo test --workspace --locked
code-quality:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ env.RELEASE_TAG }}
persist-credentials: false
- uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
with:
toolchain: stable
components: rustfmt, clippy
- name: Validate release tag and package version
shell: bash
run: |
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Release tag must use the form v1.2.3"
exit 1
fi
PACKAGE_VERSION="$(cargo metadata --locked --no-deps --format-version 1 | jq -er '.packages[] | select(.name == "bloatwarehatao-tui") | .version')"
if [ "v${PACKAGE_VERSION}" != "$RELEASE_TAG" ]; then
echo "::error::Tag ${RELEASE_TAG} does not match package version v${PACKAGE_VERSION}"
exit 1
fi
- name: Install cargo-deny
run: cargo install cargo-deny --version 0.20.2 --locked
- uses: Swatinem/rust-cache@49a0bdc70d2e1b713ca9e2869b211fcce03d3c1c # v2
- name: Check formatting
run: cargo fmt --all --check
- name: Run clippy
run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
- name: Run cargo-deny
run: cargo deny --locked check
build:
name: Build - ${{ matrix.target }}
needs: [rust-tests, code-quality]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_cross: true
# macOS
- os: macos-latest
target: aarch64-apple-darwin
use_cross: false
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ env.RELEASE_TAG }}
persist-credentials: false
- uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@49a0bdc70d2e1b713ca9e2869b211fcce03d3c1c # v2
with:
key: ${{ matrix.target }}
- name: Configure release path remapping
shell: bash
run: |
echo "RUSTFLAGS=--remap-path-prefix=${GITHUB_WORKSPACE}=. --remap-path-prefix=${HOME}/.cargo/registry/src=registry/src --remap-path-prefix=${HOME}/.cargo/git/checkouts=cargo/git/checkouts --remap-path-prefix=${HOME}/.rustup/toolchains=rustup/toolchains" >> "$GITHUB_ENV"
- name: Install cross
if: matrix.use_cross
run: cargo install cross --version 0.2.5 --locked
- name: Build release
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --locked --target ${{ matrix.target }}
else
cargo build --release --locked --target ${{ matrix.target }}
fi
shell: bash
- name: Package binary
shell: bash
run: |
VERSION="${RELEASE_TAG#v}"
ARCHIVE_BASE="bloatwarehatao-${VERSION}-${{ matrix.target }}"
if [ "${{ runner.os }}" = "Windows" ]; then
cp "target/${{ matrix.target }}/release/bloatwarehatao.exe" .
7z a "${ARCHIVE_BASE}.zip" bloatwarehatao.exe README.md LICENSE CHANGELOG.md packages
else
cp "target/${{ matrix.target }}/release/bloatwarehatao" .
tar czf "${ARCHIVE_BASE}.tar.gz" bloatwarehatao README.md LICENSE CHANGELOG.md packages
fi
- name: Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: binary-${{ matrix.target }}
path: bloatwarehatao-*-${{ matrix.target }}.*
upload-release:
name: Upload to GitHub Release
needs: [build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
path: dist
merge-multiple: true
- name: List built artifacts
run: ls -lh dist/
- name: Generate SHA256 checksums
run: |
cd dist
sha256sum bloatwarehatao-* > SHA256SUMS
- name: Upload binaries to release
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2
with:
tag_name: ${{ env.RELEASE_TAG }}
files: dist/*
fail_on_unmatched_files: true
generate_release_notes: true
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}