chore: Release #32
Workflow file for this run
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: CD | |
permissions: | |
contents: write | |
on: | |
push: | |
tags: [ 'v[0-9]+.[0-9]+.[0-9]*' ] | |
env: | |
CARGO_TERM_COLOR: always | |
RUST_BACKTRACE: full | |
RUSTFLAGS: -D warnings | |
jobs: | |
create-release: | |
name: Create release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
- uses: Swatinem/rust-cache@v1 | |
- name: Make sure it build | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release | |
- name: Create release | |
uses: taiki-e/create-gh-release-action@v1 | |
with: | |
branch: master|main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release-artifacts: | |
name: Build and release artifact for ${{ matrix.target }} | |
needs: | |
- create-release | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-musl | |
- target: aarch64-unknown-linux-musl | |
- target: x86_64-unknown-linux-gnu | |
- target: aarch64-unknown-linux-gnu | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
cross: false | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
cross: false | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
cross: false | |
runs-on: ${{ matrix.os || 'ubuntu-latest' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install cargo-about | |
uses: baptiste0928/cargo-install@v1 | |
with: | |
crate: cargo-about | |
- uses: actions-rs/toolchain@v1 | |
with: | |
target: ${{ matrix.target }} | |
profile: minimal | |
toolchain: stable | |
override: true | |
- uses: Swatinem/rust-cache@v1 | |
- name: Prepare environment variables | |
shell: bash | |
run: | | |
set -euxo pipefail | |
if [[ "${GITHUB_REF:?}" != "refs/tags/"* ]]; then | |
echo "::error::GITHUB_REF should start with 'refs/tags/'" | |
exit 1 | |
fi | |
readonly tag="${GITHUB_REF#refs/tags/}" | |
echo "TAG=${tag}" >> "${GITHUB_ENV}" | |
echo "ARTIFACT_DIR=xq-${tag}-${{ matrix.target }}" >> "${GITHUB_ENV}" | |
if [[ "${{ matrix.target }}" == *"windiws-msvc" ]]; then | |
echo "BINARY_EXT=.exe" >> "${GITHUB_ENV}" | |
echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >> "${GITHUB_ENV}" | |
else | |
echo "BINARY_EXT=" >> "${GITHUB_ENV}" | |
fi | |
- name: Write about.html | |
shell: bash | |
run: cargo about generate about.hbs > about.html | |
- name: Build | |
uses: actions-rs/cargo@v1 | |
with: | |
use-cross: ${{ matrix.cross || true }} | |
command: build | |
args: --package xq --release --locked --target ${{ matrix.target }} | |
- name: Create artifact | |
shell: bash | |
run: | | |
set -euxo pipefail | |
readonly binary="target/${{ matrix.target }}/release/xq${BINARY_EXT}" | |
mkdir -p "${ARTIFACT_DIR}" | |
cp "about.html" "${ARTIFACT_DIR}/" | |
cp "${binary}" "${ARTIFACT_DIR}/" | |
cp "README.md" "${ARTIFACT_DIR}/" | |
cp "LICENSE" "${ARTIFACT_DIR}/" | |
if [[ "${{ matrix.target }}" == *"windiws-msvc" ]]; then | |
readonly artifact="${ARTIFACT_DIR}.zip" | |
7z a "${artifact}" "${ARTIFACT_DIR}" | |
else | |
readonly artifact="${ARTIFACT_DIR}.tar.gz" | |
tar cavf "${artifact}" "${ARTIFACT_DIR}" | |
fi | |
- uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
xq-*.tar.gz | |
xq-*.zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |