Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 174 additions & 80 deletions .github/workflows/sandbox-mcp-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,183 @@ on:
default: 'dev'
type: choice
options:
- 'dev' # Development release (with date+commit)
- 'formal' # Formal release (use exact version from pyproject.toml)
- 'dev'
- 'formal'

permissions:
contents: read
id-token: write
attestations: write # Added for attestation support
permissions: {}

jobs:
publish-to-pypi:
runs-on: ubuntu-latest
environment:
name: 'pypi-production'
url: https://pypi.org/project/mcp-server-plaid
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
dist-sha256: ${{ steps.digest.outputs.sha256 }}
env:
UV_PYTHON: '3.11.14'
UV_PYTHON_PREFERENCE: only-managed
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Verify uv installation
run: uv --version

- name: Generate version and ensure required metadata
id: generate_version
working-directory: ./sandbox
run: |
# Get current Unix epoch time (seconds since January 1, 1970)
EPOCH_TIME=$(date +%s)

# Check if version is already defined in pyproject.toml
if grep -q "version =" "pyproject.toml"; then
# Read the current base version (remove any existing suffixes)
CURRENT_VERSION=$(grep "version =" "pyproject.toml" | sed -E 's/version *= *"([^"-]+).*/\1/')
echo "Base version from pyproject.toml: $CURRENT_VERSION"

# Handle different release types
if [ "${{ github.event.inputs.release_type }}" = "formal" ]; then
# For formal release, use version exactly as in pyproject.toml
FINAL_VERSION="${CURRENT_VERSION}"
echo "Formal release - using exact version: $FINAL_VERSION"
else
# For dev release, append -dev-epochtime format
FINAL_VERSION="${CURRENT_VERSION}-dev-${EPOCH_TIME}"
echo "Dev release - using version with epoch timestamp: $FINAL_VERSION"
fi

# Update version in pyproject.toml
sed -i -E "s/version *= *\"[^\"]+\"/version = \"$FINAL_VERSION\"/" pyproject.toml

# Output version for later steps
echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
else
# If no version defined, add initial version
if [ "${{ github.event.inputs.release_type }}" = "formal" ]; then
FINAL_VERSION="0.1.0"
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false

- name: Use fresh tool and build caches
run: |
echo "UV_PYTHON_INSTALL_DIR=$RUNNER_TEMP/release-python" >> "$GITHUB_ENV"
echo "UV_CACHE_DIR=$RUNNER_TEMP/release-uv-cache" >> "$GITHUB_ENV"

- name: Install verified uv
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
with:
version: '0.13.5'
checksum: f68d291c75783122dad58ab77def0e13f3233f358731db5d6d7e8715603b928f
enable-cache: false

- name: Install verified Python
# The pinned uv release contains the Python download URL and SHA-256.
run: uv python install 3.11.14

- name: Generate version and ensure required metadata
id: generate_version
working-directory: ./sandbox
env:
RELEASE_TYPE: ${{ inputs.release_type }}
run: |
# Get current Unix epoch time (seconds since January 1, 1970)
EPOCH_TIME=$(date +%s)

# Check if version is already defined in pyproject.toml
if grep -q "version =" "pyproject.toml"; then
# Read the current base version (remove any existing suffixes)
CURRENT_VERSION=$(grep "version =" "pyproject.toml" | sed -E 's/version *= *"([^"-]+).*/\1/')
echo "Base version from pyproject.toml: $CURRENT_VERSION"

# Handle different release types
if [ "$RELEASE_TYPE" = "formal" ]; then
# For formal release, use version exactly as in pyproject.toml
FINAL_VERSION="${CURRENT_VERSION}"
echo "Formal release - using exact version: $FINAL_VERSION"
else
# For dev release, append -dev-epochtime format
FINAL_VERSION="${CURRENT_VERSION}-dev-${EPOCH_TIME}"
echo "Dev release - using version with epoch timestamp: $FINAL_VERSION"
fi

# Update version in pyproject.toml
sed -i -E "s/version *= *\"[^\"]+\"/version = \"$FINAL_VERSION\"/" pyproject.toml

# Output version for later steps
echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
else
FINAL_VERSION="0.1.0-dev-${EPOCH_TIME}"
# If no version defined, add initial version
if [ "$RELEASE_TYPE" = "formal" ]; then
FINAL_VERSION="0.1.0"
else
FINAL_VERSION="0.1.0-dev-${EPOCH_TIME}"
fi

echo "No version found. Adding version: $FINAL_VERSION"
sed -i "/build-backend/a version = \"$FINAL_VERSION\"" pyproject.toml

echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
fi

echo "No version found. Adding version: $FINAL_VERSION"
sed -i "/build-backend/a version = \"$FINAL_VERSION\"" pyproject.toml

echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
fi

- name: Build package with uv
working-directory: ./sandbox
run: |
# Build using uv build which handles both sdist and wheel
uv build

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-path: 'sandbox/dist/*'

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: sandbox/dist/

- name: Build with locked dependencies
working-directory: ./sandbox
run: uv build --build-constraints requirements-build.txt --require-build-hashes

- name: Record distribution digests
id: digest
working-directory: ./sandbox
run: |
python3 - <<'PYTHON'
import hashlib
import json
import os
from pathlib import Path

digests = {
path.name: hashlib.sha256(path.read_bytes()).hexdigest()
for pattern in ("*.whl", "*.tar.gz")
for path in sorted(Path("dist").glob(pattern))
}
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
output.write(f"sha256={json.dumps(digests)}\n")
PYTHON

- name: Upload distributions
id: upload
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: sandbox-mcp-dists
path: |
sandbox/dist/*.whl
sandbox/dist/*.tar.gz
if-no-files-found: error
retention-days: 7

publish-to-pypi:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
environment:
name: pypi-production
url: https://pypi.org/project/mcp-server-plaid
permissions:
contents: read
id-token: write
attestations: write
steps:
- name: Download this build's distributions
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
artifact-ids: ${{ needs.build.outputs.artifact-id }}
merge-multiple: true
path: dist/

- name: Verify distribution digests
env:
EXPECTED_DIGESTS: ${{ needs.build.outputs.dist-sha256 }}
run: |
python3 - <<'PYTHON'
import hashlib
import json
import os
from pathlib import Path

expected = json.loads(os.environ["EXPECTED_DIGESTS"])
files = list(Path("dist").iterdir())
if len(files) != 2 or {path.name for path in files} != set(expected):
raise SystemExit("Unexpected distribution files")
if sum(path.name.endswith(".whl") for path in files) != 1 or sum(
path.name.endswith(".tar.gz") for path in files
) != 1:
raise SystemExit("Expected one wheel and one source distribution")
for path in files:
if path.is_symlink() or not path.is_file():
raise SystemExit(f"Not a regular distribution file: {path.name}")
if hashlib.sha256(path.read_bytes()).hexdigest() != expected[path.name]:
raise SystemExit(f"Distribution digest mismatch: {path.name}")
PYTHON

- name: Generate artifact attestation
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
with:
subject-path: 'dist/*'

- name: Publish package to PyPI
# PyPA publisher image for commit 7245906fb61fa33a13554f9d5fb856fe61758086.
uses: docker://ghcr.io/pypa/gh-action-pypi-publish@sha256:411241df99067c98b6d08fd8e26d14e86740a22460599c2af571e6dc26e27ffc
env:
# Direct Docker actions do not inherit the wrapper action's defaults.
INPUT_USER: __token__
INPUT_PASSWORD: ''
INPUT_REPOSITORY_URL: https://upload.pypi.org/legacy/
INPUT_PACKAGES_DIR: dist/
INPUT_VERIFY_METADATA: 'true'
INPUT_SKIP_EXISTING: 'false'
INPUT_VERBOSE: 'true'
INPUT_PRINT_HASH: 'true'
INPUT_ATTESTATIONS: 'true'
2 changes: 1 addition & 1 deletion sandbox/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling"]
requires = ["hatchling==1.33.0"]
build-backend = "hatchling.build"

[project]
Expand Down
2 changes: 2 additions & 0 deletions sandbox/requirements-build.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Keep Hatchling in sync with [build-system].requires in pyproject.toml.
hatchling==1.33.0
26 changes: 26 additions & 0 deletions sandbox/requirements-build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file was autogenerated by uv via the following command:
# uv pip compile sandbox/requirements-build.in --generate-hashes --python-version 3.11 --only-binary :all: --output-file sandbox/requirements-build.txt
hatchling==1.33.0 \
--hash=sha256:415290b84f464d2884303fca8974d38e7b85579069fab02a15db0828fbb1446d \
--hash=sha256:4c422bd4d554fcff5de5b73e9596f85e41e9f97f7e553d8f7595ecb31a627bef
# via -r sandbox/requirements-build.in
packaging==26.3 \
--hash=sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79 \
--hash=sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c
# via hatchling
pathspec==1.1.1 \
--hash=sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a \
--hash=sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189
# via hatchling
pluggy==1.7.0 \
--hash=sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec \
--hash=sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8
# via hatchling
tomlkit==0.15.2 \
--hash=sha256:05562412163a3037b94497385fb7f9204c637bc605af7a48199e41cf2272f437 \
--hash=sha256:83e32755ba1d20d9340bd069ee97e9f6232ba2346b63ffcba425de01f7e327a6
# via hatchling
trove-classifiers==2026.9.21.13 \
--hash=sha256:0a9ebc8d4e2f3e8a22848c5258033035bec17a3012ac3fea16dbaa764489eb71 \
--hash=sha256:8b1ff4f9c191b1040b71c37f1e445ab99732911e3cd91de52838453a854d7a17
# via hatchling
Loading