Skip to content

Commit

Permalink
Merge pull request #923 from PMEAL/maint/hatch
Browse files Browse the repository at this point in the history
- Migrated from bump2version to hatch for resolving version number #maint
- Refactored and updated Actions #maint
- Deprecated Python 3.8 and 3.9 #maint
- Added linter Action: ruff #maint
- Unified project config (pytest.ini, setup.cfg) files in pyproject.toml #maint
- Removed pyfastnoisesimd from dependencies as it no longer works on Python 3.9+ #maint
  • Loading branch information
ma-sadeghi authored Mar 11, 2024
2 parents e0b3e02 + 6dd157b commit 983fb62
Show file tree
Hide file tree
Showing 47 changed files with 222 additions and 329 deletions.
41 changes: 12 additions & 29 deletions .github/workflows/bump-version-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,31 @@ jobs:
name: Bump version
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'

- name: Set env variables
run: |
# The next line is very important, otherwise the line after triggers
# git to track the permission change, which breaks bump2version API (needs clean git folder)
git config core.filemode false
chmod +x .github/workflows/utils.sh
echo "VERSION_FILE=porespy/__version__.py" >> $GITHUB_ENV
echo "SETUP_CFG_FILE=setup.cfg" >> $GITHUB_ENV
echo "${{ github.event.head_commit.message }}"
- name: Install dependencies
run: |
pip install bump2version
pip install -e .[build]
- name: Bump version (build)
- name: Bump version (dev)
run: |
source .github/workflows/utils.sh
bump_version build $VERSION_FILE
# Note that we don't want to create a new tag for "builds"
# - name: Commit files
# run: |
# REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
# remote_repo="https://${GITHUB_ACTOR}:${{ secrets.PUSH_ACTION_TOKEN }}@github.com/${REPOSITORY}.git"

# git config --local user.email "action@github.com"
# git config --local user.name "GitHub Action"

# # Commit version bump to dev ([no ci] to avoid infinite loop)
# git commit -m "Bump version number (build) [no ci]" -a
# git push "${remote_repo}" dev
hatch version dev
- name: Commit files
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Bump version number (build part)
commit_author: Author <actions@github.com>
commit_message: Bump version number (dev segment)
commit_author: GitHub Actions <actions@github.com>
39 changes: 13 additions & 26 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,44 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'

- name: Set env variables
run: |
# The next line is very important, otherwise the line after triggers
# git to track the permission change, which breaks bump2version API (needs clean git folder)
git config core.filemode false
chmod +x .github/workflows/utils.sh
echo "VERSION_FILE=porespy/__version__.py" >> $GITHUB_ENV
echo "SETUP_CFG_FILE=setup.cfg" >> $GITHUB_ENV
echo "${{ github.event.head_commit.message }}"
- name: Install dependencies
run: |
pip install bump2version
pip install -e .[build]
- name: Bump version (patch)
if: contains(github.event.head_commit.message, '#patch')
run: |
source .github/workflows/utils.sh
bump_version patch $VERSION_FILE
echo "TAG_NEW=v$(get_version $VERSION_FILE)" >> $GITHUB_ENV
hatch version patch
echo "TAG_NEW=v$(hatch version)" >> $GITHUB_ENV
- name: Bump version (minor)
if: contains(github.event.head_commit.message, '#minor')
run: |
source .github/workflows/utils.sh
bump_version minor $VERSION_FILE
echo "TAG_NEW=v$(get_version $VERSION_FILE)" >> $GITHUB_ENV
hatch version minor
echo "TAG_NEW=v$(hatch version)" >> $GITHUB_ENV
- name: Bump version (major)
if: contains(github.event.head_commit.message, '#major')
run: |
source .github/workflows/utils.sh
bump_version major $VERSION_FILE
echo "TAG_NEW=v$(get_version $VERSION_FILE)" >> $GITHUB_ENV
hatch version major
echo "TAG_NEW=v$(hatch version)" >> $GITHUB_ENV
- name: Commit files
if:
if: |
contains(github.event.head_commit.message, '#patch') ||
contains(github.event.head_commit.message, '#minor') ||
contains(github.event.head_commit.message, '#major')
Expand All @@ -68,7 +59,7 @@ jobs:
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# commit version bump to release
# Commit version bump to release
git commit -m "Bump version number" -a
git push "${remote_repo}" release
Expand All @@ -77,18 +68,14 @@ jobs:
with:
source_branch: "release" # If blank, default: triggered branch
destination_branch: "dev" # If blank, default: master
pr_title: "Don't forget to merge release back into dev!"
pr_title: "Merge release -> dev to propagate version number bump"
pr_body: "Changes made to the release branch (e.g. hotfixes), plus the version bump."
pr_assignee: "jgostick,ma-sadeghi" # Comma-separated list (no spaces)
pr_label: "high priority" # Comma-separated list (no spaces)
pr_draft: false # Creates pull request as draft
pr_allow_empty: true # Creates pull request even if there are no changes
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Trim the 4th digit from the tag
run:
echo "TAG_NEW=${TAG_NEW%.dev?}" >> $GITHUB_ENV

- name: Create new tag
run: |
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cleanup-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Clean up tags
run: |
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,39 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.8']
python-version: ['3.10']
operating-system: [ubuntu-latest]
# Next line should be [1, 2, ..., max-parallel)
test_group: [1, 2, 3, 4, 5]

steps:
- uses: actions/checkout@v2
- uses: FedericoCarboni/setup-ffmpeg@v2
- uses: actions/checkout@v4
- uses: FedericoCarboni/setup-ffmpeg@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies (pip)
run: |
pip install -r requirements.txt
pip install -r requirements/tests.txt
pip install -r requirements/examples.txt
pip install -e .[test,extras]
- name: Running tests
# Make sure to pass max-parallel to --splits
run: |
pytest examples/ \
pytest \
-p no:python \
--nbval-lax \
--splits ${{ strategy.max-parallel}} \
--group ${{ matrix.test_group }} \
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@ jobs:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'

- name: Cache pip
uses: actions/cache@v2
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies (conda)
run: |
pip install -r requirements.txt
pip install -r requirements/docs.txt
pip install -e .[docs,interactive]
# Build the documentation
- name: Build the documentation
Expand Down
50 changes: 10 additions & 40 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
name: Deploy to PyPI

on:
workflow_dispatch:
push:
tags:
- '*'
- 'v*'

jobs:
deploy:
name: Publish 🐍 📦 to PyPI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: release # the production branch name (for proper version #)
ref: release

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'

- name: Set env variables
run: |
chmod +x .github/workflows/utils.sh
source .github/workflows/utils.sh
VERSION_FILE=porespy/__version__.py
echo "TAG=$(get_most_recent_tag)" >> $GITHUB_ENV
echo "VERSION=$(get_version $VERSION_FILE)" >> $GITHUB_ENV
- name: Set env variables (for tag mismatch)
run: |
echo "Tag: $TAG, Version: $VERSION"
if [ "${TAG//v}" = "${VERSION%.dev?}" ]; then
echo "TAG_MISMATCH=false" >> $GITHUB_ENV
else
echo "TAG_MISMATCH=true" >> $GITHUB_ENV
fi
echo "VERSION=$(hatch version)" >> $GITHUB_ENV
- name: Install dependencies
run: |
Expand All @@ -48,30 +39,9 @@ jobs:
run: python setup.py sdist bdist_wheel

- name: Publish distribution 📦 to PyPI
if: startsWith(github.event.ref, 'refs/tags') && contains(env.TAG_MISMATCH, 'false')
uses: pypa/gh-action-pypi-publish@master
if: startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
skip_existing: true

# - name: Publish distribution 📦 to TestPyPI
# if: startsWith(github.event.ref, 'refs/tags') && contains(env.TAG_MISMATCH, 'false')
# uses: pypa/gh-action-pypi-publish@master
# with:
# user: __token__
# password: ${{ secrets.TESTPYPI_TOKEN }}
# repository_url: https://test.pypi.org/legacy/

# Not a good idea: if a non-conforming tag is push, e.g. random_tag, it
# first gets deleted by cleanup-tags.yml, and then publish-to-pypi.yml gets
# tricked and deletes the most recent tag! Ouch!

# - name: Delete tag if doesn't match with version
# if: contains(env.TAG_MISMATCH, 'true')
# run: |
# git config --local user.email "action@github.com"
# git config --local user.name "GitHub Action"
# REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
# remote_repo="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${REPOSITORY}.git"
# git push "${remote_repo}" :refs/tags/$TAG
skip-existing: true
14 changes: 7 additions & 7 deletions .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0 # to retrieve entire history of refs/tags
fetch-depth: 0 # Retrieve entire history of refs/tags

- name: Generate release notes
- name: get-recent-tag
run: |
git fetch --all --tags --force
chmod +x .github/workflows/logger.sh
chmod +x .github/workflows/utils.sh
source .github/workflows/utils.sh
bash .github/workflows/logger.sh
echo "TAG=$(get_most_recent_tag)" >> $GITHUB_ENV
echo "TAG=$(get_most_recent_tag)" >> $GITHUB_OUTPUT
- name: Create GitHub release
uses: Roang-zero1/github-create-release-action@master
uses: Roang-zero1/github-create-release-action@v3
with:
version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+
create_draft: true
created_tag: ${{ env.TAG }}
created_tag: ${{ steps.get-recent-tag.outputs.TAG }}
update_existing: false
release_title: ${{ env.TAG }}
release_title: ${{ steps.get-recent-tag.outputs.TAG }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Ruff

on: pull_request

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
Loading

0 comments on commit 983fb62

Please sign in to comment.