Skip to content

Commit b806311

Browse files
authored
Merge pull request typst-community#11 from SillyFreak/release-workflow
Add release workflow
2 parents 41d6e49 + 7c2c349 commit b806311

File tree

5 files changed

+144
-72
lines changed

5 files changed

+144
-72
lines changed

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Package and push to registry repo
2+
on:
3+
push:
4+
tags: [ v* ]
5+
6+
env:
7+
# the repository to which to push the release version
8+
# usually a fork of typst/packages (https://github.com/typst/packages/)
9+
# that you have push privileges to
10+
REGISTRY_REPO: author/typst-packages
11+
# the path within that repo where the "<name>/<version>" directory should be put
12+
# for the Typst package registry, keep this as is
13+
PATH_PREFIX: packages/preview
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Probe runner package cache
23+
uses: awalsh128/cache-apt-pkgs-action@v1
24+
with:
25+
packages: cargo
26+
version: 1.0
27+
28+
- name: Install just from crates.io
29+
uses: baptiste0928/cargo-install@v3
30+
with:
31+
crate: just
32+
33+
- name: Setup typst
34+
uses: typst-community/setup-typst@v3
35+
with:
36+
typst-version: latest
37+
38+
- name: Determine and check package metadata
39+
run: |
40+
. scripts/setup
41+
echo "PKG_NAME=${PKG_PREFIX}" >> "${GITHUB_ENV}"
42+
echo "PKG_VERSION=${VERSION}" >> "${GITHUB_ENV}"
43+
44+
if [[ "${GITHUB_REF_NAME}" != "v${VERSION}" ]]; then
45+
echo "package version ${VERSION} does not match release tag ${GITHUB_REF_NAME}" >&2
46+
exit 1
47+
fi
48+
49+
- name: Build package
50+
run: |
51+
just doc
52+
just package out
53+
54+
- name: Checkout package registry
55+
uses: actions/checkout@v4
56+
with:
57+
repository: ${{ env.REGISTRY_REPO }}
58+
token: ${{ secrets.REGISTRY_TOKEN }}
59+
path: typst-packages
60+
61+
- name: Release package
62+
run: |
63+
mkdir -p "typst-packages/${{ env.PATH_PREFIX }}/$PKG_NAME"
64+
mv "out/${PKG_NAME}/${PKG_VERSION}" "typst-packages/${{ env.PATH_PREFIX }}/${PKG_NAME}"
65+
rmdir "out/${PKG_NAME}"
66+
rmdir out
67+
68+
GIT_USER_NAME="$(git log -1 --pretty=format:'%an')"
69+
GIT_USER_EMAIL="$(git log -1 --pretty=format:'%ae')"
70+
71+
cd typst-packages
72+
git config user.name "${GIT_USER_NAME}"
73+
git config user.email "${GIT_USER_EMAIL}"
74+
git checkout -b "${PKG_NAME}-${PKG_VERSION}"
75+
git add .
76+
git commit -m "${PKG_NAME}:${PKG_VERSION}"
77+
git push --set-upstream origin "${PKG_NAME}-${PKG_VERSION}"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ A short description about the project and/or client.
1313
- See also the [typst/packages README](https://github.com/typst/packages/?tab=readme-ov-file#package-format)
1414
- [ ] Adapt Repository URLs in `CHANGELOG.md`
1515
- Consider only committing that file with your first release, or removing the "Initial Release" part in the beginning
16+
- [ ] Adapt or deactivate the release workflow in `.github/workflows/release.yml`
17+
- to deactivate it, delete that file or remove/comment out lines 2-4 (`on:` and following)
18+
- to use the workflow
19+
- [ ] check the values under `env:`, particularly `REGISTRY_REPO`
20+
- [ ] if you don't have one, [create a fine-grained personal access token](https://github.com/settings/tokens?type=beta) with [only Contents permission](https://stackoverflow.com/a/75116350/371191) for the `REGISTRY_REPO`
21+
- [ ] on this repo, create a secret `REGISTRY_TOKEN` (at `https://github.com/[user]/[repo]/settings/secrets/actions`) that contains the so created token
22+
23+
if configured correctly, whenever you create a tag `v...`, your package will be pushed onto a branch on the `REGISTRY_REPO`, from which you can then create a pull request against [typst/packages](https://github.com/typst/packages/)
1624
- [ ] remove/replace the example test case
1725
- [ ] (add your actual code, docs and tests)
1826
- [ ] remove this section from the README

scripts/package

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ set -eu
44
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package
55
# licensed under Apache License 2.0
66

7+
. "$(dirname "${BASH_SOURCE[0]}")/setup"
8+
9+
if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then
10+
echo "package TARGET"
11+
echo ""
12+
echo "Packages all relevant files into a directory named '<name>/<version>'"
13+
echo "at TARGET. If TARGET is set to @local or @preview, the local Typst package"
14+
echo "directory will be used so that the package gets installed for local use."
15+
echo "The name and version are read from 'typst.toml' in the project root."
16+
echo ""
17+
echo "Local package prefix: $DATA_DIR/typst/package/local"
18+
echo "Local preview package prefix: $DATA_DIR/typst/package/preview"
19+
exit 1
20+
fi
21+
22+
TARGET="$(resolve-target "${1:?Missing target path, @local or @preview}")"
23+
echo "Install dir: $TARGET"
24+
725
# ignore rules
826
readarray -t ignores < <(grep -v '^#' .typstignore | grep '[^[:blank:]]')
927

@@ -49,49 +67,6 @@ function enumerate {
4967
readarray -t files < <(enumerate ".")
5068
# declare -p files >&2
5169

52-
# Local package directories per platform
53-
if [[ "$OSTYPE" == "linux"* ]]; then
54-
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
55-
elif [[ "$OSTYPE" == "darwin"* ]]; then
56-
DATA_DIR="$HOME/Library/Application Support"
57-
else
58-
DATA_DIR="${APPDATA}"
59-
fi
60-
61-
if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then
62-
echo "package TARGET"
63-
echo ""
64-
echo "Packages all relevant files into a directory named '<name>/<version>'"
65-
echo "at TARGET. If TARGET is set to @local or @preview, the local Typst package"
66-
echo "directory will be used so that the package gets installed for local use."
67-
echo "The name and version are read from 'typst.toml' in the project root."
68-
echo ""
69-
echo "Local package prefix: $DATA_DIR/typst/package/local"
70-
echo "Local preview package prefix: $DATA_DIR/typst/package/preview"
71-
exit 1
72-
fi
73-
74-
function read-toml() {
75-
local file="$1"
76-
local key="$2"
77-
# Read a key value pair in the format: <key> = "<value>"
78-
# stripping surrounding quotes.
79-
perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file"
80-
}
81-
82-
ROOT="$(cd "$(dirname "$0")"; pwd -P)/.." # macOS has no realpath
83-
TARGET="${1:?Missing target path, @local or @preview}"
84-
PKG_PREFIX="$(read-toml "$ROOT/typst.toml" "name")"
85-
VERSION="$(read-toml "$ROOT/typst.toml" "version")"
86-
87-
if [[ "$TARGET" == "@local" ]]; then
88-
TARGET="${DATA_DIR}/typst/packages/local"
89-
echo "Install dir: $TARGET"
90-
elif [[ "$TARGET" == "@preview" ]]; then
91-
TARGET="${DATA_DIR}/typst/packages/preview"
92-
echo "Install dir: $TARGET"
93-
fi
94-
9570
TMP="$(mktemp -d)"
9671

9772
for f in "${files[@]}"; do

scripts/setup

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# source this script to prepare some common environment variables
2+
3+
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package
4+
# licensed under Apache License 2.0
5+
6+
# Local package directories per platform
7+
if [[ "$OSTYPE" == "linux"* ]]; then
8+
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
9+
elif [[ "$OSTYPE" == "darwin"* ]]; then
10+
DATA_DIR="$HOME/Library/Application Support"
11+
else
12+
DATA_DIR="${APPDATA}"
13+
fi
14+
15+
function read-toml() {
16+
local file="$1"
17+
local key="$2"
18+
# Read a key value pair in the format: <key> = "<value>"
19+
# stripping surrounding quotes.
20+
perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file"
21+
}
22+
23+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)/.." # macOS has no realpath
24+
PKG_PREFIX="$(read-toml "$ROOT/typst.toml" "name")"
25+
VERSION="$(read-toml "$ROOT/typst.toml" "version")"
26+
27+
function resolve-target() {
28+
local target="$1"
29+
30+
if [[ "$target" == "@local" ]]; then
31+
echo "${DATA_DIR}/typst/packages/local"
32+
elif [[ "$target" == "@preview" ]]; then
33+
echo "${DATA_DIR}/typst/packages/preview"
34+
else
35+
echo "$target"
36+
fi
37+
}

scripts/uninstall

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@ set -eu
44
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package
55
# licensed under Apache License 2.0
66

7-
# Local package directories per platform
8-
if [[ "$OSTYPE" == "linux"* ]]; then
9-
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
10-
elif [[ "$OSTYPE" == "darwin"* ]]; then
11-
DATA_DIR="$HOME/Library/Application Support"
12-
else
13-
DATA_DIR="${APPDATA}"
14-
fi
7+
. "$(dirname "${BASH_SOURCE[0]}")/setup"
158

169
if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then
1710
echo "uninstall TARGET"
1811
echo ""
19-
echo "removes the package installed into a directory named '<name>/<version>'"
12+
echo "Removes the package installed into a directory named '<name>/<version>'"
2013
echo "at TARGET. If TARGET is set to @local or @preview, the local Typst package"
2114
echo "directory will be used so that the package gets installed for local use."
2215
echo "The name and version are read from 'typst.toml' in the project root."
@@ -26,26 +19,8 @@ if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then
2619
exit 1
2720
fi
2821

29-
function read-toml() {
30-
local file="$1"
31-
local key="$2"
32-
# Read a key value pair in the format: <key> = "<value>"
33-
# stripping surrounding quotes.
34-
perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file"
35-
}
36-
37-
ROOT="$(cd "$(dirname "$0")"; pwd -P)/.." # macOS has no realpath
38-
TARGET="${1:?Missing target path, @local or @preview}"
39-
PKG_PREFIX="$(read-toml "$ROOT/typst.toml" "name")"
40-
VERSION="$(read-toml "$ROOT/typst.toml" "version")"
41-
42-
if [[ "$TARGET" == "@local" ]]; then
43-
TARGET="${DATA_DIR}/typst/packages/local/"
44-
echo "Install dir: $TARGET"
45-
elif [[ "$TARGET" == "@preview" ]]; then
46-
TARGET="${DATA_DIR}/typst/packages/preview/"
47-
echo "Install dir: $TARGET"
48-
fi
22+
TARGET="$(resolve-target "${1:?Missing target path, @local or @preview}")"
23+
echo "Install dir: $TARGET"
4924

5025
TARGET="${TARGET:?}/${PKG_PREFIX:?}/${VERSION:?}"
5126
echo "Package to uninstall: $TARGET"

0 commit comments

Comments
 (0)