Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubleshoot auto publishing #22

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,42 @@ jobs:
id: get_version
run: |
VERSION=$(poetry version --short)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" | tee -a $GITHUB_ENV
- name: Fetch latest tag
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0")
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "LATEST_TAG=$LATEST_TAG" | tee -a $GITHUB_ENV
- name: Detect version change
run: |
# Retrieve and strip "v" prefix if present
PREVIOUS_VERSION="${{ env.LATEST_TAG }}"
CURRENT_VERSION="${{ env.VERSION }}"
LATEST_VERSION="${{ env.LATEST_TAG }}"
CURRENT_VERSION="${CURRENT_VERSION#v}"
LATEST_VERSION="${LATEST_VERSION#v}"

echo "PREVIOUS_VERSION=$PREVIOUS_VERSION"
echo "CURRENT_VERSION=$CURRENT_VERSION"

# Extract major.minor for comparison
CURRENT_MAJOR_MINOR=$(echo "$CURRENT_VERSION" | cut -d '.' -f 1-2)
LATEST_MAJOR_MINOR=$(echo "$LATEST_VERSION" | cut -d '.' -f 1-2)
CURRENT_MAJOR_MINOR=$(echo "${CURRENT_VERSION#v}" | cut -d '.' -f 1-2)
PREVIOUS_MAJOR_MINOR=$(echo "${PREVIOUS_VERSION#v}" | cut -d '.' -f 1-2)

# Compare versions
if [ "$CURRENT_MAJOR_MINOR" == "$LATEST_MAJOR_MINOR" ]; then
echo "VERSION_CHANGE=false" >> $GITHUB_ENV
if [ "$CURRENT_MAJOR_MINOR" == "$PREVIOUS_MAJOR_MINOR" ]; then
echo "VERSION_CHANGE=false" | tee -a $GITHUB_ENV
else
echo "VERSION_CHANGE=true" >> $GITHUB_ENV
echo "VERSION_CHANGE=true" | tee -a $GITHUB_ENV
fi
shell: bash
env:
VERSION: ${{ env.VERSION }} # dynamically passed VERSION variable
LATEST_TAG: ${{ env.LATEST_TAG }} # dynamically passed LATEST_TAG variable
- name: Build PyPi package
if: github.ref == 'refs/heads/main' && env.VERSION_CHANGE == 'true'
if: github.ref == 'refs/heads/master'
run: python -m build
- name: Publish PyPi package
if: github.ref == 'refs/heads/main' && env.VERSION_CHANGE == 'true'
if: github.ref == 'refs/heads/master'
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Tag the release if major or minor version changed
if: github.ref == 'refs/heads/main' && env.VERSION_CHANGE == 'true'
if: github.ref == 'refs/heads/master'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lint.ignore = ["E402", "E713", "E721", "E741", "F401", "F403", "F405"]
[tool.poetry-dynamic-versioning]
enable = true
metadata = false
format-jinja = 'v3.1.{{ distance }}'
format-jinja = 'v3.0.{{ distance }}'

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
Expand Down
Loading