Skip to content

Commit 7e6877f

Browse files
authored
chore(ci): only publish to PyPI if a new release was created (#38)
The semantic release GitHub Action will skip creating a new GitHub release if there are no new releasable changes. This is expected, but the release workflow assumed that there was always a new release to publish to PyPI. This PR updates the release workflow to move the PyPI publish steps to a separate job that will only run if the release job successfully creates a new release.
1 parent 6bfd52a commit 7e6877f

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

.github/workflows/release.yaml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Generate Next Release
22
# This workflow will generate changelog and release notes.
3-
# Source: https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/.github/workflows/release.yml
43

54
on:
65
workflow_dispatch:
@@ -9,10 +8,11 @@ env:
98
DIST_DIR: dist
109
jobs:
1110
release:
12-
name: Build and publish package
11+
name: Create next release
1312
runs-on: ubuntu-latest
14-
permissions:
15-
id-token: write
13+
14+
outputs:
15+
new_release_published: ${{ steps.release.outputs.new_release_published }}
1616

1717
steps:
1818
- name: Checkout
@@ -21,23 +21,14 @@ jobs:
2121
fetch-depth: 0
2222
ssh-key: ${{ secrets.DEPLOY_KEY }}
2323

24-
- name: Install Python
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version-file: .python-version
28-
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade build
32-
3324
- name: Create GitHub release
25+
id: release
3426
uses: cycjimmy/semantic-release-action@v4
3527
with:
36-
semantic_version: 19.0.5
3728
extra_plugins: |
3829
@semantic-release/exec@6.0.3
3930
@semantic-release/git@10.0.0
40-
conventional-changelog-conventionalcommits@4.6.3
31+
conventional-changelog-conventionalcommits@8.0.0
4132
env:
4233
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4334
GIT_AUTHOR_NAME: equinix-labs@auto-commit-workflow
@@ -46,11 +37,36 @@ jobs:
4637
GIT_COMMITTER_EMAIL: bot@equinix.noreply.github.com
4738
RELEASE_REQUESTER: "@${{ github.event.sender.login }}"
4839

40+
publish:
41+
name: Publish artifacts
42+
runs-on: ubuntu-latest
43+
needs: release
44+
if: needs.release.outputs.new_release_published == 'true'
45+
46+
permissions:
47+
id-token: write
48+
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
ssh-key: ${{ secrets.DEPLOY_KEY }}
55+
56+
- name: Install Python
57+
uses: actions/setup-python@v5
58+
with:
59+
python-version-file: .python-version
60+
61+
- name: Install dependencies
62+
run: |
63+
python -m pip install --upgrade build
64+
4965
- name: Build package
5066
run: |
5167
python -m build --sdist --wheel --outdir ${{ env.DIST_DIR }} .
5268
53-
- name: Publish package
69+
- name: Publish to PyPI
5470
uses: pypa/gh-action-pypi-publish@release/v1
5571
with:
5672
packages-dir: ${{ env.DIST_DIR }}

0 commit comments

Comments
 (0)