Skip to content

Merge pull request #6 from soran-ghaderi/soran-ghaderi-patch-1 #16

Merge pull request #6 from soran-ghaderi/soran-ghaderi-patch-1

Merge pull request #6 from soran-ghaderi/soran-ghaderi-patch-1 #16

Workflow file for this run

#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: Automated Tagging and Release
on:
push:
branches:
- master
jobs:
update-tag:
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.create_tag.outputs.new_tag }}
update_type: ${{ steps.get_update_type.outputs.update_type }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get update type from commit message
id: get_update_type
run: |
commit_message="${{ github.event.head_commit.message }}"
if [[ "$commit_message" == *"#major"* ]]; then
echo "update_type=major" >> $GITHUB_OUTPUT
elif [[ "$commit_message" == *"#minor"* ]]; then
echo "update_type=minor" >> $GITHUB_OUTPUT
else
echo "update_type=patch" >> $GITHUB_OUTPUT
fi
- name: Get latest tag
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT
- name: Create new tag
id: create_tag
run: |
latest_tag=${{ steps.get_latest_tag.outputs.latest_tag }}
update_type=${{ steps.get_update_type.outputs.update_type }}
if [ -z "$latest_tag" ]; then
new_tag="v0.1.0"
else
IFS='.' read -ra VERSION <<< "${latest_tag#v}"
major=${VERSION[0]}
minor=${VERSION[1]}
patch=${VERSION[2]}
case $update_type in
major)
major=$((major+1))
minor=0
patch=0
;;
minor)
minor=$((minor+1))
patch=0
;;
patch)
patch=$((patch+1))
;;
esac
new_tag="v$major.$minor.$patch"
fi
echo "new_tag=${new_tag}" >> $GITHUB_OUTPUT
git config user.name github-actions
git config user.email github-actions@github.com
git tag $new_tag
git push origin $new_tag
# =========== it works until here ==================
release:
needs: update-tag
if: contains(github.event.head_commit.message, '#release')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- 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/
- name: Build the package
run: |
python -m pip install --upgrade build
python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
username: __token__
password: ${{ secrets.PYPI_API_TOKEN_EBM }}
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.update-tag.outputs.new_tag }}
release_name: Release ${{ needs.update-tag.outputs.new_tag }}
draft: false
prerelease: false