-
Notifications
You must be signed in to change notification settings - Fork 59
182 lines (159 loc) Β· 6.64 KB
/
pypi-publish.yml
File metadata and controls
182 lines (159 loc) Β· 6.64 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
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
182
name: Publish Python Package to PyPI
on:
push:
branches:
- main
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Stable version to publish manually (for example: 1.0.0)"
required: false
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
publish:
if: github.repository == 'agentic-in/elephant-agent'
runs-on: ubuntu-latest
environment: PYPI_API_TOKEN
permissions:
contents: write
id-token: write
attestations: write
artifact-metadata: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Setup uv
uses: astral-sh/setup-uv@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: |
apps/site/package-lock.json
apps/dashboard/package-lock.json
- name: Extract version from tag, input, or pyproject
id: extract_version
env:
INPUT_VERSION: ${{ inputs.version || '' }}
run: |
python <<'PY'
from __future__ import annotations
import os
import re
from datetime import datetime, timezone
from pathlib import Path
import tomllib
pyproject = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))
current = pyproject["project"]["version"]
base = re.sub(r"\.dev\d+$", "", current)
ref = os.environ.get("GITHUB_REF", "")
event_name = os.environ.get("GITHUB_EVENT_NAME", "")
input_version = os.environ.get("INPUT_VERSION", "").strip()
github_output = Path(os.environ["GITHUB_OUTPUT"])
if event_name == "workflow_dispatch" and input_version:
version = input_version
tag = f"v{version}"
is_dev = "false"
elif ref.startswith("refs/tags/"):
tag = ref.split("/", 2)[-1]
version = tag[1:] if tag.startswith("v") else tag
is_dev = "false"
else:
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d%H%M%S")
version = f"{base}.dev{timestamp}"
tag = f"v{version}"
is_dev = "true"
with github_output.open("a", encoding="utf-8") as handle:
handle.write(f"version={version}\n")
handle.write(f"tag={tag}\n")
handle.write(f"is_dev={is_dev}\n")
handle.write(f"base_version={base}\n")
handle.write(f"commit_sha={os.environ.get('GITHUB_SHA', '')}\n")
PY
- name: Update package version for this publish
run: |
python <<'PY'
from pathlib import Path
import re
target = "${{ steps.extract_version.outputs.version }}"
path = Path("pyproject.toml")
content = path.read_text(encoding="utf-8")
updated = re.sub(r'^version = ".*"$', f'version = "{target}"', content, count=1, flags=re.MULTILINE)
path.write_text(updated, encoding="utf-8")
print(updated.splitlines()[6])
PY
- name: Build and verify release package
run: |
make package-build
make package-verify
- name: Attest Python release artifacts
uses: actions/attest@v4
with:
subject-checksums: dist/SHA256SUMS
- name: Publish to PyPI
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.version != '')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
if [ -z "${TWINE_PASSWORD}" ]; then
echo "::error::Missing PYPI_API_TOKEN for the publish job. Configure it as an environment secret on the PYPI_API_TOKEN environment or as a repo Actions secret."
exit 1
fi
uvx twine upload --skip-existing --verbose dist/*.whl dist/*.tar.gz
- name: Create GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.extract_version.outputs.tag }}
name: elephant ${{ steps.extract_version.outputs.tag }}
draft: false
prerelease: false
generate_release_notes: true
body: |
## Install
```bash
curl -fsSL https://elephant.agentic-in.ai/install.sh | bash -s -- --channel stable
```
Or pin the published package directly:
```bash
pip install elephant-agent==${{ steps.extract_version.outputs.version }}
```
## Provenance
Commit SHA: `${{ steps.extract_version.outputs.commit_sha }}`
Package version: `${{ steps.extract_version.outputs.version }}`
Checksums: see `SHA256SUMS` and `elephant-agent-provenance.json`
GitHub artifact attestation: generated by `actions/attest@v4` from `dist/SHA256SUMS`
files: |
dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
echo "## Elephant Agent package published" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Version:** ${{ steps.extract_version.outputs.version }}" >> "$GITHUB_STEP_SUMMARY"
echo "**Commit:** ${{ steps.extract_version.outputs.commit_sha }}" >> "$GITHUB_STEP_SUMMARY"
echo "**Type:** $(if [ '${{ steps.extract_version.outputs.is_dev }}' = 'true' ]; then echo 'development'; else echo 'stable'; fi)" >> "$GITHUB_STEP_SUMMARY"
echo "**Provenance:** dist/elephant-agent-provenance.json" >> "$GITHUB_STEP_SUMMARY"
echo "**Checksums:** dist/SHA256SUMS" >> "$GITHUB_STEP_SUMMARY"
echo "**GitHub attestation:** actions/attest@v4 with subject-checksums=dist/SHA256SUMS" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### Remote install" >> "$GITHUB_STEP_SUMMARY"
echo '```bash' >> "$GITHUB_STEP_SUMMARY"
if [ "${{ steps.extract_version.outputs.is_dev }}" = "true" ]; then
echo "curl -fsSL https://elephant.agentic-in.ai/install.sh | bash" >> "$GITHUB_STEP_SUMMARY"
else
echo "curl -fsSL https://elephant.agentic-in.ai/install.sh | bash -s -- --channel stable" >> "$GITHUB_STEP_SUMMARY"
fi
echo '```' >> "$GITHUB_STEP_SUMMARY"