Skip to content

Commit bac2ddf

Browse files
authored
PYTHON-4417 Refactor publish job (#76)
1 parent c5eac65 commit bac2ddf

File tree

7 files changed

+291
-203
lines changed

7 files changed

+291
-203
lines changed

.github/actions/bump/action.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Bump and Tag
2+
description: "Bump Version and Create Tag"
3+
inputs:
4+
version:
5+
description: "The next version to set"
6+
post_version:
7+
description: "The post version to set"
8+
app_id:
9+
description: "The app id of the bot"
10+
private_key:
11+
description: "The private key of the bot"
12+
garasign_username:
13+
description: "The garasign username"
14+
garasign_password:
15+
description: "The garasign password"
16+
artifactory_username:
17+
description: "The artifactory username"
18+
artifactory_password:
19+
description: "The artifactory password"
20+
gpg_key_id:
21+
description: "The gpg key id"
22+
dry_run:
23+
description: "Whether this is a dry run"
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- uses: actions/create-github-app-token@v1
29+
id: app-token
30+
with:
31+
app-id: ${{ inputs.app_id }}
32+
private-key: ${{ inputs.app_private_key }}
33+
34+
- uses: actions/checkout@v4
35+
with:
36+
token: ${{ steps.app-token.outputs.token }}
37+
38+
- uses: actions/setup-python@v4
39+
with:
40+
python-version: '3.11'
41+
42+
- name: Set up Git Config
43+
shell: bash
44+
run: |
45+
# Use the GitHub Actions bot as the actor.
46+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
47+
git config user.name "github-actions[bot]"
48+
49+
- name: Set up new version
50+
shell: bash
51+
run: |
52+
export CURRENT_VERSION=$(python setup.py --version)
53+
export NEW_VERSION=${{inputs.version}}
54+
sed -i "s/version = \"${CURRENT_VERSION}\"/version = \"${NEW_VERSION}\"/" pyproject.toml
55+
git add .
56+
57+
- name: Commit the new version
58+
uses: mongodb-labs/drivers-github-tools/garasign/git-sign@main
59+
with:
60+
command: git commit -a -m "BUMP ${{ inputs.version }}" -s --gpg-sign=${{ inputs.gpg_key_id }}
61+
garasign_username: ${{ inputs.garasign_username }}
62+
garasign_password: ${{ inputs.garasign_password }}
63+
artifactory_username: ${{ inputs.art_user }}
64+
artifactory_password: ${{ inputs.art_password }}
65+
66+
- name: Tag the new version
67+
uses: mongodb-labs/drivers-github-tools/garasign/git-sign@main
68+
with:
69+
command: git tag -a "${{ inputs.version }}" -m "BUMP ${{ inputs.version }}" -s --local-user=${{ inputs.gpg_key_id }}
70+
garasign_username: ${{ inputs.garasign_username }}
71+
garasign_password: ${{ inputs.garasign_password }}
72+
artifactory_username: ${{ inputs.artifactory_user }}
73+
artifactory_password: ${{ inputs.artifactory_password }}
74+
skip_setup: true
75+
76+
- name: Set up the post version
77+
shell: bash
78+
run: |
79+
export CURRENT_VERSION=${{ inputs.version }}
80+
export NEW_VERSION=${{ inputs.post_verion }}
81+
sed -i "s/version = \"${CURRENT_VERSION}\"/version = \"${NEW_VERSION}\"/" pyproject.toml
82+
git add .
83+
84+
- name: Commit the post version
85+
uses: mongodb-labs/drivers-github-tools/garasign/git-sign@main
86+
with:
87+
command: git commit -a -m "BUMP ${{ inputs.post_verion }}" -s --gpg-sign=${{ inputs.gpg_key_id }}"
88+
garasign_username: ${{ inputs.garasign_username }}
89+
garasign_password: ${{ inputs.garasign_password }}
90+
artifactory_username: ${{ inputs.artifactory_user }}
91+
artifactory_password: ${{ inputs.artifactory_password }}
92+
skip_setup: true
93+
94+
- name: Verify the tag
95+
shell: bash
96+
run: |
97+
curl -O https://pgp.mongodb.com/python-driver.pub
98+
gpg --import python-driver.pub
99+
git verify-tag ${{inputs.version}}
100+
rm python-driver.pub
101+
102+
- name: Push the version and tags to the source branch
103+
shell: bash
104+
run: |
105+
if [ -n "$(git status --porcelain)" ]; then
106+
echo "Uncommitted changes!"
107+
git status --porcelain
108+
exit 1
109+
fi
110+
if [ ${{ inputs.dry_run }} != "true" ]; then
111+
git push origin --tags
112+
git push origin
113+
fi

.github/actions/publish/action.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
name: Publish
3+
description: "Asset Publish Action"
4+
inputs:
5+
garasign_username:
6+
description: "The garasign username"
7+
garasign_password:
8+
description: "The garasign password"
9+
artifactory_username:
10+
description: "The artifactory username"
11+
artifactory_password:
12+
description: "The artifactory password"
13+
token:
14+
description: "The GitHub access token"
15+
dry_run:
16+
description: "Whether this is a dry run"
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Download all the dists
23+
uses: actions/download-artifact@v3
24+
with:
25+
name: all-dist-${{ github.run_id }}
26+
path: dist/
27+
- name: Get the list of dist files to sign
28+
shell: bash
29+
run: |
30+
export dist_files=$(ls dist/*)
31+
echo "DIST_FILES=\"${dist_files}\"" >> $GITHUB_ENV
32+
- uses: mongodb-labs/drivers-github-tools/garasign/ggp-sign@main
33+
with:
34+
garasign_username: ${{ inputs.garasign_username }}
35+
garasign_password: ${{ inputs.garasign_password }}
36+
artifactory_username: ${{ inputs.artifactory_user }}
37+
artifactory_password: ${{ inputs.artifactory_password }}
38+
filenames: ${{ env.DIST_FILES }}
39+
- name: Move the signature files to a separate directory
40+
shell: bash
41+
run: |
42+
mkdir signatures
43+
mv dist/*.sig signatures
44+
- name: Create a draft release with release files
45+
shell: bash
46+
if: inputs.dry_run == 'false'
47+
env:
48+
GH_TOKEN: ${{ inputs.token }}
49+
run: |
50+
gh release create ${{ github.ref_name }} --draft --verify-tag --title ${{ github.ref_name }} --notes ""
51+
gh release upload ${{ github.ref_name }} signatures/*.sig
52+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi
53+
- name: Publish distribution 📦 to PyPI
54+
if: inputs.dry_run == 'false'
55+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/setup-python@v3
1414
- uses: pre-commit/[email protected]
1515
with:
16-
extra_args: --hook-stage manual
16+
extra_args: --all-files --hook-stage manual
1717
- run: |
1818
sudo apt-get install -y cppcheck
1919
- run: |

.github/workflows/bump-version.yml

Lines changed: 0 additions & 80 deletions
This file was deleted.

.github/workflows/dist.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Dist
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
workflow_call:
8+
pull_request:
9+
10+
concurrency:
11+
group: dist-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build_wheels:
16+
name: "Build Wheels ${{ matrix.buildplat }}"
17+
runs-on: windows-2019
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
buildplat: ["win_amd64", "win32"]
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Build wheels
25+
uses: pypa/[email protected]
26+
env:
27+
CIBW_BUILD: "cp3*-${{ matrix.buildplat }}"
28+
CIBW_PRERELEASE_PYTHONS: "True"
29+
CIBW_TEST_COMMAND: "python -c \"import winkerberos;print(winkerberos.__version__)\""
30+
31+
- name: Assert all versions in wheelhouse
32+
if: ${{ ! startsWith(matrix.buildplat[1], 'macos') }}
33+
run: |
34+
ls wheelhouse/*cp37*.whl
35+
ls wheelhouse/*cp38*.whl
36+
ls wheelhouse/*cp39*.whl
37+
ls wheelhouse/*cp310*.whl
38+
ls wheelhouse/*cp311*.whl
39+
ls wheelhouse/*cp312*.whl
40+
41+
- uses: actions/upload-artifact@v3
42+
with:
43+
name: wheel-${{ matrix.buildplat }}
44+
path: ./wheelhouse/*.whl
45+
46+
make_sdist:
47+
name: Make SDist
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v3
51+
52+
- uses: actions/setup-python@v4
53+
with:
54+
# Build sdist on lowest supported Python
55+
python-version: '3.7'
56+
57+
- name: Build SDist
58+
run: |
59+
pip install check-manifest build
60+
check-manifest -v
61+
python -m build --sdist .
62+
63+
- uses: actions/upload-artifact@v3
64+
with:
65+
name: "sdist"
66+
path: dist/*.tar.gz
67+
68+
collect_dist:
69+
runs-on: ubuntu-latest
70+
needs: [build_wheels, make_sdist]
71+
name: Download Wheels
72+
steps:
73+
- name: Download all workflow run artifacts
74+
uses: actions/download-artifact@v3
75+
- name: Flatten directory
76+
working-directory: .
77+
run: |
78+
find . -mindepth 2 -type f -exec mv {} . \;
79+
find . -type d -empty -delete
80+
- uses: actions/upload-artifact@v3
81+
with:
82+
name: all-dist-${{ github.run_id }}
83+
path: "./*"

0 commit comments

Comments
 (0)