-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add release workflow and packaging script
adapted from https://github.com/typst-community/typst-package-template, which in turns is adapted from CeTZ
- Loading branch information
1 parent
584fbc5
commit c95942a
Showing
5 changed files
with
161 additions
and
10 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,77 @@ | ||
name: Package and push to registry repo | ||
on: | ||
push: | ||
tags: [ v* ] | ||
|
||
env: | ||
# 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 | ||
REGISTRY_REPO: wisp3rwind/typst-packages | ||
# the path within that repo where the "<name>/<version>" directory should be put | ||
# for the Typst package registry, keep this as is | ||
PATH_PREFIX: packages/preview | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
environment: release # grants access to the REGISTRY_TOKEN | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Probe runner package cache | ||
uses: awalsh128/cache-apt-pkgs-action@v1 | ||
with: | ||
packages: cargo | ||
version: 1.0 | ||
|
||
- name: Install just from crates.io | ||
uses: baptiste0928/cargo-install@v3 | ||
with: | ||
crate: just | ||
|
||
- name: Setup typst | ||
uses: typst-community/setup-typst@v3 | ||
with: | ||
typst-version: latest | ||
|
||
- name: Determine and check package metadata | ||
run: | | ||
. scripts/setup | ||
echo "PKG_NAME=${PKG_PREFIX}" >> "${GITHUB_ENV}" | ||
echo "PKG_VERSION=${VERSION}" >> "${GITHUB_ENV}" | ||
if [[ "${GITHUB_REF_NAME}" != "v${VERSION}" ]]; then | ||
echo "package version ${VERSION} does not match release tag ${GITHUB_REF_NAME}" >&2 | ||
exit 1 | ||
fi | ||
- name: Build package | ||
run: | | ||
just install out | ||
- name: Checkout package registry | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ env.REGISTRY_REPO }} | ||
token: ${{ secrets.REGISTRY_TOKEN }} | ||
path: typst-packages | ||
|
||
- name: Release package | ||
run: | | ||
mkdir -p "typst-packages/${{ env.PATH_PREFIX }}/$PKG_NAME" | ||
mv "out/${PKG_NAME}/${PKG_VERSION}" "typst-packages/${{ env.PATH_PREFIX }}/${PKG_NAME}" | ||
rmdir "out/${PKG_NAME}" | ||
rmdir out | ||
GIT_USER_NAME="$(git log -1 --pretty=format:'%an')" | ||
GIT_USER_EMAIL="$(git log -1 --pretty=format:'%ae')" | ||
cd typst-packages | ||
git config user.name "${GIT_USER_NAME}" | ||
git config user.email "${GIT_USER_EMAIL}" | ||
git checkout -b "${PKG_NAME}-${PKG_VERSION}" | ||
git add . | ||
git commit -m "${PKG_NAME}:${PKG_VERSION}" | ||
git push --set-upstream origin "${PKG_NAME}-${PKG_VERSION}" |
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,12 +1,2 @@ | ||
# [unreleased](https://github.com/wisp3rwind/typst-guide-lines/releases/tag/<tag>) | ||
|
||
## Added | ||
|
||
## Removed | ||
|
||
## Changed | ||
|
||
## Migration Guide from v0.1.x | ||
|
||
# [v0.1.0](https://github.com/wisp3rwind/typst-guide-lines/releases/tag/v0.1.0) | ||
Initial release |
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,17 @@ | ||
# Release checklist | ||
|
||
- Check & finalize changelog, commit | ||
- create a new tag and push it, this triggers the release workflow | ||
- Create a PR against the typst packages repository | ||
- prepend a new section to the changelog and commit it: | ||
``` | ||
# [unreleased](https://github.com/wisp3rwind/typst-guide-lines/releases/tag/<tag>) | ||
## Added | ||
## Removed | ||
## Changed | ||
## Migration Guide from v0.1.x | ||
``` |
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,30 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package | ||
# licensed under Apache License 2.0 | ||
|
||
. "$(dirname "${BASH_SOURCE[0]}")/setup" | ||
|
||
TARGET="$(resolve-target "${1:?Missing target path, @local or @preview}")" | ||
echo "Install dir: $TARGET" | ||
|
||
# Copy all included files to a temporary directory | ||
TMP="$(mktemp -d)" | ||
for f in src/*.typ CHANGELOG.md README.md LICENSE typst.toml; do | ||
mkdir -p "$TMP/$(dirname "$f")" 2>/dev/null | ||
cp -r "$ROOT/$f" "$TMP/$f" | ||
done | ||
|
||
# Remove and re-create the target directory | ||
TARGET="${TARGET:?}/${PKG_PREFIX:?}/${VERSION:?}" | ||
echo "Packaged to: $TARGET" | ||
if rm -r "${TARGET:?}" 2>/dev/null; then | ||
echo "Overwriting existing version." | ||
fi | ||
mkdir -p "$TARGET" | ||
|
||
# Move from temporary to target dir | ||
# include hidden files by setting dotglob | ||
shopt -s dotglob | ||
mv "$TMP"/* "$TARGET" |
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,37 @@ | ||
# source this script to prepare some common environment variables | ||
|
||
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package | ||
# licensed under Apache License 2.0 | ||
|
||
# Local package directories per platform | ||
if [[ "$OSTYPE" == "linux"* ]]; then | ||
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}" | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
DATA_DIR="$HOME/Library/Application Support" | ||
else | ||
DATA_DIR="${APPDATA}" | ||
fi | ||
|
||
function read-toml() { | ||
local file="$1" | ||
local key="$2" | ||
# Read a key value pair in the format: <key> = "<value>" | ||
# stripping surrounding quotes. | ||
perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file" | ||
} | ||
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)/.." # macOS has no realpath | ||
PKG_PREFIX="$(read-toml "$ROOT/typst.toml" "name")" | ||
VERSION="$(read-toml "$ROOT/typst.toml" "version")" | ||
|
||
function resolve-target() { | ||
local target="$1" | ||
|
||
if [[ "$target" == "@local" ]]; then | ||
echo "${DATA_DIR}/typst/packages/local" | ||
elif [[ "$target" == "@preview" ]]; then | ||
echo "${DATA_DIR}/typst/packages/preview" | ||
else | ||
echo "$target" | ||
fi | ||
} |