-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache installation & switch to Node.js (#12)
1. Add caching support. If the typst cache dir exists, don't download and extract it again; just use the cached dir. 2. Add support for ARM64 runners. This is important with self-hosted GitHub Actions runners that run on ARM64 images like those from https://buildjet.com/for-github-actions or others. 3. Add a GitHub Action to test and make sure that PRs and main commits _actually work_. Basically it just runs the action and then `typst --version` and `typst compile test.typ` to make sure it works. https://github.com/jcbhmr/setup-typst/actions 4. Use the Node.js runtime instead of a composite action. This was needed to get tight integration with the existing GitHub Actions SDK provided for Node.js-based Actions. 5. Use Vite to bundle the Node.js code on release into a self-contained JS file. GitHub Actions Node.js runtime doesn't do `npm install && node main.js`, it just does `node main.js`. Therefore, you need to bundle all your dependencies. 6. Use post-release tag mutation to build & commit the `dist/main.js` bundled Vite artifact on each new release. 7. Improve readme to describe inputs and outputs a bit more thoroughly. 8. Bump the version used in the readme from v2 (current version) to v3 9. Add a GitHub Action to automagically tag new releases with a major tag (vN) in addition to the specific tag (vN.N.N).
- Loading branch information
Showing
11 changed files
with
1,511 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: publish-action | ||
on: | ||
release: | ||
types: released | ||
concurrency: ${{ github.workflow }} | ||
jobs: | ||
publish-action: | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: npm | ||
- run: npm ci | ||
- run: npm run build | ||
- run: rm -rf node_modules | ||
- uses: actions4git/setup-git@v1 | ||
- run: git add -Af && git commit -m 'npm run build' | ||
- run: git tag -f "$TAG" && git push -f origin "$TAG" | ||
env: | ||
TAG: ${{ github.event.release.tag_name }} | ||
- uses: actions/publish-action@v0.2.2 | ||
with: | ||
source-tag: ${{ github.event.release.tag_name }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Test action | ||
on: | ||
push: | ||
branches: "main" | ||
paths-ignore: | ||
- .gitignore | ||
- README.md | ||
- LICENSE | ||
- .github/** | ||
- "!.github/workflows/test-action.yml" | ||
pull_request: | ||
paths-ignore: | ||
- .gitignore | ||
- README.md | ||
- LICENSE | ||
- .github/** | ||
- "!.github/workflows/test-action.yml" | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
jobs: | ||
test-action: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: npm | ||
- run: npm ci | ||
- run: npm run build | ||
- uses: ./ | ||
- run: typst --version | ||
- run: typst compile test.typ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Ignore test artifact | ||
test.pdf | ||
|
||
#region https://github.com/github/gitignore/blob/main/Node.gitignore | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
#endregion |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,67 @@ | ||
# Setup Typst | ||
|
||
A cross-OS action for installing Typst. | ||
📑 Install Typst for use in GitHub Actions | ||
|
||
## Inputs | ||
<table align=center><td> | ||
|
||
### `token` | ||
|
||
The token used to authenticate when fetching Typst distributions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ||
```yml | ||
- uses: yusancky/setup-typst@v3 | ||
- run: typst compile paper.typ paper.pdf | ||
``` | ||
### `version` | ||
</table> | ||
Exact version of Typst to use. Input `latest` if you want to use latest version of Typst. | ||
📝 Installs [Typst] for GitHub Actions \ | ||
⚡ Caches installation files | ||
> **Warning** | ||
> Setup Typst v2.0 does not support Typst v0.1.0 or v0.2.0 (actually they were supported on Windows). If you want to use an old version on Linux or macOS, please use [v1](https://github.com/yusancky/setup-typst/tree/v1). | ||
## Usage | ||
## Example usage | ||
![GitHub Actions](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub+Actions&color=2088FF&logo=GitHub+Actions&logoColor=FFFFFF&label=) | ||
![GitHub](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub&color=181717&logo=GitHub&logoColor=FFFFFF&label=) | ||
```yaml | ||
- uses: yusancky/setup-typst@v2 | ||
id: setup-typst | ||
with: | ||
version: 'v0.5.0' | ||
- run: typst compile file.typ | ||
```yml | ||
name: Render paper.pdf | ||
on: push | ||
jobs: | ||
render-paper: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: yusancky/setup-typst@v3 | ||
# Now Typst is installed! | ||
- run: typst compile paper.typ paper.pdf | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: paper | ||
path: paper.pdf | ||
``` | ||
You can also use the additional uses given in [Usage](https://github.com/typst/typst#usage) in the Typst documentation. | ||
### Inputs | ||
- **`typst-token`:** The GitHub token to use when pulling versions from | ||
[typst/typst]. By default this should cover all cases. You shouldn't have to | ||
touch this setting. | ||
|
||
- **`typst-version`:** Which version of `typst` to install. This can be an exact | ||
version like `0.10.0` or a semver range like `0.10` or `0.x`. You can also | ||
specify `latest` to always use the latest version. The default is `latest`. | ||
|
||
### Outputs | ||
|
||
- **`typst-version`:** The version of `typst` that was installed. This will be | ||
something like `0.10.0` or similar. | ||
|
||
- **`cache-hit`:** Whether or not Typst was restored from the runner's cache or | ||
download anew. | ||
|
||
## Development | ||
|
||
![Node.js](https://img.shields.io/static/v1?style=for-the-badge&message=Node.js&color=339933&logo=Node.js&logoColor=FFFFFF&label=) | ||
|
||
**How do I test my changes?** | ||
|
||
Open a Draft Pull Request and some magic GitHub Actions will run to test the | ||
action. | ||
|
||
[typst]: https://typst.app/ | ||
[typst/typst]: https://github.com/typst/typst |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,34 @@ | ||
name: Setup Typst | ||
author: yusancky | ||
description: A cross-OS action for installing Typst | ||
description: 📑 Install Typst for use in GitHub Actions | ||
|
||
inputs: | ||
token: | ||
description: The token used to authenticate when fetching Typst distributions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }} | ||
version: | ||
description: Exact version of Typst to use. | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Configure filenames | ||
run: | | ||
if [ "$RUNNER_OS" == 'Linux' ]; then | ||
echo "typst_asset_name=unknown-linux-musl" >> $GITHUB_ENV | ||
echo "typst_asset_zip_name=tar.xz" >> $GITHUB_ENV | ||
elif [ "$RUNNER_OS" == 'Windows' ]; then | ||
echo "typst_asset_name=pc-windows-msvc" >> $GITHUB_ENV | ||
echo "typst_asset_zip_name=zip" >> $GITHUB_ENV | ||
else | ||
echo "typst_asset_name=apple-darwin" >> $GITHUB_ENV | ||
echo "typst_asset_zip_name=tar.xz" >> $GITHUB_ENV | ||
fi | ||
shell: bash | ||
|
||
- name: Download release if latest | ||
uses: robinraju/release-downloader@v1.8 | ||
with: | ||
repository: typst/typst | ||
latest: true | ||
fileName: ${{ format('typst-x86_64-{0}.{1}', env.typst_asset_name, env.typst_asset_zip_name) }} | ||
token: ${{ inputs.token }} | ||
if: inputs.version == 'latest' | ||
- name: Download release | ||
uses: robinraju/release-downloader@v1.8 | ||
with: | ||
repository: typst/typst | ||
tag: ${{ inputs.version }} | ||
fileName: ${{ format('typst-x86_64-{0}.{1}', env.typst_asset_name, env.typst_asset_zip_name) }} | ||
token: ${{ inputs.token }} | ||
if: inputs.version != 'latest' | ||
|
||
- name: Unzip Typst (Linux, macOS) | ||
run: | | ||
sudo mkdir /usr/local/typst | ||
${{ format('sudo tar -xf typst-x86_64-{0}.{1} -C /usr/local/typst/', env.typst_asset_name, env.typst_asset_zip_name) }} | ||
shell: bash | ||
if: runner.os == 'Linux' || runner.os == 'macOS' | ||
- name: Unzip Typst (Windows) | ||
run: ${{ format('7z x typst-x86_64-{0}.{1} -oc:\typst', env.typst_asset_name, env.typst_asset_zip_name) }} | ||
shell: bash | ||
if: runner.os == 'Windows' | ||
branding: | ||
icon: terminal | ||
color: white | ||
|
||
- name: Delete zip | ||
run: ${{ format('rm -f typst-x86_64-{0}.{1}', env.typst_asset_name, env.typst_asset_zip_name) }} | ||
shell: bash | ||
inputs: | ||
typst-token: | ||
description: > | ||
The GitHub token to use when pulling versions from typst/typst. By default | ||
this should cover all cases. You shouldn't have to touch this setting. | ||
default: | ||
${{ github.server_url == 'https://github.com' && github.token || '' }} | ||
typst-version: | ||
description: > | ||
Which version of 'typst' to install. This can be an exact version like | ||
'0.10.0' or a semver range like '0.10' or '0.x'. You can also specify | ||
'latest' to always use the latest version. The default is 'latest'. | ||
default: latest | ||
|
||
- name: Add system path (Linux, macOS) | ||
run: ${{ format('echo "/usr/local/typst/typst-x86_64-{0}" >> $GITHUB_PATH', env.typst_asset_name) }} | ||
shell: bash | ||
if: runner.os == 'Linux' || runner.os == 'macOS' | ||
- name: Add system path (Windows) | ||
run: ${{ format('echo "c:\typst\typst-x86_64-{0}" >> $GITHUB_PATH', env.typst_asset_name) }} | ||
shell: bash | ||
if: runner.os == 'Windows' | ||
outputs: | ||
typst-version: | ||
description: > | ||
The version of 'typst' that was installed. This will be something like | ||
'0.10.0' or similar. | ||
cache-hit: | ||
description: > | ||
Whether or not Typst was restored from the runner's cache or download | ||
anew. | ||
branding: | ||
color: orange | ||
icon: download | ||
runs: | ||
using: node20 | ||
main: dist/main.js |
Oops, something went wrong.