Change pipeline to publish by pushing a git tag #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy packages to PyPI and Anaconda | ||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
- 'v*.*' | ||
jobs: | ||
# Check that the tag matches the lastest version in the code | ||
check-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Check version | ||
run: | | ||
# Get the latest version from the code | ||
latest_version=$(sed -r 's/__version__ = "(.*)"/\1/' ravenpackapi/version.py) | ||
# Get the tag from the git tag | ||
tag=$(echo $GITHUB_REF | sed -r 's/refs\/tags\/v(.*)/\1/') | ||
# Check that the tag matches the latest version | ||
if [ "$latest_version" != "$tag" ]; then | ||
echo "The tag $tag does not match the latest version $latest_version" | ||
exit 1 | ||
fi | ||
# Build packages | ||
build: | ||
needs: check-version | ||
uses: ./.github/workflows/build.yml | ||
# Anaconda | ||
deploy-conda: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 1 | ||
needs: | ||
- build | ||
steps: | ||
- name: Download the conda dists | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: conda-dist | ||
path: dist/ | ||
- name: Set up Python 3.10 for Anaconda | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.10' | ||
- name: Setup anaconda | ||
run: | | ||
# $CONDA is an environment variable pointing to the root of the miniconda directory | ||
echo $CONDA/bin >> $GITHUB_PATH | ||
conda install --yes anaconda-client | ||
- name: Upload to Anaconda | ||
env: | ||
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }} | ||
run: | | ||
ls | ||
cd dist | ||
ls | ||
anaconda upload --label main osx-64/*.tar.bz2 | ||
anaconda upload --label main linux-64/*.tar.bz2 | ||
anaconda upload --label main win-64/*.tar.bz2 | ||
# Pypi | ||
deploy-pypi: | ||
environment: | ||
name: pypi | ||
url: https://pypi.org/p/ravenpackapi | ||
permissions: | ||
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 1 | ||
needs: | ||
- build | ||
steps: | ||
- name: Download the pypi dists | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: pypi-dist | ||
path: dist/ | ||
- name: Publish package distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
# Create a release | ||
github-release: | ||
needs: deploy-pypi | ||
name: >- | ||
Create a GitHub Release | ||
runs-on: ubuntu-latest | ||
needs: check-version | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Dump the changelog | ||
run: .github/changelogtext.sh > '${{ github.ref_name }}.md' | ||
- name: Create GitHub Release | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
run: | | ||
latest_version=$(sed -r 's/__version__ = "(.*)"/\1/' ravenpackapi/version.py) | ||
gh release create '${{ github.ref_name }}' -F '${{ github.ref_name }}.md' --title "Version $latest_version" --repo '${{ github.repository }}' |