Skip to content

Release and publish #70

Release and publish

Release and publish #70

Workflow file for this run

name: Release and publish
on:
workflow_run:
workflows: [ "Tests" ]
branches: [ main ]
types:
- completed # only release when tests have passed
workflow_dispatch: # or if manually run
jobs:
release:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') }}
# only run when tests have passed (or manually triggered)
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools setuptools_scm wheel
pip install -e .
- name: Check if version has changed
id: check_version
run: |
current_pip_version=$(pip index versions doped | grep LATEST | awk '{print $NF}')
current_repo_version=$(grep version pyproject.toml | awk '{print $NF}' | tr -d '"' | head -1)
if [ "$current_pip_version" != "$current_repo_version" ]; then
echo "version_changed=true" >> $GITHUB_ENV
else
echo "version_changed=false" >> $GITHUB_ENV
fi
- name: Build packages
if: env.version_changed == 'true'
run: |
python3 -m pip install --upgrade build
python3 -m build
- name: Publish
if: env.version_changed == 'true'
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Write release info
if: env.version_changed == 'true'
run: |
awk 'BEGIN {p = 0} {a = 0 }; /^v\d*.\d*.\d*./ { p += 1; a = 1}; p + a == 1 { print } ' CHANGELOG.rst | sed -e '1,1d' | sed -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba' -e '}' > release_info.txt
- name: Get Release Tag
if: env.version_changed == 'true'
run: |
VERSION=$(grep version pyproject.toml | awk '{print $NF}' | tr -d '"' | head -1)
echo "version=${VERSION}" >> $GITHUB_ENV
- name: Release
if: env.version_changed == 'true'
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.version }}
release_name: ${{ env.version }}
body_path: release_info.txt
draft: false
prerelease: false