name: Build on Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get the release version from the tag
if: env.VERSION == ''
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Show the version
run: |
echo "version is: $VERSION"
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create $VERSION --draft --verify-tag --title $VERSION
outputs:
version: ${{ env.VERSION }}
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs: ["create-release"]
timeout-minutes: 10
env:
CARGO: cargo
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Install Linux cross-compilation tools
if: matrix.os == 'ubuntu-latest' && matrix.target != 'x86_64-unknown-linux-gnu'
run: |
if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
cargo install cross
echo CARGO=cross >> $GITHUB_ENV
fi
- name: Build
run: $CARGO build --release --target ${{ matrix.target }}
- name: Prepare artifact
shell: bash
run: |
VERSION=${{ needs.create-release.outputs.version }}
BIN=deindent-$VERSION-${{ matrix.target }}
echo VERSION=$VERSION >> $GITHUB_ENV
echo BIN=$BIN >> $GITHUB_ENV
TARGET_DIR="target/${{ matrix.target }}/release"
mv "$TARGET_DIR/deindent" "$BIN"
- name: Upload release archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh release upload "$VERSION" "$BIN"
finalize-release:
name: finalize-release
runs-on: ubuntu-latest
needs: ["create-release", "build"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Remove draft status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh release edit ${{ needs.create-release.outputs.version }} --draft=false