Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split build and upload jobs in ci-cd GHA workflow #44

Merged
merged 13 commits into from
Mar 28, 2024
Merged
68 changes: 44 additions & 24 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,40 +73,68 @@ jobs:
runs-on: ubuntu-latest
environment: test_release
concurrency: release
if: github.ref_name != 'main'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}

# Do a dry run of PSR
# Dry run of PSR to build the distribution
- name: Test release
uses: python-semantic-release/python-semantic-release@v8.5.0
if: github.ref_name != 'main'
with:
root_options: --noop

check_if_should_release:
# This is a dummy step to avoid starting the release step which will
# trigger a notification when the pypi env needs to be used and we
# don't want to do that unless we're actually releasing.
- uses: snok/install-poetry@v1.3.4
- name: Install Dependencies
run: poetry install --only main,test_build
shell: bash

- name: Test build of distribution packages
shell: bash
run: |
poetry build
poetry run python -Im twine check --strict dist/*

build_release:
needs:
- test
- lint
- commitlint

if: github.ref_name == 'main' && !startsWith(github.event.pull_request.title,'chore:') && !startsWith(github.event.head_commit.message,'chore:')
if: github.ref_name == 'main' && !startsWith(github.event.pull_request.title,'chore') && !startsWith(github.event.head_commit.message,'chore')

runs-on: ubuntu-latest
outputs:
released: ${{ steps.release.outputs.released }}

steps:
- name: Dummy
run: |
echo "GitHub requires the step do something, so we're just going to echo something here."
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}

# On main branch: Call PSR to build the distribution
- name: Release
uses: python-semantic-release/python-semantic-release@v8.5.0
id: release

with:
bdraco marked this conversation as resolved.
Show resolved Hide resolved
bdraco marked this conversation as resolved.
Show resolved Hide resolved
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

release:
needs:
- check_if_should_release
- build_release

if: needs.build_release.outputs.released == 'true'
runs-on: ubuntu-latest
environment: pypi
concurrency: release
Expand All @@ -115,24 +143,16 @@ jobs:
contents: write

steps:
- uses: actions/checkout@v4
- name: Download all the dists
uses: actions/download-artifact@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}

# On main branch: actual PSR + upload to PyPI & GitHub
- name: Release
uses: python-semantic-release/python-semantic-release@v8.5.0
id: release
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
name: python-package-distributions
path: dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: steps.release.outputs.released == 'true'

- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/upload-to-gh-release@main
if: steps.release.outputs.released == 'true'
uses: python-semantic-release/upload-to-gh-release@1eeda76de33f20e9341a93b0e697c79773c6914c
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Loading
Loading