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

adds github actions for building wheels if the version updates #62

Merged
merged 8 commits into from
Nov 28, 2023
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
66 changes: 66 additions & 0 deletions .github/workflows/build_wheels.yml
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 }}
57 changes: 57 additions & 0 deletions .github/workflows/check_diff.yml
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]

name = "pypechain"
version = "0.0.10"
version = "0.0.11"
authors = [
{ name = "Matthew Brown", email = "matt@delv.tech" },
{ name = "Dylan Paiton", email = "dylan@delv.tech" },
Expand All @@ -10,7 +10,7 @@ authors = [
]
description = "Codegen python interfaces for web3.py contracts."
readme = "README.md"
requires-python = ">=3.10, <3.11"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
Expand Down
17 changes: 14 additions & 3 deletions scripts/upload_latest.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/bin/bash

# Source the .env file to export the TWINE_USERNAME and TWINE_PASSWORD
# Check if there is a .env file with TWINE_USERNAME and TWINE_PASSWORD
# or if the environment variables are already set.
if [ -f ".env" ]; then
echo "Overwriting TWINE_USERNAME and TWINE_PASSWORD environment variables from .env"
export $(cat .env | xargs)
else
echo ".env file not found"
exit 1
echo "Checking for TWINE_USERNAME and TWINE_PASSWORD environment variables..."

if [ -z "$TWINE_USERNAME" ]; then
echo "TWINE_USERNAME environment variable was not set"
exit 1
fi

if [ -z "$TWINE_PASSWORD" ]; then
echo "TWINE_PASSWORD environment variable was not set"
exit 1
fi
fi

# Navigate to the dist directory
Expand Down
Loading