Skip to content

Build and release

Build and release #21

Workflow file for this run

name: Build and release
on:
workflow_run:
workflows:
- Check
types:
- completed
branches:
- main
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
check-version:
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
release_exists: ${{ steps.release_check.outputs.release_exists }}
should_run: ${{ steps.decide.outputs.should_run }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Read version
id: version
run: |
version=$(awk -F' *= *' '$1 == "version" { gsub(/"/, "", $2); print $2; exit }' Cargo.toml)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Check release existence
id: release_check
uses: actions/github-script@v7
with:
script: |
const tag = `${{ steps.version.outputs.version }}`;
try {
await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag,
});
core.setOutput('release_exists', 'true');
} catch (error) {
if (error.status === 404) {
core.setOutput('release_exists', 'false');
} else {
throw error;
}
}
- name: Decide run
id: decide
run: |
if [[ "${{ steps.release_check.outputs.release_exists }}" == "false" ]]; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
else
echo "should_run=false" >> "$GITHUB_OUTPUT"
fi
build:
needs: check-version
if: needs.check-version.outputs.should_run == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-musl
artifact: typst-webservice-linux-x64
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
artifact: typst-webservice-linux-arm64
- os: macos-15-intel
target: x86_64-apple-darwin
artifact: typst-webservice-macos-x64
- os: macos-15
target: aarch64-apple-darwin
artifact: typst-webservice-macos-arm64
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Optionally install musl-tools
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'
run: sudo apt-get install -y musl-tools
- uses: Swatinem/rust-cache@v2
- name: Build
env:
CC_aarch64_unknown_linux_musl: ${{ matrix.target == 'aarch64-unknown-linux-musl' && 'musl-gcc' || '' }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/typst-webservice dist/${{ matrix.artifact }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: dist/${{ matrix.artifact }}
docker:
needs:
- check-version
- build
if: needs.check-version.outputs.should_run == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: Download linux x64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-linux-x64
path: dist
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
file: Dockerfile
push: true
build-args: "version=${{ needs.check-version.outputs.version }}"
context: dist
tags: "ghcr.io/tweedegolf/typst-webservice:${{ needs.check-version.outputs.version }},ghcr.io/tweedegolf/typst-webservice:latest"
release:
needs:
- check-version
- build
if: needs.check-version.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- name: Download linux x64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-linux-x64
path: dist
- name: Download linux arm64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-linux-arm64
path: dist
- name: Download macos x64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-macos-x64
path: dist
- name: Download macos arm64 artifact
uses: actions/download-artifact@v4
with:
name: typst-webservice-macos-arm64
path: dist
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-version.outputs.version }}
name: Version ${{ needs.check-version.outputs.version }}
generate_release_notes: true
files: |
dist/typst-webservice-linux-x64
dist/typst-webservice-linux-arm64
dist/typst-webservice-macos-x64
dist/typst-webservice-macos-arm64