Skip to content

ci: fix ci/cd pipeline #5

ci: fix ci/cd pipeline

ci: fix ci/cd pipeline #5

Workflow file for this run

name: release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build:
name: build-${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bin_name: errat
archive_ext: tar.gz
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
bin_name: errat
archive_ext: tar.gz
use_cross: true
- os: macos-13
target: x86_64-apple-darwin
bin_name: errat
archive_ext: tar.gz
use_cross: false
- os: macos-14
target: aarch64-apple-darwin
bin_name: errat
archive_ext: tar.gz
use_cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
bin_name: errat.exe
archive_ext: zip
use_cross: false
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Setup cross
if: ${{ matrix.use_cross }}
uses: taiki-e/setup-cross@v1
- name: Build (cross)
if: ${{ matrix.use_cross }}
run: cross build --release --target ${{ matrix.target }}
- name: Build
if: ${{ !matrix.use_cross }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: ${{ matrix.archive_ext == 'tar.gz' }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME}"
dist="dist"
mkdir -p "${dist}"
bin="target/${{ matrix.target }}/release/${{ matrix.bin_name }}"
pkg="errat-${version}-${{ matrix.target }}"
stage="${pkg}"
mkdir -p "${stage}"
cp "${bin}" "${stage}/"
cp README.md README.zh-CN.md LICENSE "${stage}/"
tar -czf "${dist}/${pkg}.tar.gz" "${stage}"
- name: Sha256 (unix)
if: ${{ matrix.archive_ext == 'tar.gz' }}
shell: bash
run: |
set -euo pipefail
file="dist/errat-${GITHUB_REF_NAME}-${{ matrix.target }}.tar.gz"
python - <<'PY' "$file"
import hashlib, pathlib, sys
p = pathlib.Path(sys.argv[1])
h = hashlib.sha256(p.read_bytes()).hexdigest()
out = p.with_suffix(p.suffix + ".sha256")
out.write_text(f"{h} {p.name}\n")
PY
- name: Package (windows)
if: ${{ matrix.archive_ext == 'zip' }}
shell: pwsh
run: |
$version = "${{ github.ref_name }}"
$dist = "dist"
New-Item -ItemType Directory -Force -Path $dist | Out-Null
$bin = "target\${{ matrix.target }}\release\${{ matrix.bin_name }}"
$pkg = "errat-$version-${{ matrix.target }}"
$stage = $pkg
New-Item -ItemType Directory -Force -Path $stage | Out-Null
Copy-Item $bin $stage\
Copy-Item README.md, README.zh-CN.md, LICENSE $stage\
$zip = "$dist\$pkg.zip"
Compress-Archive -Path $stage\* -DestinationPath $zip -Force
$hash = (Get-FileHash $zip -Algorithm SHA256).Hash.ToLower()
$sha = "$zip.sha256"
"$hash $(Split-Path $zip -Leaf)" | Out-File -Encoding ascii $sha
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: errat-${{ matrix.target }}
path: dist/*
release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
path: dist
- name: Publish release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: dist/**/*