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

ci: fix workflows edgecases and bump version to 0.4.0 #8

Merged
merged 1 commit into from
Nov 13, 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
81 changes: 45 additions & 36 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ name: Publish Python Package

on:
push:
branches:
- main
paths:
- 'setup.py'
pull_request:
branches:
- "main"
- main
paths:
- 'setup.py'

Expand All @@ -18,39 +13,53 @@ jobs:
outputs:
version_changed: ${{ steps.version-change.outputs.version_changed }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Check if version changed
id: version-change
run: |
VERSION_CHANGE=$(git diff HEAD^ HEAD -- setup.py | grep -e "^+.*version.*=" -e "^-.*version.*=" | wc -l)
if [ "$VERSION_CHANGE" -eq 0 ]; then
echo "Version not changed"
echo "::set-output name=version_changed::false"
else
echo "Version changed"
echo "::set-output name=version_changed::true"
fi
- name: Check out code
uses: actions/checkout@v4
- name: Fetch all history for all tags and branches
run: git fetch --unshallow
- name: Check if version changed
id: version-change
run: |
# Get the latest commit on main before the merge
MAIN_COMMIT=$(git rev-parse origin/main^1)

# Get the version from the main branch before the merge
MAIN_VERSION=$(git show "$MAIN_COMMIT:setup.py" | grep -Po "version='\K.*?(?=')")

# Get the version from the latest commit on the incoming branch
HEAD_VERSION=$(grep -Po "version='\K.*?(?=')" setup.py)

echo "Main version: $MAIN_VERSION"
echo "Head version: $HEAD_VERSION"

# Compare versions
if [ "$MAIN_VERSION" != "$HEAD_VERSION" ]; then
echo "Version changed"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version not changed"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

publish:
needs: check-version-changed
if: needs.check-version-changed.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
93 changes: 51 additions & 42 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ name: Create Release on Push

on:
push:
branches:
- main
paths:
- 'setup.py'
pull_request:
branches:
- "main"
- main
paths:
- 'setup.py'

Expand All @@ -18,45 +13,59 @@ jobs:
outputs:
version_changed: ${{ steps.version-change.outputs.version_changed }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check if version changed
id: version-change
run: |
VERSION_CHANGE=$(git diff HEAD^ HEAD -- setup.py | grep -e "^+.*version.*=" -e "^-.*version.*=" | wc -l)
if [ "$VERSION_CHANGE" -eq 0 ]; then
echo "Version not changed"
echo "::set-output name=version_changed::false"
else
echo "Version changed"
echo "::set-output name=version_changed::true"
fi
- name: Checkout Repository
uses: actions/checkout@v4
- name: Fetch all history for all tags and branches
run: git fetch --unshallow
- name: Check if version changed
id: version-change
run: |
# Get the latest commit on main before the merge
MAIN_COMMIT=$(git rev-parse origin/main^1)

# Get the version from the main branch before the merge
MAIN_VERSION=$(git show "$MAIN_COMMIT:setup.py" | grep -Po "version='\K.*?(?=')")

# Get the version from the latest commit on the incoming branch
HEAD_VERSION=$(grep -Po "version='\K.*?(?=')" setup.py)

echo "Main version: $MAIN_VERSION"
echo "Head version: $HEAD_VERSION"

# Compare versions
if [ "$MAIN_VERSION" != "$HEAD_VERSION" ]; then
echo "Version changed"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version not changed"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

release:
needs: check-version-changed
if: needs.check-version-changed.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Extract Version from setup.py
id: get_version
run: |
echo "::set-output name=VERSION::$(python setup.py --version)"
- name: Create and Push Tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag v${{ steps.get_version.outputs.VERSION }}
git push origin v${{ steps.get_version.outputs.VERSION }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: neuralnetlib v${{ steps.get_version.outputs.VERSION }}
tag_name: v${{ steps.get_version.outputs.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Extract Version from setup.py
id: get_version
run: |
echo "VERSION=$(python setup.py --version)" >> $GITHUB_OUTPUT
- name: Create and Push Tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag v${{ steps.get_version.outputs.VERSION }}
git push origin v${{ steps.get_version.outputs.VERSION }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: "neuralnetlib v${{ steps.get_version.outputs.VERSION }}"
tag_name: "v${{ steps.get_version.outputs.VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='neuralnetlib',
version='0.3.1',
version='0.4.0',
author='Marc Pinet',
description='A simple neural network library with only numpy as dependency',
long_description=open('README.md', encoding="utf-8").read(),
Expand Down