Skip to content

Commit

Permalink
Merge pull request #8 from marcpinet/ci-fix-workflow-and-bump-version
Browse files Browse the repository at this point in the history
ci: fix and improve workflows and bump version to 0.4.0
  • Loading branch information
marcpinet committed Nov 13, 2023
2 parents 46d3309 + 9562032 commit b985788
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 84 deletions.
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/*
87 changes: 40 additions & 47 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,54 @@ name: Create Release on Push

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

jobs:
check-version-changed:
runs-on: ubuntu-latest
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
# ... (previous jobs)

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
with:
fetch-depth: 0 # Ensure all tags are fetched
- 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: Get last tag
id: get_last_tag
run: |
echo "LAST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
- name: Create and Push Tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
NEW_TAG="v${{ steps.get_version.outputs.VERSION }}"
git tag $NEW_TAG
git push origin $NEW_TAG
- name: Generate Release Notes
id: generate_release_notes
run: |
NEW_TAG="v${{ steps.get_version.outputs.VERSION }}"
LAST_TAG=${{ steps.get_last_tag.outputs.LAST_TAG }}
RELEASE_NOTES=$(git log $LAST_TAG...$NEW_TAG --pretty=format:"- %s" --reverse)
echo "RELEASE_NOTES=$RELEASE_NOTES" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: "neuralnetlib ${{ steps.get_version.outputs.VERSION }}"
tag_name: ${{ steps.get_version.outputs.VERSION }}
body: ${{ steps.generate_release_notes.outputs.RELEASE_NOTES }}
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

0 comments on commit b985788

Please sign in to comment.