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

Publish to pypi #18

Merged
merged 7 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Publish to PyPI

# Workflow runs prerelease job on every push to main branch
# and a release job on every tag push.
# A publish job is executed on every successful prerelease or release job
# And if publish is successful, the version is also updated in the pyproject.toml file and pushed to main branch
# Workflow does not trigger itself as it only changes pyproject.toml, which is not in paths for this workflow
# The package is distributed as sed-processor
on:
push:
# branches:
# - main
tags:
- 'v*'
paths:
- specsanalyzer/**/*
- specsscan/**/*
- .github/workflows/release.yml
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
prerelease:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
lfs: true

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.8
poetry-version: 1.2.2

- name: bump pre-release version
id: version
working-directory: specsanalzer
run: |
VERSION=$(poetry version -s prerelease)
echo "version=$VERSION" >> $GITHUB_OUTPUT
poetry build

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

- name: Upload pyproject.toml
uses: actions/upload-artifact@v3
with:
name: pyproject
path: pyproject.toml

release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
lfs: true

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.8
poetry-version: 1.2.2

- name: Bump release version and build
id: version
working-directory: specsanalyzer
run: |
VERSION=$(echo ${GITHUB_REF#refs/tags/v} | sed 's/-.*//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
poetry version $VERSION
poetry build

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

- name: Upload pyproject.toml
uses: actions/upload-artifact@v3
with:
name: pyproject
path: pyproject.toml

publish:
needs: [prerelease, release]
if: always() && (needs.prerelease.result == 'success' || needs.release.result == 'success')
runs-on: ubuntu-latest
outputs:
version: ${{ needs.prerelease.outputs.version || needs.release.outputs.version }}
environment:
name: pypi
url: https://pypi.org/p/specsanalyzer
permissions:
id-token: write

steps:
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: .

bump-version:
needs: publish
if: always() && (needs.publish.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}

- uses: actions/checkout@v3
with:
lfs: true
token: ${{ steps.generate_token.outputs.token }}

- name: Download pyproject.toml
uses: actions/download-artifact@v3
with:
name: pyproject

- name: Commit files
run: |
git config --local user.email "bump[bot]@users.noreply.github.com"
git config --local user.name "bump[bot]"
git add $GITHUB_WORKSPACE/pyproject.toml
git commit -m "bump version to ${{ needs.publish.outputs.version }}"

- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ steps.generate_token.outputs.token }}
branch: main
1 change: 1 addition & 0 deletions tutorial/1_specsanalyzer_conversion_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
" rotation_angle=2,\n",
" angle_offset_px=-3,\n",
")\n",
"plt.figure()\n",
"res_xarray.plot()"
]
},
Expand Down
Loading