Publish Typst Package #2
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
| # This workflow publishes a package to the Typst Package Registry. | |
| name: Publish Typst Package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| packages: | |
| description: Packages to publish | |
| required: true | |
| default: "all" | |
| type: string | |
| source: | |
| # the repository to which to push the release version | |
| # usually a fork of typst/packages (https://github.com/typst/packages/) | |
| # that you have push privileges to | |
| description: Source repository to publish the package | |
| required: true | |
| default: "Myriad-Dreamin/packages" | |
| type: string | |
| # the path within that repo where the "<name>/<version>" directory should be put | |
| # for the Typst package registry, keep this as is | |
| destination: | |
| description: Destination path to install the package | |
| required: true | |
| default: "packages/preview" | |
| type: string | |
| dry-run: | |
| description: Dry run the publish process | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| plan: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up typship | |
| run: cargo install --git https://github.com/Myriad-Dreamin/typship --branch ci typship | |
| # sure would be cool if github gave us proper conditionals... | |
| # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible | |
| # functionality based on whether this is a pull_request, and whether it's from a fork. | |
| # (PRs run on the *source* but secrets are usually on the *target* -- that's *good* | |
| # but also really annoying to build CI around when it needs secrets to work right.) | |
| - id: plan | |
| run: | | |
| typship ${{ (!github.event.pull_request && format('host --tag={0}', github.ref_name)) || 'host' }} --packages=${{ inputs.packages }} --output-format=json > plan-typship-manifest.json | |
| echo "typship ran successfully" | |
| cat plan-typship-manifest.json | |
| echo "manifest=$(jq -c "." plan-typship-manifest.json)" >> "$GITHUB_OUTPUT" | |
| - name: "Upload dist-manifest.json" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: artifacts-plan-typship-manifest | |
| path: plan-typship-manifest.json | |
| publish: | |
| name: publish (${{ join(matrix.targets, ', ') }}) | |
| # Let the initial task tell us to not run (currently very blunt) | |
| needs: | |
| - plan | |
| if: ${{ inputs.dry-run == false && fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} | |
| strategy: | |
| fail-fast: false | |
| # Target platforms/runners are computed by dist in create-release. | |
| # Each member of the matrix has the following arguments: | |
| # | |
| # - runner: the github runner | |
| # - dist-args: cli flags to pass to dist | |
| # - install-dist: expression to run to install dist on the runner | |
| # | |
| # Typically there will be: | |
| # - 1 "global" task that builds universal installers | |
| # - N "local" tasks that build each platform's binaries and platform-specific installers | |
| matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} | |
| runs-on: ${{ matrix.runner }} | |
| container: ${{ matrix.container && matrix.container.image || null }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: enable windows longpaths | |
| run: | | |
| git config --global core.longpaths true | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| submodules: recursive | |
| - name: Pull packages | |
| uses: actions/checkout@v4 | |
| with: | |
| # Repository name with owner. For example, actions/checkout | |
| # Default: ${{ github.repository }} | |
| repository: ${{ inputs.source }} | |
| # The token to use to pull the repository, needs write access to the repository. | |
| token: ${{ secrets.REGISTRY_TOKEN }} | |
| # Relative path under $GITHUB_WORKSPACE to place the repository | |
| path: "typst-packages" | |
| - name: Detect existing package | |
| id: detect-existing-package | |
| run: | | |
| if [ -d "typst-packages/${{ inputs.destination }}/${{ matrix.package.name }}/${{ matrix.package.version }}" ]; then | |
| echo "package already exists" | |
| echo "package-exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "package does not exist" | |
| echo "package-exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Put package to @preview namespace | |
| if: steps.detect-existing-package.outputs.package-exists == 'false' | |
| run: | | |
| mkdir -p typst-packages/${{ inputs.destination }}/${{ matrix.package.name }} | |
| mv ${{ matrix.package.source }} typst-packages/${{ inputs.destination }}/${{ matrix.package.name }}/${{ matrix.package.version }} | |
| - name: Upload built package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: preview-${{ matrix.package.name }}-${{ matrix.package.version }} | |
| path: typst-packages/${{ inputs.destination }}/${{ matrix.package.name }}/${{ matrix.package.version }} | |
| - name: Make PR | |
| if: steps.detect-existing-package.outputs.package-exists == 'false' | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.REGISTRY_TOKEN }} | |
| path: typst-packages | |
| title: "@preview/{{ matrix.package.name }} {{ matrix.package.version }}" | |
| body: | | |
| I am submitting | |
| * [ ] a new package | |
| * [x] an update for a package | |
| Description: New release. | |
| I have read and followed the submission guidelines and, in particular, I | |
| * [x] selected [a name](https://github.com/typst/packages/blob/main/docs/manifest.md#naming-rules) that isn't the most obvious or canonical name for what the package does | |
| * [x] added a [`typst.toml`](https://github.com/typst/packages/blob/main/docs/manifest.md#package-metadata) file with all required keys | |
| * [x] added a [`README.md`](https://github.com/typst/packages/blob/main/docs/documentation.md) with documentation for my package | |
| * [x] have chosen [a license](https://github.com/typst/packages/blob/main/docs/licensing.md) and added a `LICENSE` file or linked one in my `README.md` | |
| * [x] tested my package locally on my system and it worked | |
| * [x] [`exclude`d](https://github.com/typst/packages/blob/main/docs/tips.md#what-to-commit-what-to-exclude) PDFs or README images, if any, but not the LICENSE | |
| * [x] ensured that my package is licensed such that users can use and distribute the contents of its template directory without restriction, after modifying them through normal use. | |
| commit-message: "build: bump @preview/{{ matrix.package.name }} to {{ matrix.package.version }}" | |
| branch: preview/{{ matrix.package.name }}/v{{ matrix.package.version }} | |
| base: "main" | |
| draft: false |