Merge pull request #96 from funstory-ai/develop #119
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: Release | |
on: | |
push: | |
branches: | |
- main | |
- master | |
permissions: | |
id-token: write | |
contents: write | |
pull-requests: write | |
jobs: | |
check-repository: | |
name: Check if running in main repository | |
runs-on: ubuntu-latest | |
outputs: | |
is_main_repo: ${{ github.repository == 'funstory-ai/BabelDOC' }} | |
steps: | |
- run: echo "Running repository check" | |
build: | |
name: Build distribution π¦ | |
needs: check-repository | |
if: needs.check-repository.outputs.is_main_repo == 'true' | |
runs-on: ubuntu-latest | |
outputs: | |
is_release: ${{ steps.check-version.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: true | |
fetch-depth: 2 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup uv with Python 3.12 | |
uses: astral-sh/setup-uv@4db96194c378173c656ce18a155ffc14a9fc4355 # v5.2.2 | |
with: | |
python-version: "3.12" | |
enable-cache: true | |
cache-dependency-glob: "uv.lock" | |
- name: Check if there is a parent commit | |
id: check-parent-commit | |
run: | | |
echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT | |
- name: Detect and tag new version | |
id: check-version | |
if: steps.check-parent-commit.outputs.sha | |
uses: salsify/action-detect-and-tag-new-version@b1778166f13188a9d478e2d1198f993011ba9864 # v2.0.3 | |
with: | |
version-command: | | |
cat pyproject.toml | grep "version = " | head -n 1 | awk -F'"' '{print $2}' | |
- name: Install Dependencies | |
run: | | |
uv sync | |
- name: Bump version for developmental release | |
if: "! steps.check-version.outputs.tag" | |
run: | | |
version=$(bumpver update --patch --tag=final --dry 2>&1 | grep "New Version" | awk '{print $NF}') && | |
bumpver update --set-version $version.dev$(date +%s) | |
- name: Build package | |
run: "uv build" | |
- name: Store the distribution packages | |
uses: actions/[email protected] | |
with: | |
name: python-package-distributions | |
path: dist/ | |
publish-to-pypi: | |
name: Publish Python π distribution π¦ to PyPI | |
if: needs.build.outputs.is_release != '' | |
needs: | |
- check-repository | |
- build | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/BabelDOC | |
permissions: | |
id-token: write | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish distribution π¦ to PyPI | |
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 | |
publish-to-testpypi: | |
name: Publish Python π distribution π¦ to TestPyPI | |
if: needs.build.outputs.is_release == '' | |
needs: | |
- check-repository | |
- build | |
runs-on: ubuntu-latest | |
environment: | |
name: testpypi | |
url: https://test.pypi.org/p/BabelDOC | |
permissions: | |
id-token: write | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish distribution π¦ to TestPyPI | |
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
post-release: | |
name: Post Release Tasks | |
needs: | |
- check-repository | |
- build | |
- publish-to-pypi | |
- publish-to-testpypi | |
if: | | |
always() && needs.check-repository.outputs.is_main_repo == 'true' && | |
(needs.publish-to-pypi.result == 'success' || needs.publish-to-testpypi.result == 'success') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: true | |
fetch-depth: 2 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish the release notes | |
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0 | |
with: | |
publish: ${{ needs.build.outputs.is_release != '' }} | |
tag: ${{ needs.build.outputs.is_release }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |