forked from kudryk/dbt-postgres-python
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (131 loc) · 4.8 KB
/
python-release.yml
File metadata and controls
155 lines (131 loc) · 4.8 KB
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
# 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-postgres-python
type: choice
options:
- dbt-postgres-python
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
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Package setup
run: |
if [[ ${{ inputs.package }} == dbt-postgres-python ]]
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.5.0"
- 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
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@v2
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
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ${{ env.PACKAGE_DIR }}/dist/
- 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-postgres-python'
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 }}