Merge pull request #249 from Haidra-Org/main #56
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: horde-engine build and publish | |
on: | |
push: | |
branches: | |
- releases | |
permissions: | |
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
contents: write | |
pull-requests: read | |
jobs: | |
build-n-publish: | |
name: horde-engine build and publish | |
runs-on: ubuntu-latest | |
environment: # see https://github.com/pypa/gh-action-pypi-publish/tree/release/v1/ | |
name: pypi | |
url: https://pypi.org/p/horde-engine/ | |
steps: | |
# Version bumps the project and creates a tag by creating | |
# a github release. The github release itself is not so | |
# interesting, as it's incomplete because we haven't finished | |
# the build. The important goal here is a pypi release and this | |
# get us our version number. | |
- name: "📣 Release on push" | |
id: release | |
uses: rymndhng/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
bump_version_scheme: patch | |
use_github_release_notes: true | |
- name: "✔️ Checkout" | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Pass the version number in an env var to the below steps | |
- name: Set build version env var | |
run: echo "SETUPTOOLS_SCM_PRETEND_VERSION=${{ steps.release.outputs.version }}" >> $GITHUB_ENV | |
# We need python... | |
- name: "🐍 Set up Python 3.10" | |
if: ${{ steps.release.outputs.version != '' }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
# Install build deps | |
# NOTE If any horde-engine imports used by build_helper.py are changed, or the specific modules | |
# imported from horde-engine depend on a package not included here, running build_helper.py later on will fail. | |
# See `build_helper.py` for more information. | |
- name: "🛠 Install pypa/build" | |
if: ${{ steps.release.outputs.version != '' }} | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install build psutil typing-extensions loguru strenum python-dotenv --user | |
- name: "✏️ Install changelog dependencies" | |
if: ${{ steps.release.outputs.version != '' }} | |
uses: actions/setup-node@v3 | |
- name: "✏️ Generate release changelog" | |
if: ${{ steps.release.outputs.version != '' }} | |
run: | | |
npm -g install auto-changelog | |
auto-changelog --template=.changelog --ignore-commit-pattern="update changelog|version bump|Merge pull" | |
# Try to add the changelog back to the releases branch | |
- uses: EndBug/add-and-commit@v9 | |
with: | |
add: 'CHANGELOG.md' | |
message: 'ci: update changelog' | |
# Patches our requirements.txt and pyproject.toml | |
# Build a changelog | |
- name: "🔧 Prepare our build for release" | |
if: ${{ steps.release.outputs.version != '' }} | |
run: >- | |
python build_helper.py | |
# Build a pypi distribution using the env var version number | |
- name: "🔧 Build a binary wheel and a source tarball" | |
if: ${{ steps.release.outputs.version != '' }} | |
run: >- | |
python -m build --sdist --wheel --outdir dist/ . | |
# Publish the package | |
- name: "📦 Publish distribution to PyPI" | |
if: ${{ steps.release.outputs.version != '' }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
# Update the badges (maybe, if we're lucky) | |
- name: "📦 Refresh pypi badge cache" | |
run: >- | |
curl -X PURGE | |
https://camo.githubusercontent.com/42307cf23a47bc021a97a6da572ce61568aa29b7d23ccfbbc89bf15168d23ce0/68747470733a2f2f62616467652e667572792e696f2f70792f686f7264656c69622e7376673f6272616e63683d6d61696e266b696c6c5f63616368653d31 | |
- name: "📦 Refresh downloads badge cache" | |
run: >- | |
curl -X PURGE | |
https://camo.githubusercontent.com/769edfb1778d4cbc3f93bc5ad0be9597bbd2d9c162cc1e9fb44172a5b660af01/68747470733a2f2f706570792e746563682f62616467652f686f7264656c6962 | |
- name: "Inform with Discord Webhook" | |
if: ${{ steps.release.outputs.version != '' }} | |
uses: tsickert/[email protected] | |
with: | |
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
content: "New version of horde-engine has been published to pypi: ${{ steps.release.outputs.version }}. Changelog: https://t.ly/z2vQ" |