Skip to content

Commit 6554944

Browse files
Merge branch 'main' into add-elevenlabs
2 parents fcaaa53 + bedc115 commit 6554944

File tree

3 files changed

+471
-0
lines changed

3 files changed

+471
-0
lines changed

.github/workflows/release-check.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Release Check
2+
3+
on:
4+
# Allow manual trigger for testing
5+
workflow_dispatch:
6+
7+
jobs:
8+
prepare:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
matrix: ${{ steps.set-matrix.outputs.matrix }}
12+
last_release: ${{ steps.last-release.outputs.hash }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Find package directories
19+
id: set-matrix
20+
run: |
21+
# Find all package.json and pyproject.toml files, excluding root
22+
DIRS=$(git ls-tree -r HEAD --name-only | grep -E "package.json|pyproject.toml" | xargs dirname | grep -v "^.$" | jq -R -s -c 'split("\n")[:-1]')
23+
echo "matrix=${DIRS}" >> $GITHUB_OUTPUT
24+
echo "Found directories: ${DIRS}"
25+
26+
- name: Get last release hash
27+
id: last-release
28+
run: |
29+
HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
30+
echo "hash=${HASH}" >> $GITHUB_OUTPUT
31+
echo "Using last release hash: ${HASH}"
32+
33+
check-release:
34+
needs: prepare
35+
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
directory: ${{ fromJson(needs.prepare.outputs.matrix) }}
39+
fail-fast: false
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
45+
46+
- uses: astral-sh/setup-uv@v5
47+
48+
- name: Setup Node.js
49+
if: endsWith(matrix.directory, '/package.json')
50+
uses: actions/setup-node@v4
51+
with:
52+
node-version: '18'
53+
54+
- name: Setup Python
55+
if: endsWith(matrix.directory, '/pyproject.toml')
56+
run: uv python install
57+
58+
- name: Check release
59+
id: check
60+
run: |
61+
# Create unique hash for this directory
62+
dir_hash=$(echo "${{ matrix.directory }}" | sha256sum | awk '{print $1}')
63+
64+
# Run release check script with verbose output
65+
echo "Running release check against last release: ${{ needs.prepare.outputs.last_release }}"
66+
67+
# Run git diff first to show changes
68+
echo "Changes since last release:"
69+
git diff --name-only "${{ needs.prepare.outputs.last_release }}" -- "${{ matrix.directory }}" || true
70+
71+
# Run the release check
72+
output=$(uv run --script scripts/release.py --dry-run "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" 2>&1)
73+
exit_code=$?
74+
75+
echo "Release check output (exit code: $exit_code):"
76+
echo "$output"
77+
78+
# Extract package info if successful
79+
if [ $exit_code -eq 0 ]; then
80+
pkg_info=$(echo "$output" | grep -o -E "[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+" || true)
81+
else
82+
echo "Release check failed"
83+
exit 1
84+
fi
85+
86+
if [ ! -z "$pkg_info" ]; then
87+
echo "Found package that needs release: $pkg_info"
88+
89+
# Create outputs directory
90+
mkdir -p ./outputs
91+
92+
# Save both package info and full changes
93+
echo "$pkg_info" > "./outputs/${dir_hash}_info"
94+
echo "dir_hash=${dir_hash}" >> $GITHUB_OUTPUT
95+
96+
# Log what we're saving
97+
echo "Saved package info to ./outputs/${dir_hash}_info:"
98+
cat "./outputs/${dir_hash}_info"
99+
else
100+
echo "No release needed for this package"
101+
fi
102+
103+
- name: Set artifact name
104+
if: steps.check.outputs.dir_hash
105+
id: artifact
106+
run: |
107+
# Replace forward slashes with dashes
108+
SAFE_DIR=$(echo "${{ matrix.directory }}" | tr '/' '-')
109+
echo "name=release-outputs-${SAFE_DIR}" >> $GITHUB_OUTPUT
110+
111+
- uses: actions/upload-artifact@v4
112+
if: steps.check.outputs.dir_hash
113+
with:
114+
name: ${{ steps.artifact.outputs.name }}
115+
path: ./outputs/${{ steps.check.outputs.dir_hash }}*
116+
117+
check-tag:
118+
needs: [prepare, check-release]
119+
runs-on: ubuntu-latest
120+
steps:
121+
- uses: actions/checkout@v4
122+
123+
- uses: actions/download-artifact@v4
124+
with:
125+
pattern: release-outputs-src-*
126+
merge-multiple: true
127+
path: outputs
128+
129+
- name: Simulate tag creation
130+
run: |
131+
if [ -d outputs ]; then
132+
# Collect package info
133+
find outputs -name "*_info" -exec cat {} \; > packages.txt
134+
135+
if [ -s packages.txt ]; then
136+
DATE=$(date +%Y.%m.%d)
137+
echo "🔍 Dry run: Would create tag v${DATE} if this was a real release"
138+
139+
# Generate comprehensive release notes
140+
{
141+
echo "# Release ${DATE}"
142+
echo ""
143+
echo "## Updated Packages"
144+
while IFS= read -r line; do
145+
echo "- $line"
146+
done < packages.txt
147+
} > notes.md
148+
149+
echo "🔍 Would create release with following notes:"
150+
cat notes.md
151+
152+
echo "🔍 Would create tag v${DATE} with the above release notes"
153+
echo "🔍 Would create GitHub release from tag v${DATE}"
154+
else
155+
echo "No packages need release"
156+
fi
157+
else
158+
echo "No release artifacts found"
159+
fi

.github/workflows/release.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Automatic Release Creation
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
detect-last-release:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
last_release: ${{ steps.last-release.outputs.hash }}
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Get last release hash
17+
id: last-release
18+
run: |
19+
HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
20+
echo "hash=${HASH}" >> $GITHUB_OUTPUT
21+
echo "Using last release hash: ${HASH}"
22+
23+
create-tag-name:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
tag_name: ${{ steps.last-release.outputs.tag}}
27+
steps:
28+
- name: Get last release hash
29+
id: last-release
30+
run: |
31+
DATE=$(date +%Y.%m.%d)
32+
echo "tag=v${DATE}" >> $GITHUB_OUTPUT
33+
echo "Using tag: v${DATE}"
34+
35+
detect-packages:
36+
needs: [detect-last-release]
37+
runs-on: ubuntu-latest
38+
outputs:
39+
packages: ${{ steps.find-packages.outputs.packages }}
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Install uv
46+
uses: astral-sh/setup-uv@v5
47+
48+
- name: Find packages
49+
id: find-packages
50+
working-directory: src
51+
run: |
52+
cat << 'EOF' > find_packages.py
53+
import json
54+
import os
55+
import subprocess
56+
from itertools import chain
57+
from pathlib import Path
58+
59+
packages = []
60+
61+
print("Starting package detection...")
62+
print(f"Using LAST_RELEASE: {os.environ['LAST_RELEASE']}")
63+
64+
# Find all directories containing package.json or pyproject.toml
65+
paths = chain(Path('.').glob('*/package.json'), Path('.').glob('*/pyproject.toml'))
66+
for path in paths:
67+
print(f"\nChecking path: {path}")
68+
# Check for changes in .py or .ts files
69+
# Run git diff from the specific directory
70+
cmd = ['git', 'diff', '--name-only', f'{os.environ["LAST_RELEASE"]}..HEAD', '--', '.']
71+
result = subprocess.run(cmd, capture_output=True, text=True, cwd=path.parent)
72+
73+
# Check if any .py or .ts files were changed
74+
changed_files = result.stdout.strip().split('\n')
75+
print(f"Changed files found: {changed_files}")
76+
77+
has_changes = any(f.endswith(('.py', '.ts')) for f in changed_files if f)
78+
if has_changes:
79+
print(f"Adding package: {path.parent}")
80+
packages.append(str(path.parent))
81+
82+
print(f"\nFinal packages list: {packages}")
83+
84+
# Write output
85+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
86+
f.write(f"packages={json.dumps(packages)}\n")
87+
EOF
88+
89+
LAST_RELEASE=${{ needs.detect-last-release.outputs.last_release }} uv run --script --python 3.12 find_packages.py
90+
91+
create-tag:
92+
needs: [detect-packages, create-tag-name]
93+
runs-on: ubuntu-latest
94+
permissions:
95+
contents: write
96+
steps:
97+
- uses: actions/checkout@v4
98+
99+
- name: Create release
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
run: |
103+
# Configure git
104+
git config --global user.name "GitHub Actions"
105+
git config --global user.email "[email protected]"
106+
107+
# Get packages array
108+
PACKAGES='${{ needs.detect-packages.outputs.packages }}'
109+
110+
if [ "$(echo "$PACKAGES" | jq 'length')" -gt 0 ]; then
111+
# Generate comprehensive release notes
112+
{
113+
echo "# Release ${{ needs.create-tag-name.outputs.tag_name }}"
114+
echo ""
115+
echo "## Updated Packages"
116+
echo "$PACKAGES" | jq -r '.[]' | while read -r package; do
117+
echo "- $package"
118+
done
119+
} > notes.md
120+
121+
# Create and push tag
122+
git tag -a "${{ needs.create-tag-name.outputs.tag_name }}" -m "Release ${{ needs.create-tag-name.outputs.tag_name }}"
123+
git push origin "${{ needs.create-tag-name.outputs.tag_name }}"
124+
125+
# Create GitHub release
126+
gh release create "${{ needs.create-tag-name.outputs.tag_name }}" \
127+
--title "Release ${{ needs.create-tag-name.outputs.tag_name }}" \
128+
--notes-file notes.md
129+
else
130+
echo "No packages need release"
131+
fi

0 commit comments

Comments
 (0)