edit: a new publish workflow #15
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
name: "Publish to Typst package" | |
on: | |
push: | |
branches: | |
- main | |
- release-* | |
env: | |
GIT_USER_EMAIL: [email protected] | |
GIT_USER_NAME: HPDell | |
PACKAGE_NAME: cineca | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Typst Build | |
uses: typst-community/setup-typst@v3 | |
- name: Install toml-cli | |
run: pip install toml-cli | |
- name: Copy to preview packages | |
run: | | |
export PKG_VERSION=`toml get --toml-path typst.toml "package.version"` | |
export PKG_PREVIEW_HOME="$HOME/.cache/typst/packages/preview/${{ env.PACKAGE_NAME }}/$PKG_VERSION/" | |
mkdir -p $PKG_PREVIEW_HOME | |
rsync -avP ./ $PKG_PREVIEW_HOME | |
- name: Test build example | |
run: typst compile example.typ | |
publish: | |
needs: [build] | |
if: startsWith(github.ref_name, 'release-') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Clone packages repo | |
run: git clone https://hpdell:${{ secrets.GH_TOKEN }}@github.com/HPDell/typst-packages.git packages | |
- name: Get version number | |
run: | | |
pip install toml-cli | |
echo "PKG_VERSION=`toml get --toml-path typst.toml package.version`" >> "$GITHUB_ENV" | |
- name: Create branch and copy files | |
working-directory: packages/packages/preview | |
run: | | |
git switch -c feat/${{ env.PACKAGE_NAME }} | |
mkdir -p ${{ env.PACKAGE_NAME }}/$PKG_VERSION | |
rsync -av \ | |
--exclude=.git \ | |
--exclude=.github \ | |
--exclude=.gitignore \ | |
--exclude=.vscode \ | |
./ \ | |
packages/packages/preview/${{ env.PACKAGE_NAME }}/$PKG_VERSION/ | |
echo "PKG_COMMIT_MSG=`git log --format='%s' -n 1`" >> "$GITHUB_ENV" | |
- name: Commit and squash | |
working-directory: packages | |
run: | | |
git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
git config --global user.name "${{ env.GIT_USER_NAME }}" | |
git add -A | |
git commit -m "${{ env.PACKAGE_NAME }}:$PKG_VERSION\n\n$PKG_COMMIT_MSG" | |
git switch main | |
git merge feat/${{ env.PACKAGE_NAME }} | |
git branch -D feat/${{ env.PACKAGE_NAME }} | |
git push origin main |