Skip to content

Release: Pypi

Release: Pypi #41

Workflow file for this run

# ---------------------------------------------------------------------------------------
# @parent : github workflow
# @desc : pypi release
# @author : Aetherinox
# @url : https://github.com/Aetherinox
# ---------------------------------------------------------------------------------------
name: "Release: Pypi"
run-name: "Release: Pypi"
# ---------------------------------------------------------------------------------------
# environment variables
# ---------------------------------------------------------------------------------------
env:
ASSIGN_USER: Aetherinox
BOT_NAME_1: AdminServ
BOT_NAME_2: AdminServX
BOT_NAME_DEPENDABOT: dependabot[bot]
# ---------------------------------------------------------------------------------------
# triggers
# ---------------------------------------------------------------------------------------
on:
workflow_dispatch:
inputs:
# ---------------------------------------------------------------------------------------
# Python Build Type
# setup and build
# ---------------------------------------------------------------------------------------
OPT_BUILD_TYPE:
type: choice
description: Build Type
options:
- py setup.py
- py build
# ---------------------------------------------------------------------------------------
# Pypi Service
# Official or Test
# ---------------------------------------------------------------------------------------
OPT_PYPI_TYPE:
type: choice
description: Pypi Service
options:
- Official
- Test
# ---------------------------------------------------------------------------------------
# STABLE: stable version
# CANDIDATE: release candidate
# ---------------------------------------------------------------------------------------
OPT_RELEASE_TYPE:
type: choice
description: 📦 Build Type
options:
- Stable
- Release Candidate
# ---------------------------------------------------------------------------------------
# ENABLE: the changelog generated in releases tab will only display single commits.
# DISABLE: the changelog shows pull requests completed based on their labels
# ---------------------------------------------------------------------------------------
CHANGELOG_MODE_COMMIT:
description: "📑 Use Commits Instead of PRs"
required: true
default: true
type: boolean
# ---------------------------------------------------------------------------------------
# ENABLE: Will show all types of commits, including uncategorized
# DISABLE: WIll only show actions that have been categorized using the format
# type(scope): description
# type: description
# ---------------------------------------------------------------------------------------
SHOW_UNCATEGORIZED:
description: "🗂️ Show Uncategorized Commits"
required: true
default: false
type: boolean
# ---------------------------------------------------------------------------------------
# jobs
# ---------------------------------------------------------------------------------------
jobs:
build:
name: Prepare Package
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.build_package_version.outputs.PACKAGE_VERSION }}
package_filename: ${{ steps.build_handle_tarball.outputs.PACKAGE_FILENAME }}
steps:
- name: "✅ Start"
run: |
echo "Starting build: ${{ github.event.inputs.OPT_BUILD_TYPE }}" / ${{ inputs.OPT_BUILD_TYPE }}
- name: "☑️ Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "👁️‍🗨️ Debug › Get Package Version"
id: build_package_version
run: |
# returns version with V at beginning
# VER=$(cat VERSION)
# echo "PACKAGE_VERSION=$VER" >> $GITHUB_OUTPUT
# returns version without V at beginning
VER=$( python3 setup.py -V | tail -1 )
echo "PACKAGE_VERSION=$VER" >> $GITHUB_OUTPUT
# ---------------------------------------------------------------------------------------
# setup python
# ---------------------------------------------------------------------------------------
- name: "🐍 Python › Setup"
uses: actions/setup-python@v5
with:
python-version: "3.x"
# ---------------------------------------------------------------------------------------
# install pip, setuptools, wheel, twine, etc
# ---------------------------------------------------------------------------------------
- name: "🐍 Python › Build Tools"
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
# ---------------------------------------------------------------------------------------
# build python script
# ---------------------------------------------------------------------------------------
- name: "🐍 Python › Build Tarball"
id: build_handle_tarball
run: |
if [ "${{ github.event.inputs.OPT_BUILD_TYPE }}" = "py setup.py" ]; then
echo "Starting build: py setup.py"
python setup.py sdist
fi
if [ "${{ github.event.inputs.OPT_BUILD_TYPE }}" = "py build" ]; then
echo "Starting build: py build"
python -m build . --sdist
fi
PACKAGE=$(find dist/*tar.gz -type f -printf "%f\n")
echo "PACKAGE_FILENAME=dist/$PACKAGE" >> $GITHUB_OUTPUT
- name: "👁️‍🗨️ Debug › Print Package Info"
id: build_print_package
run: |
echo ${{ steps.build_package_version.outputs.PACKAGE_VERSION }}
echo ${{ steps.build_handle_tarball.outputs.PACKAGE_FILENAME }}
- name: "🪢 Twine › Check Dist"
run: |
twine check dist/*
- name: "📁 Upload › Artifact"
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
# ---------------------------------------------------------------------------------------
# Pypi: Official Stable Release
# ---------------------------------------------------------------------------------------
pypi-publish-official:
name: >-
📦 PyPI › Official
if: ${{ github.event.inputs.OPT_PYPI_TYPE == 'Official' }}
needs:
- build
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
environment:
name: Orion
url: https://pypi.org/p/mkdocs-link-embeds-plugin
steps:
- name: "📁 Download › Saved Artifacts"
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Release 📦 PyPI Official
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
#password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: dist/
print-hash: true
# ---------------------------------------------------------------------------------------
# Pypi: Test API
# ---------------------------------------------------------------------------------------
pypi-publish-test:
name: >-
📦 PyPI › Test Api
if: ${{ github.event.inputs.OPT_PYPI_TYPE == 'Test' }}
needs:
- build
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
environment:
name: Orion
url: https://test.pypi.org/p/mkdocs-link-embeds-plugin
steps:
- name: "📁 Download › Saved Artifacts"
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Release 📦 PyPI Test
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# ---------------------------------------------------------------------------------------
# Job > Distribute Release on Github Releases
# ---------------------------------------------------------------------------------------
dist-release:
name: >-
📦 Github › Release
runs-on: ubuntu-latest
needs: [ build, pypi-publish-official, pypi-publish-test ]
env:
PACKAGE_VERSION: ${{ needs.build.outputs.package_version }}
PACKAGE_FILENAME: ${{ needs.build.outputs.package_filename }}
if: |
always()
&& contains(needs.*.result, 'success')
&& !contains(needs.*.result, 'failure')
permissions:
contents: write
steps:
# ---------------------------------------------------------------------------------------
# Dist Releases > Checkout
# ---------------------------------------------------------------------------------------
- name: "☑️ Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
# ---------------------------------------------------------------------------------------
# Dist Releases > [ Artifact ]: Download
# ---------------------------------------------------------------------------------------
- name: "📁 Download › Saved Artifacts"
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
# ---------------------------------------------------------------------------------------
# [ Tag ]: Pre Create
#
# in order to use the changelog github action, you must pre-create the tag otherwise
# the changelog action will have no idea what tag you are going to be creating and
# the list of commits will not be for the correct release.
# ---------------------------------------------------------------------------------------
- name: "🔖 Tag › Pre Create ${{ env.PACKAGE_VERSION }}"
uses: rickstaa/action-create-tag@v1
id: "tag_create"
with:
tag: ${{ env.PACKAGE_VERSION }}
tag_exists_error: false
message: "Latest release"
# ---------------------------------------------------------------------------------------
# Dist Releases > [ Tag ]: Confirm
# ---------------------------------------------------------------------------------------
- name: "🔖 Tag › Confirm ${{ env.PACKAGE_VERSION }}"
run: |
echo "Tag already present: ${{ steps.tag_create.outputs.tag_exists }}"
# ---------------------------------------------------------------------------------------
# Dist Releases > Checksum
# ---------------------------------------------------------------------------------------
- name: "🆔 Checksum › Stable"
id: checksum-st
if: ${{ github.event.inputs.OPT_RELEASE_TYPE == 'Stable' }}
run: |
filename_tar="${{ env.PACKAGE_FILENAME }}"
sha256="$(shasum --algorithm 256 ${filename_tar} | awk '{ print $1 }')"
shasum --algorithm 256 ${filename_tar} > SHA256SUMS.txt
echo "FILE_ZIP=${filename_tar}" >> $GITHUB_ENV
echo "SHA256SUM=${sha256}" >> $GITHUB_ENV
- name: "🆔 Checksum › Release Candidate"
id: checksum-rc
if: ${{ github.event.inputs.OPT_RELEASE_TYPE == 'Release Candidate' }}
run: |
filename_tar="${{ env.PACKAGE_FILENAME }}"
sha256="$(shasum --algorithm 256 ${filename_tar} | awk '{ print $1 }')"
shasum --algorithm 256 ${filename_tar} > SHA256SUMS.txt
echo "FILE_ZIP=${filename_tar}" >> $GITHUB_ENV
echo "SHA256SUM=${sha256}" >> $GITHUB_ENV
- name: "🆔 Checksum › Print"
id: checksum-st-check
run: |
echo ${{ env.SHA256SUM }}
# ---------------------------------------------------------------------------------------
# Dist Releases > Contributor Images
# ---------------------------------------------------------------------------------------
- name: "🥸 Contributors › Generate"
id: contribs-generate
uses: jaywcjlove/github-action-contributors@main
with:
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
output: CONTRIBUTORS.svg
avatarSize: 42
# ---------------------------------------------------------------------------------------
# Generate Changelog
#
# generates a changelog from the github api. requires a PREVIOUS_TAG in order to figure
# out the changes made between the two versions.
#
# outputs:
# ${{ steps.changelog.outputs.changelog }}
# ---------------------------------------------------------------------------------------
- name: "📝 Changelog › Pre Setup (Categorized Commits)"
run: |
echo "TAG_LAST=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "COMMIT_LAST=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: "📝 Changelog › Build (Categorized)"
id: changelog-categorized
if: ${{ startsWith( inputs.SHOW_UNCATEGORIZED, false ) }}
uses: mikepenz/release-changelog-builder-action@v4
with:
token: ${{ secrets.ADMINSERV_TOKEN }}
#fromTag: "${{ env.TAG_LAST }}"
#toTag: "${{ github.ref }}"
configuration: ".github/changelog-configuration.json"
ignorePreReleases: false
commitMode: ${{ inputs.CHANGELOG_MODE_COMMIT }}
fetchReleaseInformation: true
fetchViaCommits: true
configurationJson: |
{
"template": "## Release Info \n- <sub>**Version began on**: <sub>........</sub>`#{{FROM_TAG_DATE}}`</sub>\n- <sub>**SHA256**: <sub>................................</sub>`${{ env.SHA256SUM }} 🔺 ${{ env.FILE_ZIP }}`</sub>\n- <sub>**Stamp**: <sub>....................................</sub>`#{{FROM_TAG}}-#{{FROM_TAG_DATE}} 🔺 #{{TO_TAG}}-#{{TO_TAG_DATE}}`</sub>\n- <sub>**Last Release**: <sub>......................</sub>`#{{DAYS_SINCE}} days ago`</sub>\n\n<br>\n\n---\n\n<br>\n\n### What's New\nThis release contains the following changes:\n\n<br>\n\n---\n\n<br>\n\n### Statistics\nHow the files have changed:\n<ul><li><a href='#{{RELEASE_DIFF}}'>Changed files</a> : <b>#{{CHANGED_FILES}}</b> </li><li>Commits : <b>#{{COMMITS}}</b> </li><li>Additions : <b>#{{ADDITIONS}}</b></li><li>Deletions : <b>#{{DELETIONS}}</b></li>\n<br />\n</ul>\n\n<br>\n\n---\n\n<br>\n\n### Pull Requests\n#{{CHANGELOG}}\n\n<br>\n\n---\n\n<br>\n\n"
}
env:
GITHUB_TOKEN: ${{ secrets.ADMINSERV_TOKEN }}
# ---------------------------------------------------------------------------------------
# shows only categorized commits using the commit standards
# type(scope): description
# type: description
# ---------------------------------------------------------------------------------------
- name: "📝 Changelog › Build (Uncategorized)"
id: changelog-uncategorized
if: ${{ startsWith( inputs.SHOW_UNCATEGORIZED, true ) }}
uses: mikepenz/release-changelog-builder-action@v4
with:
token: ${{ secrets.ADMINSERV_TOKEN }}
#fromTag: "${{ env.TAG_LAST }}"
#toTag: "${{ github.ref }}"
configuration: ".github/changelog-configuration.json"
ignorePreReleases: false
commitMode: ${{ inputs.CHANGELOG_MODE_COMMIT }}
fetchReleaseInformation: true
fetchViaCommits: true
configurationJson: |
{
"template": "## Release Info \n- <sub>**Version began on**: <sub>........</sub>`#{{FROM_TAG_DATE}}`</sub>\n- <sub>**SHA256**: <sub>................................</sub>`${{ env.SHA256SUM }} 🔺 ${{ env.FILE_ZIP }}`</sub>\n- <sub>**GUID**: <sub>.......................................</sub>`${{ steps.dotenv.outputs.GUID }}`</sub>\n- <sub>**UUID**: <sub>.......................................</sub>`${{ steps.dotenv.outputs.UUID }}</sub>`\n- <sub>**Stamp**: <sub>....................................</sub>`#{{FROM_TAG}}-#{{FROM_TAG_DATE}} 🔺 #{{TO_TAG}}-#{{TO_TAG_DATE}}`</sub>\n- <sub>**Last Release**: <sub>......................</sub>`#{{DAYS_SINCE}} days ago`\n</sup>\n\n<br>\n\n---\n\n<br>\n\n### What's New\nThis release contains the following changes:\n\n<br>\n\n---\n\n<br>\n\n### Statistics\nHow the files have changed:\n<ul><li><a href='#{{RELEASE_DIFF}}'>Changed files</a> : <b>#{{CHANGED_FILES}}</b> </li><li>Commits : <b>#{{COMMITS}}</b> </li><li>Additions : <b>#{{ADDITIONS}}</b></li><li>Deletions : <b>#{{DELETIONS}}</b></li>\n<br />\n</ul>\n\n<br>\n\n---\n\n<br>\n\n### Commits (#{{UNCATEGORIZED_COUNT}})\n#{{UNCATEGORIZED}}\n\n<br>\n\n---\n\n<br>\n\n### Pull Requests\n#{{CHANGELOG}}\n\n<br>\n\n---\n\n<br>\n\n"
}
env:
GITHUB_TOKEN: ${{ secrets.ADMINSERV_TOKEN }}
# ---------------------------------------------------------------------------------------
# Fetch Changelog
# ---------------------------------------------------------------------------------------
- name: "📝 Changelog › Print (Categorized)"
if: ${{ startsWith( inputs.SHOW_UNCATEGORIZED, false ) }}
run: |
echo "${{ steps.changelog-categorized.outputs.changelog }}"
- name: "📝 Changelog › Print (Uncategorized)"
if: ${{ startsWith( inputs.SHOW_UNCATEGORIZED, true ) }}
run: |
echo "${{ steps.changelog-uncategorized.outputs.changelog }}"
# ---------------------------------------------------------------------------------------
# [ Release ]: Post Release
#
# outputs:
# [RELEASE ID]:
# ${{ steps.bundle-rc.outputs.id
# ${{ steps.bundle-st.outputs.id
# ---------------------------------------------------------------------------------------
- name: "🏳️ Post › Stable"
if: ${{ github.event.inputs.OPT_RELEASE_TYPE == 'Stable' }}
uses: softprops/action-gh-release@v2
id: bundle-st
env:
GITHUB_TOKEN: ${{ secrets.ADMINSERV_TOKEN }}
with:
token: ${{ secrets.ADMINSERV_TOKEN }}
name: ${{ env.PACKAGE_VERSION }}
tag_name: ${{ env.PACKAGE_VERSION }}
target_commitish: ${{ github.event.inputs.branch }}
draft: false
generate_release_notes: false
files: |
${{ env.PACKAGE_FILENAME }}
SHA256SUMS.txt
prerelease: false
body: |
${{ steps.changelog-categorized.outputs.changelog }}
${{ steps.changelog-uncategorized.outputs.changelog }}
---
- name: "🏳️ Post › Release Candidate"
if: ${{ github.event.inputs.OPT_RELEASE_TYPE == 'Release Candidate' }}
uses: softprops/action-gh-release@v2
id: bundle-rc
env:
GITHUB_TOKEN: ${{ secrets.ADMINSERV_TOKEN }}
with:
token: ${{ secrets.ADMINSERV_TOKEN }}
name: v${{ env.PACKAGE_VERSION }}
tag_name: ${{ env.PACKAGE_VERSION }}
target_commitish: ${{ github.event.inputs.branch }}
draft: false
generate_release_notes: false
files: |
${{ env.PACKAGE_FILENAME }}
SHA256SUMS.txt
prerelease: false
body: |
> [!WARNING]
> This is a **release candidate**, which means it is not a stable release and could contain bugs. You should download it at your own risk.
${{ steps.changelog-categorized.outputs.changelog }}
${{ steps.changelog-uncategorized.outputs.changelog }}
---
# ---------------------------------------------------------------------------------------
# Print Status
# ---------------------------------------------------------------------------------------
- name: "🎛️ [ Status ]: Print"
run: |
echo "Printing Variables"
echo
echo "---- CHANGELOG ---------------------------------------------------------------"
echo "${{ steps.changelog-categorized.outputs.changelog }}"
echo "${{ steps.changelog-uncategorized.outputs.changelog }}"
echo "---- CHANGELOG ---------------------------------------------------------------"
echo ""
echo ""
echo "---- VARIABLES ---------------------------------------------------------------"
echo "Package Version ............ ${{ env.PACKAGE_VERSION }}"
echo "Tag: Previous .............. ${{ env.TAG_LAST }}"
echo "Tag: Now.... ............... ${{ github.ref }}"
echo "Last Commit ................ ${{ env.COMMIT_LAST }}"
echo "ST Output ID ............... ${{ steps.bundle-st.outputs.id }}"
echo "RC Output ID ............... ${{ steps.bundle-rc.outputs.id }}"
echo "---- CHANGELOG ---------------------------------------------------------------"