Release pipeline #131
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: Release pipeline | |
on: | |
workflow_dispatch: | |
inputs: | |
version_bump_type: | |
description: The version bump type to perform. | |
required: true | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
- premajor | |
- preminor | |
- prepatch | |
- prerelease | |
env: | |
IMAGE_NAME: ${{ github.repository }} | |
POETRY_VERSION: "1.8.3" | |
POETRY_VIRTUALENVS_IN_PROJECT: true | |
REGISTRY: ghcr.io | |
jobs: | |
build-and-push-image: | |
environment: | |
name: publish | |
url: https://pypi.org/p/dbt-bouncer | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
id-token: write | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Fetch tags | |
run: git fetch --prune --unshallow --tags | |
- name: Determine python version | |
id: python-version | |
run: | | |
export PYTHON_VERSION=$(cat .python-version) | |
echo "PYTHON_VERSION: $PYTHON_VERSION" | |
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_OUTPUT | |
- name: Setup Python | |
uses: ./.github/actions/setup_python_env | |
with: | |
install-python-deps: 'false' | |
poetry-version: ${{ env.POETRY_VERSION }} | |
python-version: ${{ steps.python-version.outputs.PYTHON_VERSION }} | |
- name: Install version bump Poetry plugin | |
run: poetry self add poetry-bumpversion | |
- name: Bump version | |
run: | | |
poetry version $(git tag --sort version:refname | tail -n 1) | |
poetry version ${{ inputs.version_bump_type }} | |
# Need to re-install dbt-bouncer so version bump is visible when `dbt-bouncer --version` is called | |
- name: Re-install dbt-bouncer | |
run: poetry install | |
- name: Build pex file | |
run: make build-pex | |
- name: Save version to env var | |
id: version | |
run: | | |
echo "version=$(poetry version --short)" >> $GITHUB_OUTPUT | |
echo "major=$(echo $(poetry version --short | cut -d '.' -f 1))" >> $GITHUB_OUTPUT | |
echo "minor=$(echo $(poetry version --short | cut -d '.' -f 2))" >> $GITHUB_OUTPUT | |
echo "patch=$(echo $(poetry version --short | cut -d '.' -f 3))" >> $GITHUB_OUTPUT | |
- name: Determine if prerelease flag is necessary | |
run: | | |
[ "${{ inputs.version_bump_type }}" = "premajor" ] || [ "${{ inputs.version_bump_type }}" = "preminor" ] || [ "${{ inputs.version_bump_type }}" = "prepatch" ] || [ "${{ inputs.version_bump_type }}" = "prerelease" ] && export PRERELEASE="--prerelease" || export PRERELEASE="--latest" | |
echo "PRERELEASE: $PRERELEASE" | |
echo PRERELEASE=$PRERELEASE >> "$GITHUB_ENV" | |
- name: Tag commit and push | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "github-actions[bot]" | |
git checkout -b branch-v${{ steps.version.outputs.version }} | |
git add -A | |
git commit -m "Bumping version to v${{ steps.version.outputs.version }}" | |
# Tag and push X.X.X | |
git tag -f \ | |
-a v${{ steps.version.outputs.version }} \ | |
-m "v${{ steps.version.outputs.version }}" | |
git push -f origin "v${{ steps.version.outputs.version }}" | |
# Tag and push X.X | |
git tag -f \ | |
-a v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }} \ | |
-m "v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}" | |
git push -f origin "v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}" | |
# Tag and push X.X.X | |
git tag -f \ | |
-a v${{ steps.version.outputs.major }} \ | |
-m "v${{ steps.version.outputs.major }}" | |
git push -f origin "v${{ steps.version.outputs.major }}" | |
# Tag and push branch | |
git push -f origin "branch-v${{ steps.version.outputs.version }}" | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=v${{ steps.version.outputs.version }} | |
type=raw,value=v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }} | |
type=raw,value=v${{ steps.version.outputs.major }} | |
type=raw,value=${{ github.sha }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
- name: Build and push image | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
build-args: PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: . | |
load: false | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
- name: Build whl | |
run: poetry build --output dist_pypi | |
- name: Publish package distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: dist_pypi/ | |
- name: Create release | |
env: | |
GH_TOKEN: ${{ secrets.PAT_GITHUB }} | |
run: | | |
export LAST_RELEASE=$(gh release list --repo ${{ github.repository }} --order desc --json name --limit 1 | jq -r '.[0].name') | |
echo $LAST_RELEASE | |
gh release create v${{ steps.version.outputs.version }} \ | |
--generate-notes \ | |
--repo ${{ github.repository }} \ | |
--notes-start-tag $LAST_RELEASE \ | |
--target branch-v${{ steps.version.outputs.version }} \ | |
--title 'v${{ steps.version.outputs.version }}' \ | |
$PRERELEASE \ | |
--verify-tag | |
- name: Upload .pex to release | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: gh release upload v${{ steps.version.outputs.version }} ./dist/dbt-bouncer.pex | |
- name: Checkout `gh-pages` | |
run: git fetch origin gh-pages --depth=1 | |
- name: Deploy docs website | |
run: | | |
poetry run mike deploy --push --update-aliases v${{ steps.version.outputs.version }} stable | |
poetry run mike set-default --push stable |