-
Notifications
You must be signed in to change notification settings - Fork 88
136 lines (119 loc) · 4.38 KB
/
publish-to-pypi.yaml
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
name: Publish to PyPI
on:
workflow_call:
secrets:
PYPI_USERNAME:
required: true
PYPI_PASSWORD:
required: true
inputs:
ref:
description: 'Git ref to build (branch name or SHA)'
required: true
type: string
default: 'main'
releaseLevel:
description: 'Release level'
required: true
type: string
default: 'patch'
isPrerelease:
description: 'Whether this is a prerelease'
required: true
type: boolean
default: true
prereleaseSuffix:
description: 'Suffix to add onto the new version number in order to mark it as a prerelease. Value ignored when shipping a release that is not a prerelease.'
required: false
type: string
default: 'rc1'
TWINE_REPOSITORY:
description: 'PyPI repository'
required: true
type: string
default: 'pypi' # options are: pypi, testpypi
jobs:
pypi:
timeout-minutes: 30
name: pypi
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history and tags to compute list of commits in release
ref: ${{ inputs.ref }}
- name: Verify prereleaseSuffix not empty if isPrerelease is true
if: ${{ inputs.isPrerelease == true }}
run: |
if [ -z "${{ inputs.prereleaseSuffix }}" ]; then
echo "prereleaseSuffix cannot be empty if isPrerelease is true"
exit 1
fi
- name: Bump version
id: bump
uses: './.github/actions/bump-version'
with:
versionFile: pinecone/__version__
bumpType: ${{ inputs.releaseLevel }}
prereleaseSuffix: ${{ inputs.prereleaseSuffix }}
- name: Verify unique release number
run: |
TAG_NAME=${{ steps.bump.outputs.VERSION_TAG }}
if git rev-parse -q --verify "refs/tags/$TAG_NAME" >/dev/null; then
echo "Tag $TAG_NAME already exists."
exit 1
fi
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Setup Poetry
uses: ./.github/actions/setup-poetry
- name: Set up Git
run: |
git config --global user.name "Pinecone CI"
git config --global user.email "[email protected]"
- name: Poetry bump pyproject toml version
run: |
poetry version ${{ steps.bump.outputs.version }}
- name: Build Python client
run: make package
- name: Upload Python client to PyPI
id: pypi_upload
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
TWINE_REPOSITORY: ${{ inputs.TWINE_REPOSITORY }}
run: make upload
- name: Discard changes, if prerelease
if: ${{ inputs.isPrerelease == true }}
run: |
git checkout pinecone/__version__
- name: Commit changes, if not prerelease
if: ${{ inputs.isPrerelease == false }}
run: |
# Add the original pinecone client version file to git
# Even though Poetry is now the preferred means of working
# with this project, since this __version__ file has been the
# one source of truth for our release process. We need to maintain
# both files for the time being, and they should always contain the
# identical package version
git add pinecone/__version__
# Add also the pyproject.toml, which is Poetry's source of truth, so
# that we maintain the exact same version across the two files
git add pyproject.toml
git commit -m "[skip ci] Bump version to ${{ steps.bump.outputs.VERSION_TAG }}"
- name: Tag version
run: |
newVersionTag="${{ steps.bump.outputs.VERSION_TAG }}"
git tag -a $newVersionTag -m "Release $newVersionTag"
- name: Push tags (prerelease)
if: ${{ inputs.isPrerelease == true }}
# In the case of the prerelease, we discarded the version changes
# instead of committing them. So we need a slightly different
# command to push the git tag we created.
run: git push --tags
- name: Push tags (production release)
if: ${{ inputs.isPrerelease == false }}
run: git push --follow-tags