Commit CHANGELOG.md, create a Release and deploy MkDocs #13
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: Deploy a new version | |
on: | |
workflow_dispatch: | |
inputs: | |
version_tag: | |
description: 'Version tag' | |
required: true | |
default: v0.1.0 | |
dry_run: | |
type: boolean | |
description: 'Dry run' | |
default: false | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
environment: mkdocs | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Push new version tag temporarily for changelog generation | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email github-actions[bot]@users.noreply.github.com | |
git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }} | |
git push --tags | |
- name: (dry-run) Get CHANGELOG | |
if: ${{ github.event.inputs.dry_run }} | |
id: changelog-dry-run | |
uses: requarks/[email protected] | |
with: | |
includeInvalidCommits: true | |
excludeTypes: build,docs,style,other | |
token: ${{ github.token }} | |
tag: ${{ github.event.inputs.version_tag }} | |
- name: (dry-run) Display CHANGELOG | |
if: ${{ github.event.inputs.dry_run }} | |
run: | | |
echo "${{ steps.changelog-dry-run.outputs.changes }}" | |
echo "${{ steps.changelog-dry-run.outputs.changes }}" > "$GITHUB_STEP_SUMMARY" | |
- name: (dry-run) Remove temporary version tag | |
if: ${{ github.event.inputs.dry_run }} | |
run: | | |
git tag -d ${{ github.event.inputs.version_tag }} | |
git push origin --delete ${{ github.event.inputs.version_tag }} | |
- name: Update CHANGELOG | |
if: ${{ !github.event.inputs.dry_run }} | |
id: changelog | |
uses: requarks/[email protected] | |
with: | |
includeInvalidCommits: true | |
excludeTypes: build,docs,style,other | |
token: ${{ github.token }} | |
tag: ${{ github.event.inputs.version_tag }} | |
changelogFilePath: docs/CHANGELOG.md | |
- name: Commit docs/CHANGELOG.md and update tag | |
if: ${{ !github.event.inputs.dry_run }} | |
run: | | |
git tag -d ${{ github.event.inputs.version_tag }} | |
git push origin --delete ${{ github.event.inputs.version_tag }} | |
git add docs/CHANGELOG.md | |
git commit -m "docs: update docs/CHANGELOG.md for ${{ github.event.inputs.version_tag }} [skip ci]" | |
git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }} | |
git push | |
git push --tags | |
- name: Create Release | |
if: ${{ !github.event.inputs.dry_run }} | |
uses: ncipollo/[email protected] | |
with: | |
allowUpdates: true | |
draft: false | |
makeLatest: true | |
name: ${{ github.event.inputs.version_tag }} | |
tag: ${{ github.event.inputs.version_tag }} | |
body: ${{ steps.changelog.outputs.changes }} | |
- name: Set up Python | |
if: ${{ !github.event.inputs.dry_run }} | |
uses: actions/setup-python@v5 | |
id: setup-python | |
with: | |
python-version-file: pyproject.toml | |
- name: Run mkdocs | |
if: ${{ !github.event.inputs.dry_run }} | |
run: | | |
pip3 install uv | |
uv venv | |
source .venv/bin/activate | |
uv pip install -r deps/requirements_docs.txt | |
set +e # Do not exit shell on failure | |
export HTTPS_REMOTE="https://gitlab-ci-token:${{ secrets.GL_TOKEN }}@gitlab.com/${{ vars.GL_PROJECT }}.git" | |
git remote add gitlab "$HTTPS_REMOTE" | |
git branch -D gl-pages | |
git pull gitlab gl-pages:gl-pages | |
# Delete the latest page because we're going to make it as an alias to the latest version. | |
mike delete --deploy-prefix public -r "$HTTPS_REMOTE" -b gl-pages latest | |
out=$(mike deploy --deploy-prefix public -r "$HTTPS_REMOTE" -p -b gl-pages -u ${{ github.event.inputs.version_tag }} latest 2> stderr.txt) | |
exit_code=$? | |
err=$(<stderr.txt) | |
mike set-default --deploy-prefix public -r "$HTTPS_REMOTE" -p -b gl-pages latest | |
# Display the raw output in the step | |
echo "${out}" | |
echo "${err}" | |
# Display the Markdown output in the job summary | |
{ echo "\`\`\`python"; echo "${out}"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY" | |
exit ${exit_code} |