-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (121 loc) · 4.28 KB
/
Copy pathrelease.yml
File metadata and controls
133 lines (121 loc) · 4.28 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
# Release workflow for the python-sdk.
#
# Triggered by tag-release.yml (workflow_dispatch at the new tag) or by a
# manually pushed `v*` tag. Builds the sdist/wheel, publishes to PyPI via a
# Trusted Publisher (OIDC - no stored API token), and creates a GitHub Release
# whose body is the matching section from CHANGELOG.md with auto-generated
# commit notes appended.
#
# ----------------------------------------------------------------------------
# Trusted Publishing setup (do this once on PyPI - no secrets in GitHub):
# https://docs.pypi.org/trusted-publishers/
#
# On https://pypi.org, add a GitHub Actions trusted publisher to the
# `chatbotkit` project (Manage -> Publishing) with these exact values:
# Owner: chatbotkit
# Repository name: python-sdk
# Workflow name: release.yml
# Environment name: pypi
#
# For the very first release (the project does not exist on PyPI yet) use a
# "pending" publisher instead: https://pypi.org/manage/account/publishing/
# with the same four values plus the project name `chatbotkit`.
#
# Also create a GitHub Environment named `pypi` on the python-sdk repo
# (Settings -> Environments) to match `environment.name` below. Configure it:
# - Deployment branches and tags -> "Selected" -> add a tag rule `v*`.
# This is what enforces "release only from a tag": a manual workflow_dispatch
# off `next`/`main` is blocked at this gate, so no OIDC token is minted and
# nothing is uploaded. Publishing can only happen from a `v*` tag ref.
# - Optionally add required reviewers for a manual approval gate before upload.
# ----------------------------------------------------------------------------
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
# No permissions by default; each job requests only what it needs.
permissions: {}
jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build sdist and wheel
run: |
python -m pip install --upgrade pip
pip install build twine
python -m build
twine check dist/*
- name: Extract changelog section for this version
run: |
VERSION="${GITHUB_REF_NAME#v}"
if [ -f CHANGELOG.md ]; then
awk -v ver="$VERSION" '
$0 ~ ("^## \\[" ver "\\]") { capture = 1; next }
capture && /^## \[/ { exit }
capture { print }
' CHANGELOG.md > release-notes.md
fi
if [ ! -s release-notes.md ]; then
echo "Release v${VERSION}. See the full changelog in CHANGELOG.md." > release-notes.md
fi
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
- name: Upload release notes
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release-notes.md
publish-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
# The Trusted Publisher on PyPI is scoped to this environment name.
environment:
name: pypi
url: https://pypi.org/p/chatbotkit
# OIDC: mint the short-lived token PyPI exchanges for upload rights.
# This job intentionally does nothing else (no checkout of repo code) so the
# id-token can never be exfiltrated by build/test steps.
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: Create GitHub Release
needs: [build, publish-pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download release notes
uses: actions/download-artifact@v4
with:
name: release-notes
path: .
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: release-notes.md
generate_release_notes: true