Skip to content

ci: fix branch check #29

ci: fix branch check

ci: fix branch check #29

Workflow file for this run

name: Publish to PyPI
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-n-publish:
name: Publish to PyPI
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
submodules: true
# versioneer.py requires the latest tag to be reachable. Here we
# fetch the complete history to get access to the tags.
# A shallow clone can work when the following issue is resolved:
# https://github.com/actions/checkout/issues/338
fetch-depth: 0
- name: Check branch for tag
run: |
BRANCH_NAME=$(git branch --contains ${{ github.ref }} | sed 's/^[* ]*//' | grep -E 'main|master' | xargs)
if [[ -z "$BRANCH_NAME" ]]; then
echo "##[error]Tag is not in main or master branch."
exit 1
fi
- name: Fetch the latest tag
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Latest tag is $LATEST_TAG"
git checkout $LATEST_TAG
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '8'
- name: Compile Java files
run: |
java -version
javac src/actipy/*.java
- name: Set up Python
uses: actions/setup-python@v5
with:
# python-version: "3.x"
python-version: "3.11" # setuptools not working in 3.12
- name: Build source and wheel distributions
run: |
python -m pip install --upgrade pip wheel twine tomli
python setup.py sdist bdist_wheel
twine check --strict dist/*
- name: Sanity check build
run: |
python -m pip install dist/*.gz
python -c "import actipy; print(actipy.__version__)"
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
--generate-notes