Setup workflow test to use trusted publisher #88
Workflow file for this run
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: Publish On Tag | |
on: | |
workflow_call: | |
push: | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.7 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.7 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install setuptools wheel twine | |
- name: Get module version | |
id: get_module_version | |
run: | | |
version=$(python -c "from auto_py_to_exe import __version__ as v; print(v)") | |
echo "Module version: $version" | |
echo "version=$version" >> $GITHUB_OUTPUT | |
- name: Fail on tag and module version mismatch | |
if: (!endsWith(github.ref, steps.get_module_version.outputs.version)) | |
run: | | |
echo "Ref that triggered release: ${{ github.ref }}" | |
echo "Current module version: ${{ steps.get_module_version.outputs.version }}" | |
exit 1 | |
- name: Get documented version changes from CHANGELOG.md | |
id: get_documented_changes | |
shell: python | |
run: | | |
import os | |
import random | |
import re | |
import string | |
# Read in the changelog | |
with open("CHANGELOG.md", "r", encoding='utf-8') as f: | |
changelog = f.read() | |
version = "${{ steps.get_module_version.outputs.version }}" | |
# Get the changes for the current version | |
changes_for_target_version_regex = r"##\s*{}\s*\n((?:.|\n)*?)(?:\n##\s*|\Z)".format(re.escape(version)) | |
match = re.search(changes_for_target_version_regex, changelog) | |
if match is None: | |
raise Exception(f"Changes were not detected in CHANGELOG.md for version {version}") | |
changes = re.search(changes_for_target_version_regex, changelog).group(1).strip() | |
# Replace GitHub user links with @mentions | |
github_user_regex = re.compile(r"\[[^\]]+\]\(https:\/\/github\.com\/([A-Za-z0-9-]+)\)") | |
changes = github_user_regex.sub(r'@\1', changes) | |
# Get the previous version | |
versions_regex = r"^## (\d+\.\d+\.\d+)(?=^## \d+\.\d+\.\d+|$)" | |
versions = re.findall(versions_regex, changelog, re.MULTILINE) | |
current_version_index = [i for i, v in enumerate(versions) if v == version][0] | |
previous_version = versions[current_version_index + 1] | |
# Build up the changelog | |
footer = f"\n\n---" | |
footer += f"\n\n[🌐 auto-py-to-exe {version} on PyPI](https://pypi.org/project/auto-py-to-exe/{version}/)" | |
footer += f"\n[v{previous_version} ➡️ v{version} changes](https://github.com/brentvollebregt/auto-py-to-exe/compare/v{previous_version}...v{version})" | |
changes += footer | |
# Output the changelog | |
print(changes) | |
# Writing multiline strings to output: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings | |
github_output_file_path = os.getenv('GITHUB_OUTPUT') | |
delimiter = ''.join(random.choice(string.ascii_uppercase) for i in range(20)) | |
with open(github_output_file_path, "a") as github_output_file: | |
github_output_file.write(f"changes<<{delimiter}\n{changes}\n{delimiter}") | |
- name: Build distribution | |
run: python setup.py sdist bdist_wheel --universal | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Create release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: v${{ steps.get_module_version.outputs.version }} | |
name: v${{ steps.get_module_version.outputs.version }} | |
draft: false | |
prerelease: false | |
body: ${{ steps.get_documented_changes.outputs.changes }} | |
files: | | |
./dist/auto_py_to_exe-${{ steps.get_module_version.outputs.version }}-py2.py3-none-any.whl |