Create release #197
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: Create release | |
on: | |
workflow_dispatch: | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: "0 0 * * *" | |
jobs: | |
create-tag: | |
name: Check if new commit | |
runs-on: ubuntu-latest | |
outputs: | |
skip: ${{ steps.skip.outputs.skip }} | |
tag: ${{ steps.create-tag-name.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Should it run? | |
id: skip | |
run: | | |
# Resolve the current tag into it's commit to be able to directly compare | |
# with HEAD. This means that a manual tag such as "version 1.0" will not | |
# cause the CI job to create a new tag pointing to the same commit. | |
PREVTAGCOMMIT_UNSANITIZED="$(git tag --sort=creatordate | tail -n1)" | |
PREVTAGCOMMIT_SANITIZED="$(git rev-list -n 1 $PREVTAGCOMMIT_UNSANITIZED)" | |
PREVTAGCOMMIT="$(git rev-parse --short $PREVTAGCOMMIT_SANITIZED)" | |
CURRENTCOMMIT="$(git rev-parse --short HEAD)" | |
if [ "$PREVTAGCOMMIT" == "$CURRENTCOMMIT" ]; then | |
echo "Tags are the same ($PREVTAGCOMMIT != $CURRENTCOMMIT), skipping future steps" | |
echo "skip=true" >> $GITHUB_OUTPUT | |
else | |
echo "Tags are not the same ($PREVTAGCOMMIT != $CURRENTCOMMIT). Continuing." | |
echo "skip=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Set tag name | |
id: create-tag-name | |
if: steps.skip.outputs.skip == 'false' | |
run: | | |
v=${GITHUB_REF##*/} | |
echo "Version: $v" | |
echo "tag=$(date '+%F')-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
setup-envs: | |
name: Generate data for release | |
runs-on: ubuntu-latest | |
needs: create-tag | |
if: needs.create-tag.outputs.skip == 'false' | |
outputs: | |
release_body: ${{ steps.release.outputs.release_body }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate latest changelog | |
uses: orhun/git-cliff-action@v3 | |
id: git-cliff-latest | |
with: | |
args: -vv --latest --strip header | |
env: | |
OUTPUT: CHANGELOG.md | |
- name: Set the release body | |
id: release | |
continue-on-error: true | |
shell: bash | |
run: | | |
r=$(cat ${{ steps.git-cliff-latest.outputs.changelog }}) | |
r="$(printf "$r" | tail -n +3)" | |
r="${r//'%'/'%25'}" | |
r="${r//$'\n'/'%0A'}" | |
r="${r//$'\r'/'%0D'}" | |
build: | |
name: Build document | |
runs-on: ubuntu-latest | |
needs: [create-tag, setup-envs] | |
if: needs.create-tag.outputs.skip == 'false' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: satackey/[email protected] | |
continue-on-error: true | |
name: Enable docker cache | |
- uses: xu-cheng/latex-action@v3 | |
name: "Compile document 1/2" | |
with: | |
root_file: main.tex | |
args: -synctex=1 -interaction=nonstopmode -file-line-error -pdf | |
- uses: xu-cheng/latex-action@v3 | |
name: "Compile document 2/2" | |
with: | |
root_file: main.tex | |
args: -synctex=1 -interaction=nonstopmode -file-line-error -pdf | |
pre_compile: "bibtex main; makeindex main.nlo -s nomencl.ist -o main.nls" | |
post_compile: "latexmk -c" | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: main-pdf-release | |
path: ./main.pdf | |
publish-github: | |
name: Publish on GitHub | |
runs-on: ubuntu-latest | |
needs: [create-tag, setup-envs, build] | |
if: needs.create-tag.outputs.skip == 'false' | |
steps: | |
- name: Checkout | |
if: ${{ !env.ACT }} | |
uses: actions/checkout@v4 | |
- name: Download artifacts | |
if: ${{ !env.ACT }} | |
id: download | |
uses: actions/download-artifact@v4 | |
with: | |
name: main-pdf-release | |
path: main-pdf-release | |
- name: Upload the release | |
if: ${{ !env.ACT }} | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ needs.create-tag.outputs.tag }} | |
file: ${{steps.download.outputs.download-path}}/main.pdf | |
asset_name: $tag.pdf | |
release_name: "${{ needs.create-tag.outputs.tag }}" | |
body: "${{ needs.setup-envs.outputs.release_body }}" |