Skip to content

Update README.md in test #194

Update README.md in test

Update README.md in test #194

Workflow file for this run

name: Publish to pip
on:
push:
branches:
- main
paths-ignore:
- 'pyproject.toml' # Ignore changes to pyproject.toml
- 'src/version.py' # Ignore changes to src/version.py
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Echo Push Event
run: |
echo trigger_branch=${{ github.ref }} >> $GITHUB_ENV
echo "The workflow was triggered by a push to branch: $trigger_branch"
echo git_event=${{ github.sha }} >> $GITHUB_ENV
echo "Push event SHA: $git_event"
echo "Pushed by: ${{ github.actor }}"
shell: bash
- name: Check if version number is in pyproject.toml
run: |
# Check if the version number is in pyproject.toml
if grep -q "version\s*=\s*['\"]\?[0-9.-]\+['\"]\?" pyproject.toml; then
echo "✔ Version is found in pyproject.toml."
else
echo "✘ ERROR - Version not found in pyproject.toml."
fi
shell: bash
- name: Extract version number from pyproject.toml
run: |
# Use grep to find the line containing the version number
version_line=$(grep -E "version\s*=" pyproject.toml)
# Use awk to extract the version number
version=$(echo "$version_line" | awk -F"['\"]" '{print $2}')
# Echo the extracted version number
echo "✔ Version number is: $version"
echo "version=$version" >> $GITHUB_ENV
shell: bash
- name: Increment the rightmost integer in the version
run: |
# Increment the rightmost integer by 1
IFS='.' read -a version_parts <<< "$version"
last_part="${version_parts[-1]}"
new_last_part=$((last_part + 1))
version_parts[-1]=$new_last_part
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
# Update the version in pyproject.toml
sed -i "s/\(version\s*=\s*['\"]\?\)[0-9.-]\+\(['\"]\?\)/\1$new_version\2/" pyproject.toml
# Echo the updated version
echo "✔ New version number is: $new_version"
echo "new_version=$new_version" >> $GITHUB_ENV
shell: bash
- name: Create a new branch
run: |
branch="feature/update-version-$new_version"
echo "creating branch: $branch"
echo "branch=$branch" >> $GITHUB_ENV
git checkout -b $branch
git push origin $branch
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Commit and Push Changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "SuleyNL"
# Switch to the update_version branch
git fetch
git checkout $branch
git add pyproject.toml
echo "Branch to push to is: $branch"
# Commit the changes in pyproject.toml
git commit -am "Increment version from $version to $new_version"
# Push the changes from current local branch to remote branch
git push origin HEAD:$branch
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
# The version can also be updated using a version in the github repo, this must first be analyzed for pros and cons
#- name: Update version in src/version.py and pyproject.toml
# run: |
# # Increment the version in src/version.py
# python -c "import re; f=open('src/version.py', 'r+'); v=re.sub(r'(\d+)', lambda x: str(int(x.group(0))+1), f.read()); f.seek(0); f.write(v); f.truncate(); f.close()"
# # Update the version in pyproject.toml
# sed -i 's/\(version = "\)[0-9.]*\(".*\)/\1NEW_VERSION\2/' pyproject.toml
# env:
# NEW_VERSION: ${{ github.run_number }}
- name: Create Pull Request
run: |
echo "Push event SHA: $git_event"
echo mergedBranch="${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
echo "✔ Merged from branch: $mergedBranch"
pr_title="Update version from $version to $new_version"
pr_body="This is an automated version-update on pyproject.toml.
The workflow was triggered by a succesfull pull request from branch: $mergedBranch
With push event SHA of: $git_event
This action is performed by the Github Action: publish.yml after every accepted pull request. When finished,
this will have published the latest patch of the Extractable codebase to Pypi so it can be pip installed.
# DO NOT DO ANYTHING WITH THIS PULL REQUEST
This pull request should resolve itself within 1 minute.
If its older than 5 minutes and still not resolved you may check the github workflow actions to see where it went wrong.
And in that case it is safe to delete this pull request"
gh pr create --base main --head $branch --title "$pr_title" --body "$pr_body"
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Merge Pull Request
run: |
# Use the gh pr review command to request changes
gh pr comment $branch --body "updated version in pyproject.toml from $version to $new_version"
# Merge the pull request
gh pr merge $branch --merge --admin --delete-branch
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Build package
run: |
python -m pip install --upgrade pdm
pdm build
working-directory: ./ # Specify the directory where pyproject.toml is located
- name: Upload package to PyPI
run: |
python -m pip install twine
twine upload dist/extractable-* --verbose
echo "### :rocket: Succesfully shipped [extractable-$new_version](https://pypi.org/project/extractable/$new_version/) to pip!" > $GITHUB_STEP_SUMMARY
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API }}
# TODO: would be nice if the pushed code was first tested by publishing on test pypi and then rerunning the e2e and unit and component tests
#- name: Add main_version to github repo variable
#TODO: would be nice if this worked: keeping the version number in the github main repo
# run: |
# echo "mversion is $m_version"
# echo "$m_version=$new_version" >> $GITHUB_ENV
#
# echo "main_version=$new_version" >> $GITHUB_ENV
# echo "github env: $new_version"
#
# env:
# GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
# m_version: ${{ vars.main_version }}
#- name: Add main_version to github repo variable try 2
# uses: peter-evans/repository-dispatch@v2
# with:
# token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
# event-type: 'edit-variable'
# client-payload: {
# secret_name: 'MAIN_VERSION',
# secret_value: "${{ env.new_version }}",
# }