Build typst-package-check #35
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 typst-package-check | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: The branch, tag or SHA in https://github.com/typst/package-check. | |
| default: main | |
| type: string | |
| release: | |
| description: Whether to publish artifacts in a new release. | |
| default: false | |
| type: boolean | |
| pull_request: | |
| paths: | |
| - .github/workflows/package-check.yaml | |
| # The following lines are based on GitHub docs, because typst/package-check uses nix and docker. | |
| # https://docs.github.com/en/actions/tutorials/build-and-test-code/rust | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.target }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| env: | |
| INPUT_REF: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || 'main' }} | |
| INPUT_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.release || false }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-musl | |
| cargo: cross | |
| - target: x86_64-pc-windows-msvc | |
| cargo: cargo xwin | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| repository: typst/package-check | |
| ref: ${{ env.INPUT_REF }} | |
| - uses: actions/checkout@v6 | |
| with: | |
| path: dev-builds | |
| - name: Report the revision | |
| shell: bash | |
| id: report | |
| run: | | |
| set -euxo pipefail | |
| revision=$(python dev-builds/scripts/get_revision.py) | |
| echo "Revision: $revision" | |
| echo "revision=$revision" >> "$GITHUB_OUTPUT" | |
| echo "Revision: \`$revision\`." >> "$GITHUB_STEP_SUMMARY" | |
| - run: rustup target add ${{ matrix.target }} | |
| - name: Cache cargo xwin | |
| if: ${{ matrix.cargo == 'cargo xwin' }} | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cache/cargo-xwin | |
| key: | | |
| ${{ runner.os }}-cargo-xwin-${{ matrix.target }} | |
| - name: Setup cargo xwin | |
| if: ${{ matrix.cargo == 'cargo xwin' }} | |
| run: | | |
| set -euxo pipefail | |
| # Install llvm-tools for assembly dependencies. | |
| # Otherwise, the following error will occur. | |
| # error: failed to run custom build command for `link-cplusplus v1.0.12` | |
| # --- stderr | |
| # error occurred in cc-rs: failed to find tool "llvm-lib": No such file or directory (os error 2) | |
| # (link-cplusplus is used by cxx) | |
| rustup component add llvm-tools | |
| # Install clang 19 for cxx. | |
| # The default 18 cannot compile cxx 1.0.194, which is required by typst-package-check through wasm-opt(build). | |
| sudo apt update | |
| sudo apt install clang-19 | |
| # Note: The priority of the default clang 18 is 100. | |
| sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 120 | |
| # Display that clang 19 is the best version now. | |
| update-alternatives --display clang | |
| pip install cargo-xwin | |
| - name: Download xwin (MSVC CRT and Windows SDK) | |
| if: ${{ matrix.cargo == 'cargo xwin' }} | |
| run: | | |
| cargo xwin cache xwin | |
| - name: Setup cross | |
| if: ${{ matrix.cargo == 'cross' }} | |
| run: | | |
| curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash | |
| cargo binstall cross --force # Even if cached, reinstall to set PATH properly. | |
| - name: Vendor openssl for musl | |
| if: ${{ endsWith(matrix.target, '-musl') }} | |
| run: | | |
| cat <<EOF >> Cargo.toml | |
| openssl = { version = "^0.10", features = ["vendored"] } | |
| EOF | |
| - uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ matrix.target }}-typst-package-check-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-${{ matrix.target }}-typst-package-check | |
| ${{ runner.os }}-cargo-${{ matrix.target }} | |
| - name: Build | |
| run: | | |
| ${{ matrix.cargo }} build --release --target ${{ matrix.target }} | |
| - name: Prepare to upload | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| directory=typst-package-check-${{ matrix.target }} | |
| mkdir $directory | |
| cp README.md LICENSE* $directory | |
| if [ -f target/${{ matrix.target }}/release/typst-package-check.exe ]; then | |
| cp target/${{ matrix.target }}/release/typst-package-check.exe $directory | |
| 7z a -r $directory.zip $directory | |
| else | |
| cp target/${{ matrix.target }}/release/typst-package-check $directory | |
| tar cJf $directory.tar.xz $directory | |
| fi | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| path: "typst-package-check-${{ matrix.target }}.*" | |
| archive: false | |
| - uses: softprops/action-gh-release@v2 | |
| if: ${{ env.INPUT_RELEASE == 'true' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.report.outputs.revision }} | |
| name: ${{ steps.report.outputs.revision }} | |
| draft: true | |
| prerelease: false # can be edited in the Web UI | |
| files: | | |
| typst-package-check-${{ matrix.target }}.* | |
| - name: Report the release | |
| if: ${{ env.INPUT_RELEASE == 'true' }} | |
| run: | | |
| echo "Please publish the [draft release](https://github.com/typst-community/dev-builds/releases)." >> "$GITHUB_STEP_SUMMARY" |