Skip to content

Remove duplicate indices calc #12

Remove duplicate indices calc

Remove duplicate indices calc #12

Workflow file for this run

name: Publish to GitHub and PyPI
on:
workflow_dispatch:
push:
branches: [master]
paths:
- "src/flash_head/_version.py"
permissions:
contents: write
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
should_release: ${{ steps.check.outputs.should_release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get current version
id: get_version
run: |
VERSION=$(python3 -c "exec(open('src/flash_head/_version.py').read()); print(__version__)")
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Check if version changed and release is needed
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="v${{ steps.get_version.outputs.version }}"
# Manual trigger — skip diff check, only check for duplicate
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
if gh release view "${TAG}" --repo "${{ github.repository }}" > /dev/null 2>&1; then
echo "Release ${TAG} already exists — skipping."
echo "should_release=false" >> "$GITHUB_OUTPUT"
else
echo "should_release=true" >> "$GITHUB_OUTPUT"
fi
exit 0
fi
# Check if this version was already released
if gh release view "${TAG}" --repo "${{ github.repository }}" > /dev/null 2>&1; then
echo "Release ${TAG} already exists — skipping."
echo "should_release=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Check if __version__ actually changed in this push
if git rev-parse HEAD~1 > /dev/null 2>&1; then
if git diff HEAD~1 HEAD -- src/flash_head/_version.py | grep -q '^[+-]__version__'; then
echo "should_release=true" >> "$GITHUB_OUTPUT"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
else
# First commit — release if _version.py exists
echo "should_release=true" >> "$GITHUB_OUTPUT"
fi
release:
runs-on: ubuntu-latest
needs: check-version
if: needs.check-version.outputs.should_release == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Build release distributions
run: |
python -m pip install build
python -m build
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v${{ needs.check-version.outputs.version }}" \
--repo "${{ github.repository }}" \
--title "v${{ needs.check-version.outputs.version }}" \
--generate-notes \
dist/*
pypi-publish:
runs-on: ubuntu-latest
needs:
- check-version
- release
permissions:
contents: read
id-token: write
environment:
name: pypi
url: https://pypi.org/p/flash-head
steps:
- name: Download release assets
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir dist
gh release download "v${{ needs.check-version.outputs.version }}" \
--repo "${{ github.repository }}" \
--dir dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/