ci: bump version to 4.3.2 #84
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
name: Create Release on Push | |
on: | |
push: | |
branches: | |
- 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: 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 | |
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 "action@github.com" | |
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=$(git describe --tags --abbrev=0 $NEW_TAG^) | |
# Ensure release notes do not cause format errors | |
RELEASE_NOTES=$(git log $LAST_TAG...$NEW_TAG --pretty=format:"- %s" --reverse | sed 's/%/%25/g; s/\r/%0D/g; s/\n/%0A/g') | |
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT | |
echo -e "$RELEASE_NOTES" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: "neuralnetlib ${{ steps.get_version.outputs.VERSION }}" | |
tag_name: v${{ steps.get_version.outputs.VERSION }} | |
body: ${{ steps.generate_release_notes.outputs.RELEASE_NOTES }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |