44 workflow_dispatch :
55
66jobs :
7- detect-last-release :
7+ create-metadata :
88 runs-on : ubuntu-latest
99 outputs :
10- last_release : ${{ steps.last-release.outputs.hash }}
10+ hash : ${{ steps.last-release.outputs.hash }}
11+ version : ${{ steps.create-version.outputs.version}}
1112 steps :
1213 - uses : actions/checkout@v4
1314 with :
@@ -20,23 +21,33 @@ jobs:
2021 echo "hash=${HASH}" >> $GITHUB_OUTPUT
2122 echo "Using last release hash: ${HASH}"
2223
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
24+ - name : Install uv
25+ uses : astral-sh/setup-uv@v5
26+
27+ - name : Create version name
28+ id : create-version
29+ run : |
30+ VERSION=$(uv run --script scripts/release.py generate-version)
31+ echo "version $VERSION"
32+ echo "version=$VERSION" >> $GITHUB_OUTPUT
33+
34+ - name : Create notes
3035 run : |
31- DATE=$(date +%Y.%m.%d)
32- echo "tag=v${DATE}" >> $GITHUB_OUTPUT
33- echo "Using tag: v${DATE}"
36+ HASH="${{ steps.last-release.outputs.hash }}"
37+ uv run --script scripts/release.py generate-notes --directory src/ $HASH > RELEASE_NOTES.md
38+ cat RELEASE_NOTES.md
39+
40+ - name : Release notes
41+ uses : actions/upload-artifact@v4
42+ with :
43+ name : release-notes
44+ path : RELEASE_NOTES.md
3445
35- detect -packages :
36- needs : [detect-last-release ]
46+ update -packages :
47+ needs : [create-metadata ]
3748 runs-on : ubuntu-latest
3849 outputs :
39- packages : ${{ steps.find-packages .outputs.packages }}
50+ changes_made : ${{ steps.commit .outputs.changes_made }}
4051 steps :
4152 - uses : actions/checkout@v4
4253 with :
@@ -45,156 +56,50 @@ jobs:
4556 - name : Install uv
4657 uses : astral-sh/setup-uv@v5
4758
48- - name : Find packages
49- id : find-packages
50- working-directory : src
59+ - name : Update packages
5160 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
61+ HASH="${{ needs.create-metadata.outputs.hash }}"
62+ uv run --script scripts/release.py update-packages --directory src/ $HASH
5863
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
64+ - name : Configure git
65+ run : |
66+ git config --global user.name "GitHub Actions"
67+ git config --global user.email "[email protected] " 8868
89- LAST_RELEASE=${{ needs.detect-last-release.outputs.last_release }} uv run --script --python 3.12 find_packages.py
69+ - name : Commit changes
70+ id : commit
71+ run : |
72+ VERSION="${{ needs.create-metadata.outputs.version }}"
73+ git add -u
74+ if git diff-index --quiet HEAD; then
75+ echo "changes_made=false" >> $GITHUB_OUTPUT
76+ else
77+ git commit -m 'Automatic update of packages'
78+ git tag -a "$VERSION" -m "Release $VERSION"
79+ git push origin "$VERSION"
80+ echo "changes_made=true" >> $GITHUB_OUTPUT
81+ fi
9082
91- create-tag :
92- needs : [detect -packages, create-tag-name ]
93- if : fromJson( needs.detect -packages.outputs.packages)[0] != null
83+ create-release :
84+ needs : [update -packages, create-metadata ]
85+ if : needs.update -packages.outputs.changes_made == 'true'
9486 runs-on : ubuntu-latest
9587 environment : release
9688 permissions :
9789 contents : write
9890 steps :
9991 - uses : actions/checkout@v4
10092
101- - name : Install uv
102- uses : astral-sh/setup-uv@v5
103-
104- - name : Install Node.js
105- uses : actions/setup-node@v4
93+ - name : Download release notes
94+ uses : actions/download-artifact@v4
10695 with :
107- node-version : ' 20'
108-
109- - name : Update package versions and create tag
110- env :
111- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
112- run : |
113- # Configure git
114- git config --global user.name "GitHub Actions"
115- git config --global user.email "[email protected] " 116-
117- # Get packages array and version
118- PACKAGES='${{ needs.detect-packages.outputs.packages }}'
119- VERSION="${{ needs.create-tag-name.outputs.tag_name }}"
120- VERSION_NO_V="${VERSION#v}" # Remove 'v' prefix for package versions
121-
122- # Create version update script
123- cat << 'EOF' > update_versions.py
124- import json
125- import os
126- import sys
127- import toml
128- from pathlib import Path
129-
130- def update_package_json(path, version):
131- with open(path) as f:
132- data = json.load(f)
133- data['version'] = version
134- with open(path, 'w') as f:
135- json.dump(data, f, indent=2)
136- f.write('\n')
137-
138- def update_pyproject_toml(path, version):
139- data = toml.load(path)
140- if 'project' in data:
141- data['project']['version'] = version
142- elif 'tool' in data and 'poetry' in data['tool']:
143- data['tool']['poetry']['version'] = version
144- with open(path, 'w') as f:
145- toml.dump(data, f)
146-
147- packages = json.loads(os.environ['PACKAGES'])
148- version = os.environ['VERSION']
149-
150- for package_dir in packages:
151- package_dir = Path('src') / package_dir
152-
153- # Update package.json if it exists
154- package_json = package_dir / 'package.json'
155- if package_json.exists():
156- update_package_json(package_json, version)
157-
158- # Update pyproject.toml if it exists
159- pyproject_toml = package_dir / 'pyproject.toml'
160- if pyproject_toml.exists():
161- update_pyproject_toml(pyproject_toml, version)
162- EOF
163-
164- # Install toml package for Python
165- uv pip install toml
166-
167- # Update versions
168- PACKAGES="$PACKAGES" VERSION="$VERSION_NO_V" uv run update_versions.py
169-
170- # Commit version updates
171- git add src/*/package.json src/*/pyproject.toml
172- git commit -m "chore: update package versions to $VERSION"
173-
174- # Create and push tag
175- git tag -a "$VERSION" -m "Release $VERSION"
176- git push origin HEAD "$VERSION"
96+ name : release-notes
17797
17898 - name : Create release
17999 env :
180100 GH_TOKEN : ${{ secrets.RELEASE_TOKEN }}
181101 run : |
182- PACKAGES='${{ needs.detect-packages.outputs.packages }}'
183-
184- if [ "$(echo "$PACKAGES" | jq 'length')" -gt 0 ]; then
185- # Generate comprehensive release notes
186- {
187- echo "# Release ${{ needs.create-tag-name.outputs.tag_name }}"
188- echo ""
189- echo "## Updated Packages"
190- echo "$PACKAGES" | jq -r '.[]' | while read -r package; do
191- echo "- $package"
192- done
193- } > notes.md
194- # Create GitHub release
195- gh release create "${{ needs.create-tag-name.outputs.tag_name }}" \
196- --title "Release ${{ needs.create-tag-name.outputs.tag_name }}" \
197- --notes-file notes.md
198- else
199- echo "No packages need release"
200- fi
102+ VERSION="${{ needs.create-metadata.outputs.version }}"
103+ gh release create "$VERSION" \
104+ --title "Release $VERSION" \
105+ --notes-file RELEASE_NOTES.md
0 commit comments