Build and release #22
This file contains hidden or 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: 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| persist-credentials: false | |
| - 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@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| 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 | |
| env: | |
| STEPS_RELEASE_CHECK_OUTPUTS_RELEASE_EXISTS: ${{ steps.release_check.outputs.release_exists }} | |
| 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| persist-credentials: false | |
| - 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@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 | |
| - 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@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| persist-credentials: false | |
| - name: Download linux x64 artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: typst-webservice-linux-x64 | |
| path: dist | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push docker image | |
| uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0 | |
| 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@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: typst-webservice-linux-x64 | |
| path: dist | |
| - name: Download linux arm64 artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: typst-webservice-linux-arm64 | |
| path: dist | |
| - name: Download macos x64 artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: typst-webservice-macos-x64 | |
| path: dist | |
| - name: Download macos arm64 artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: typst-webservice-macos-arm64 | |
| path: dist | |
| - name: Create release | |
| uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0 | |
| 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 |