refactor: update pyproject.toml using actions 4 #12
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: Release and Publish | |
# | |
#on: | |
# push: | |
# branches: | |
# - master # Adjust as necessary | |
# | |
#jobs: | |
# release: | |
# runs-on: ubuntu-latest | |
# | |
# steps: | |
# - name: Checkout code | |
# uses: actions/checkout@v3 | |
# | |
# - name: Get latest tag | |
# id: get_latest_tag | |
# run: | | |
# git fetch --tags | |
# TAG=$(git tag --sort=-creatordate | head -n 1) | |
# echo "Latest tag is $TAG" | |
# echo "::set-output name=latest::$TAG" | |
# | |
# - name: Determine new version | |
# id: new_version | |
# run: | | |
# latest_tag="${{ steps.get_latest_tag.outputs.latest }}" | |
# if [ -z "$latest_tag" ]; then | |
# new_version="0.1.0" # No 'v' prefix for version number | |
# else | |
# # Increment the patch version | |
# new_version=$(echo $latest_tag | awk -F. -v OFS=. '{$NF++;print}' | sed 's/^v//') | |
# fi | |
# echo "New version is $new_version" | |
# echo "::set-output name=new_version::$new_version" | |
# | |
# - name: Update pyproject.toml version | |
# run: | | |
# sed -i "s/^version = .*/version = \"${{ steps.new_version.outputs.new_version }}\"/" pyproject.toml | |
# | |
# - name: Create new tag | |
# run: | | |
# git tag "v${{ steps.new_version.outputs.new_version }}" | |
# git push origin "v${{ steps.new_version.outputs.new_version }}" | |
# | |
# - 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 -r requirements.txt | |
# | |
# - name: Set PYTHONPATH | |
# run: echo "PYTHONPATH=$(pwd)/torchebm" >> $GITHUB_ENV | |
# | |
# - name: Install package | |
# run: | | |
# pip install . | |
# | |
# - name: Run tests | |
# run: | | |
# pytest tests/ # Adjust the path to your test directory | |
# | |
# - name: Build the package | |
# run: | | |
# python -m pip install --upgrade build | |
# python -m build # This will create .tar.gz and .whl files in the dist/ directory | |
# | |
# - name: Publish to PyPI | |
# uses: pypa/gh-action-pypi-publish@release/v1 | |
# with: | |
# username: __token__ # Use __token__ for token-based authentication | |
# password: ${{ secrets.PYPI_API_TOKEN_EBM }} | |
name: Release and Publish | |
on: | |
push: | |
branches: | |
- master # Adjust as necessary | |
paths: | |
- 'pyproject.toml' # Trigger on changes to pyproject.toml | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get current version from pyproject.toml | |
id: get_version | |
run: | | |
version=$(grep '^version =' pyproject.toml | sed 's/version = //; s/"//g') | |
echo "Current version is $version" | |
echo "::set-output name=current_version::$version" | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
git fetch --tags | |
TAG=$(git tag --sort=-creatordate | head -n 1) | |
echo "Latest tag is $TAG" | |
echo "::set-output name=latest::$TAG" | |
- name: Determine new version | |
id: new_version | |
run: | | |
latest_tag="${{ steps.get_latest_tag.outputs.latest }}" | |
current_version="${{ steps.get_version.outputs.current_version }}" | |
if [ "$latest_tag" == "$current_version" ]; then | |
echo "No new version detected." | |
exit 1 # Exit if no new version is found | |
else | |
echo "New version detected: $current_version" | |
echo "::set-output name=new_version::$current_version" | |
fi | |
- name: Create new tag | |
run: | | |
git tag "v${{ steps.new_version.outputs.new_version }}" | |
git push origin "v${{ steps.new_version.outputs.new_version }}" | |
- 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 -r requirements.txt | |
- name: Set PYTHONPATH | |
run: echo "PYTHONPATH=$(pwd)/torchebm" >> $GITHUB_ENV | |
- name: Install package | |
run: | | |
pip install . | |
- name: Run tests | |
run: | | |
pytest tests/ # Adjust the path to your test directory | |
- name: Build the package | |
run: | | |
python -m pip install --upgrade build | |
python -m build # This will create .tar.gz and .whl files in the dist/ directory | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
username: __token__ # Use __token__ for token-based authentication | |
password: ${{ secrets.PYPI_API_TOKEN_EBM }} |