-
Notifications
You must be signed in to change notification settings - Fork 8
Publish to PyPI when a GitHub release is published #214
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd5a896
Push to PyPI on release
jeremystretch 6701ec7
Set id-token: write
jeremystretch 9c79d02
Change release type; use real PyPI
jeremystretch bdc24f7
Pin gh-action-pypi-publish to v1.12.4
jeremystretch a9ff94d
Declare explicit read permissions for workflow
jeremystretch a7f6d5b
Pin pypa/gh-action-pypi-publish to commit hash
jeremystretch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,48 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: [ release ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: false | ||
on: | ||
release: | ||
types: [released] | ||
|
||
env: | ||
PYTHON_RUNTIME_VERSION: "3.11" | ||
PYTHON_PACKAGE_NAME: netboxlabs-netbox-branching | ||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
get-package-name: | ||
name: Get package name | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Python package name | ||
id: package-name | ||
run: echo "package-name=${{ env.PYTHON_PACKAGE_NAME }}" >> "$GITHUB_OUTPUT" | ||
outputs: | ||
package-name: ${{ steps.package-name.outputs.package-name }} | ||
get-next-version: | ||
name: Get next version | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set short sha output | ||
id: short-sha | ||
run: echo "short-sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" | ||
- name: Set release version | ||
id: release-version | ||
run: | | ||
pip install toml-cli | ||
release_version=`toml get --toml-path pyproject.toml project.version` | ||
echo "Release version: $release_version" | ||
echo "release-version=$release_version" >> "$GITHUB_OUTPUT" | ||
outputs: | ||
short-sha: ${{ steps.short-sha.outputs.short-sha }} | ||
release-version: ${{ steps.release-version.outputs.release-version }} | ||
get-release-notes: | ||
name: Get release notes | ||
build: | ||
name: Build distribution | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set release notes | ||
id: release-notes | ||
env: | ||
PR_BODY: ${{ github.event.pull_request.body }} | ||
run: | | ||
echo 'release-notes<<EOF' >> $GITHUB_OUTPUT | ||
echo $PR_BODY >> $GITHUB_OUTPUT | ||
echo 'EOF' >> $GITHUB_OUTPUT | ||
outputs: | ||
release-notes: ${{ steps.release-notes.outputs.release-notes }} | ||
build: | ||
name: Build | ||
needs: [ get-package-name, get-next-version, get-release-notes ] | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.x" | ||
- name: Install pypa/build | ||
run: | | ||
python3 -m pip install build | ||
- name: Build distribution package | ||
run: | | ||
python3 -m build | ||
- name: Upload distribution package | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
if-no-files-found: error | ||
|
||
publish: | ||
name: Publish to PyPI | ||
needs: | ||
- build | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
permissions: | ||
id-token: write | ||
contents: read | ||
env: | ||
BUILD_VERSION: ${{ needs.get-next-version.outputs.release-version }} | ||
BUILD_TRACK: release | ||
BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }} | ||
OUTPUT_FILENAME: ${{ needs.get-package-name.outputs.package-name }}-${{ needs.get-next-version.outputs.release-version }}.tar.gz | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ env.PYTHON_RUNTIME_VERSION }} | ||
- name: Build sdist package | ||
run: | | ||
python3 -m pip install --upgrade build | ||
python3 -m build --sdist --outdir dist/ | ||
- name: Replace underscores with hyphens in build filename | ||
run: | | ||
BUILD_FILENAME=$(ls dist/ | grep tar.gz) | ||
mv dist/$BUILD_FILENAME dist/${{ env.OUTPUT_FILENAME }} | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.OUTPUT_FILENAME }} | ||
path: dist/${{ env.OUTPUT_FILENAME }} | ||
retention-days: 30 | ||
if-no-files-found: error | ||
- name: Publish release distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
packages-dir: dist | ||
release: | ||
name: Release | ||
needs: [ get-next-version, get-release-notes, build ] | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Create release | ||
id: create_release | ||
uses: actions/create-release@latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: v${{ needs.get-next-version.outputs.release-version }} | ||
release_name: ${{ needs.get-next-version.outputs.release-version }} | ||
body: ${{ needs.get-release-notes.outputs.release-notes }} | ||
draft: false | ||
- name: Download distribution package | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
- name: Publish distribution to PyPI | ||
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.