Merge pull request #156 from pasqal-io/dev #39
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: Publish pasqal-cloud π¦ to PyPI and TestPyPI | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-n-publish: | |
name: Build and publish Python π distributions π¦ to PyPI and TestPyPI | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.8 | |
- name: Install pypa/build | |
run: >- | |
python -m | |
pip install | |
build | |
--user | |
- name: Build a binary wheel and a source tarball | |
run: >- | |
python -m | |
build | |
--sdist | |
--wheel | |
--outdir dist/ | |
- name: Publish distribution π¦ to Test PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PASQAL_CLOUD_TEST_PYPI_TOKEN }} | |
repository_url: https://test.pypi.org/legacy/ | |
- name: Publish distribution π¦ to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PASQAL_CLOUD_PYPI_TOKEN }} | |
create-github-release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
needs: build-n-publish | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Extract version from _version.py | |
id: get_version | |
run: | | |
version=$(python -c "exec(open('pasqal_cloud/_version.py').read()); print(__version__)") | |
echo "VERSION=$version" >> $GITHUB_ENV | |
- name: Get release notes from CHANGELOG.md | |
run: | | |
version=${{ env.VERSION }} | |
# Extract notes from changelog | |
notes=$(awk -v ver="$version" ' | |
BEGIN { found_version=0; leading_blank=1; } | |
/## \[/ { if (found_version) { exit } } | |
/## \['"$version"'\]/ { | |
found_version=1; | |
next | |
} | |
found_version { | |
# Remove the _released line | |
if ($0 ~ /^_released/) { next } | |
# Remove leading ### or ## or # and any additional whitespace | |
gsub(/^#+ +/, "", $0); | |
# Check if the line is blank | |
if ($0 != "") { | |
print $0; # Print the current line | |
leading_blank=0; # Reset leading blank flag | |
} else if (!leading_blank) { | |
print ""; # Print a blank line for subsequent empty lines | |
} | |
} | |
' CHANGELOG.md) | |
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
echo "$notes" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Display release notes | |
run: echo "${{ env.RELEASE_NOTES }}" | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: ${{ env.VERSION }} | |
body: ${{ env.RELEASE_NOTES }} | |
draft: false | |
prerelease: false |