Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

PyPI Release

PyPI Release #169

# This workflow will update the latest version with minor release and upload a package to PyPi
name: PyPI Release
on:
workflow_dispatch:
inputs:
package:
description: Package
required: false
default: dbt-fal
type: choice
options:
- dbt-fal
version:
description: Version
required: false
default: patch
type: choice
options:
- prerelease
- patch
- minor
- major
publish_from_any_branch:
description: Publish from any branch
required: false
default: false
type: boolean
jobs:
deploy:
# Run only for `release` branch or if marked as acceptable
if: github.ref == 'refs/heads/release' || inputs.publish_from_any_branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Package setup
run: |
if [[ ${{ inputs.package }} == dbt-fal ]]
then
echo "PACKAGE_DIR=projects/adapter" >> $GITHUB_ENV
echo "TAG_PREFIX=adapter-v" >> $GITHUB_ENV
fi
- name: Install poetry
shell: bash
run: pip install poetry=="1.4.2"
- name: Bump to publishing version
working-directory: ${{ env.PACKAGE_DIR }}
shell: bash
run: |
VERSION_TYPE="${{ inputs.version }}"
if [[ ! "$VERSION_TYPE" == prerelease ]]
then
# Don't bump for prereleases, publish them
poetry version $VERSION_TYPE
fi
# version has format '0.4.1'
publishing_version=$(poetry version -s)
echo "publishing_version=$publishing_version" >> $GITHUB_ENV
# tag has format 'v0.4.0' (note the 'v')
prev_version_tag=$(git describe --tags --match '${{ env.TAG_PREFIX }}*' --abbrev=0)
echo "prev_version_tag=$prev_version_tag" >> $GITHUB_ENV
# set __version__.py files in src directory
VERSION_FILE_CONTENT="version = '$publishing_version'"
VERSION_FILES=$(find src -name __version__.py)
for FILE_PATH in $VERSION_FILES; do
echo $VERSION_FILE_CONTENT > $FILE_PATH
done
- name: Build package
working-directory: ${{ env.PACKAGE_DIR }}
shell: bash
env:
PYPI_USERNAME: ${{ secrets.PYPI_USER }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: poetry build
- name: Generate a changelog
uses: orhun/[email protected]
id: git-cliff
with:
config: ${{ env.PACKAGE_DIR }}/cliff.toml
args: ${{ env.prev_version_tag }}..${{ github.ref }}
env:
OUTPUT: CHANGES.md
- name: Set the release body
id: release
shell: bash
run: |
r=$(cat ${{ steps.git-cliff.outputs.changelog }})
r="${r//'%'/'%25'}" # Multiline escape sequences for %
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
echo "::set-output name=RELEASE_BODY::$r"
- name: Publish GitHub
uses: softprops/action-gh-release@v1
with:
name: ${{ inputs.package }} ${{ env.publishing_version }}
body: ${{ steps.release.outputs.RELEASE_BODY }}
tag_name: ${{ env.TAG_PREFIX }}${{ env.publishing_version }}
files: |
${{ env.PACKAGE_DIR }}/dist/${{ inputs.package }}-${{ env.publishing_version }}-py3-none-any.whl
${{ env.PACKAGE_DIR }}/dist/${{ inputs.package }}-${{ env.publishing_version }}.tar.gz
- name: Publish PyPI
working-directory: ${{ env.PACKAGE_DIR }}
env:
PYPI_USERNAME: ${{ secrets.PYPI_USER }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: poetry publish -u $PYPI_USERNAME -p $PYPI_PASSWORD -v -n
- name: Clear the repo untracked files
run: git clean -fxd
- name: Bump repo version
working-directory: ${{ env.PACKAGE_DIR }}
run: |
poetry version prerelease
# set __version__.py files in src directory
VERSION=$(poetry version -s)
VERSION_FILE_CONTENT="version = '$VERSION'"
VERSION_FILES=$(find src -name __version__.py)
for FILE_PATH in $VERSION_FILES; do
echo $VERSION_FILE_CONTENT > $FILE_PATH
done
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
if: inputs.package == 'dbt-fal'
with:
branch: bump-${{ inputs.package }}-${{ env.publishing_version }}
delete-branch: true
title: Bump the pyproject.toml ${{ inputs.package }} version
base: main
token: ${{ secrets.RELEASER_GITHUB_PAT }}
body: ${{ steps.release.outputs.RELEASE_BODY }}