Skip to content

Commit 74046ad

Browse files
committed
Change: Allow only manual releases from main
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent 45a63b1 commit 74046ad

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

.github/workflows/build-test-release.yml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ on:
1414
description: Create a (pre-)release when CI passes
1515
default: false
1616
required: false
17-
update_dependencies:
18-
type: boolean
19-
description: Update dependencies to their latest version
20-
default: false
21-
required: false
2217
outputs:
2318
tag:
2419
description: "The created release tag"
@@ -102,10 +97,9 @@ jobs:
10297

10398
- name: Run All Code Quality Checks & Tests
10499
run: poe all --check
105-
106100

107101
github-release:
108-
if: ${{ inputs.create_release == 'true' }}
102+
if: ${{ github.ref == 'refs/heads/main' && inputs.create_release }}
109103
needs:
110104
- build-python
111105
- tests
@@ -125,7 +119,6 @@ jobs:
125119
path: dist/
126120

127121
- name: Prevent automatic major/minor release
128-
if: (github.event_name == 'push')
129122
run: |
130123
echo "Fetching the latest release..."
131124
tag=$(gh release view --json tagName --jq '.tagName')
@@ -150,12 +143,44 @@ jobs:
150143
run: echo "${{ steps.tag.outputs.tag }}"
151144

152145
- name: Release
153-
if: (inputs.create_release)
154146
uses: softprops/action-gh-release@v2
155147
with:
156148
files: |
157149
./dist/*
158150
tag_name: ${{ steps.tag.outputs.tag }}
159-
prerelease: ${{github.ref != 'refs/heads/main'}}
160151
generate_release_notes: true
161152
target_commitish: ${{ github.sha }}
153+
154+
publish:
155+
name: Publish to PyPI
156+
needs: github-release
157+
runs-on: ubuntu-latest
158+
permissions:
159+
contents: write
160+
id-token: write # Required for Trusted Publishing
161+
steps:
162+
- name: Download assets from latest GitHub release using gh CLI
163+
env:
164+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165+
run: |
166+
mkdir -p assets-to-publish
167+
release_tag="${{ needs.build-test-release.outputs.tag }}"
168+
gh release download "$release_tag" --repo "$GITHUB_REPOSITORY" --dir assets-to-publish
169+
170+
- name: List downloaded assets
171+
run: ls -la assets-to-publish
172+
173+
- name: Upload assets to PyPI
174+
uses: pypa/gh-action-pypi-publish@release/v1
175+
with:
176+
# To test, use the TestPyPI:
177+
# repository-url: https://test.pypi.org/legacy/
178+
# You must also create an account and project on TestPyPI,
179+
# as well as set the trusted-publisher in the project settings:
180+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
181+
# To publish to the official PyPI repository, just keep
182+
# repository-url commented out.
183+
packages-dir: assets-to-publish
184+
skip-existing: true
185+
print-hash: true
186+
verbose: true

.github/workflows/ci.yml

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
inputs:
1616
create_release:
1717
type: boolean
18-
description: Create a (pre-)release when CI passes
18+
description: Create a release when CI passes
1919
default: false
2020
required: true
2121

@@ -30,12 +30,13 @@ jobs:
3030
- run: echo "ci started"
3131

3232
build-test-release:
33+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
3334
name: build-test-release
3435
uses: "./.github/workflows/build-test-release.yml"
3536
permissions:
3637
contents: write
3738
with:
38-
create_release: ${{ (github.event_name == 'workflow_dispatch' && inputs.create_release) || (github.event_name == 'push') }}
39+
create_release: ${{ inputs.create_release }}
3940

4041
check-code-quality:
4142
uses: "./.github/workflows/check-code-quality.yml"
@@ -53,39 +54,3 @@ jobs:
5354
- name: "Check whether all jobs passed"
5455
run: echo '${{ toJSON(needs) }}' | jq -e 'to_entries | all(.value.result == "success")'
5556
- run: echo "ci passed"
56-
57-
publish:
58-
name: Publish to PyPI
59-
runs-on: ubuntu-latest
60-
permissions:
61-
contents: write
62-
id-token: write # Required for Trusted Publishing
63-
needs: build-test-release
64-
if: (github.event_name == 'workflow_dispatch' && inputs.create_release) || github.event_name == 'push'
65-
66-
steps:
67-
- name: Download assets from latest GitHub release using gh CLI
68-
env:
69-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70-
run: |
71-
mkdir -p assets-to-publish
72-
release_tag="${{ needs.build-test-release.outputs.tag }}"
73-
gh release download "$release_tag" --repo "$GITHUB_REPOSITORY" --dir assets-to-publish
74-
75-
- name: List downloaded assets
76-
run: ls -la assets-to-publish
77-
78-
- name: Upload assets to PyPI
79-
uses: pypa/gh-action-pypi-publish@release/v1
80-
with:
81-
# To test, use the TestPyPI:
82-
# repository-url: https://test.pypi.org/legacy/
83-
# You must also create an account and project on TestPyPI,
84-
# as well as set the trusted-publisher in the project settings:
85-
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
86-
# To publish to the official PyPI repository, just keep
87-
# repository-url commented out.
88-
packages-dir: assets-to-publish
89-
skip-existing: true
90-
print-hash: true
91-
verbose: true

0 commit comments

Comments
 (0)