-
Notifications
You must be signed in to change notification settings - Fork 2
181 lines (154 loc) · 7.54 KB
/
release_pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---
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: "2.0.1"
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