Create release #7
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: | | |
PREVTAGCOMMIT="$(git tag --sort=creatordate | tail -n1 | awk -F'-' '{print $4}')" | |
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@v2 | |
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'/ && | |
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/action-docker-layer-caching@v0.0.11 | |
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@v3 | |
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@v3 | |
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 }}" |