-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds github actions for building wheels if the version updates (#62)
only uploads to pypi if the patch version updates, otherwise we have to do it manually using the upload script.
- Loading branch information
Showing
4 changed files
with
139 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: build package wheel | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
detect-changes: | ||
uses: ./.github/workflows/check_diff.yml | ||
with: | ||
file_path: pyproject.toml | ||
|
||
build: | ||
needs: detect-changes | ||
if: needs.detect-changes.outputs.version_changed == 'true' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.x" # Use the latest version of Python 3 | ||
|
||
- name: Install Flit | ||
run: python -m pip install flit | ||
|
||
- name: Build Wheel with Flit | ||
run: flit build | ||
|
||
- name: Test Install Wheel | ||
run: pip install dist/*.whl | ||
|
||
- name: Upload to GitHub Artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: python-package | ||
path: dist/*.whl | ||
|
||
publish-to-pypi: | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.detect-changes.outputs.only_patch_version_changed == 'true' | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.x" # Use the latest version of Python 3 | ||
|
||
- name: Install Twine | ||
run: python -m pip install --upgrade pip && python -m pip install --upgrade twine | ||
|
||
- name: Upload to PyPI using script | ||
run: bash scripts/upload_latest.sh | ||
env: | ||
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Check Diff | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
file_path: | ||
description: File path to check for version change | ||
required: true | ||
type: string | ||
outputs: | ||
version_changed: | ||
description: true if the version line in the file has changed | ||
value: ${{ jobs.check.outputs.version_changed }} | ||
only_patch_version_changed: | ||
description: true if only the patch version has changed | ||
value: ${{ jobs.check.outputs.only_patch_version_changed }} | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version_changed: ${{ steps.check.outputs.version_changed }} | ||
only_patch_version_changed: ${{ steps.check.outputs.only_patch_version_changed }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
submodules: recursive | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Check for version changes | ||
id: check | ||
run: | | ||
OLD_VERSION=$(git show ${{ github.event.pull_request.base.sha }}:${{ inputs.file_path }} | grep '^version = ' | cut -d '"' -f 2) | ||
NEW_VERSION=$(grep '^version = ' ${{ inputs.file_path }} | cut -d '"' -f 2) | ||
echo "OLD_VERSION=$OLD_VERSION" | ||
echo "NEW_VERSION=$NEW_VERSION" | ||
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then | ||
echo "Version has changed." | ||
echo "version_changed=true" >> $GITHUB_OUTPUT | ||
IFS='.' read -ra OLD_PARTS <<< "$OLD_VERSION" | ||
IFS='.' read -ra NEW_PARTS <<< "$NEW_VERSION" | ||
if [ "${OLD_PARTS[0]}" == "${NEW_PARTS[0]}" ] && [ "${OLD_PARTS[1]}" == "${NEW_PARTS[1]}" ]; then | ||
echo "Only the patch version has changed." | ||
echo "only_patch_version_changed=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "Major or minor version has changed." | ||
echo "only_patch_version_changed=false" >> $GITHUB_OUTPUT | ||
fi | ||
else | ||
echo "No version change detected." | ||
echo "version_changed=false" >> $GITHUB_OUTPUT | ||
echo "only_patch_version_changed=false" >> $GITHUB_OUTPUT | ||
fi |
This file contains 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
This file contains 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