feat: improvements to release.yml
This commit is contained in:
parent
a5dbc1d3d3
commit
bedc11573e
1 changed files with 82 additions and 125 deletions
197
.github/workflows/release.yml
vendored
197
.github/workflows/release.yml
vendored
|
|
@ -1,31 +1,18 @@
|
||||||
name: Release
|
name: Automatic Release Creation
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
|
||||||
# Run every day at 9:00 UTC
|
|
||||||
- cron: '0 9 * * *'
|
|
||||||
# Allow manual trigger for testing
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
prepare:
|
detect-last-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
|
||||||
last_release: ${{ steps.last-release.outputs.hash }}
|
last_release: ${{ steps.last-release.outputs.hash }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Find package directories
|
|
||||||
id: set-matrix
|
|
||||||
run: |
|
|
||||||
# Find all package.json and pyproject.toml files, excluding root
|
|
||||||
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]')
|
|
||||||
echo "matrix=${DIRS}" >> $GITHUB_OUTPUT
|
|
||||||
echo "Found directories: ${DIRS}"
|
|
||||||
|
|
||||||
- name: Get last release hash
|
- name: Get last release hash
|
||||||
id: last-release
|
id: last-release
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -33,142 +20,112 @@ jobs:
|
||||||
echo "hash=${HASH}" >> $GITHUB_OUTPUT
|
echo "hash=${HASH}" >> $GITHUB_OUTPUT
|
||||||
echo "Using last release hash: ${HASH}"
|
echo "Using last release hash: ${HASH}"
|
||||||
|
|
||||||
release:
|
create-tag-name:
|
||||||
needs: prepare
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: release
|
outputs:
|
||||||
strategy:
|
tag_name: ${{ steps.last-release.outputs.tag}}
|
||||||
matrix:
|
steps:
|
||||||
directory: ${{ fromJson(needs.prepare.outputs.matrix) }}
|
- name: Get last release hash
|
||||||
fail-fast: false
|
id: last-release
|
||||||
permissions:
|
run: |
|
||||||
contents: write
|
DATE=$(date +%Y.%m.%d)
|
||||||
packages: write
|
echo "tag=v${DATE}" >> $GITHUB_OUTPUT
|
||||||
|
echo "Using tag: v${DATE}"
|
||||||
|
|
||||||
|
detect-packages:
|
||||||
|
needs: [detect-last-release]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
packages: ${{ steps.find-packages.outputs.packages }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- uses: astral-sh/setup-uv@v5
|
- name: Install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Find packages
|
||||||
if: endsWith(matrix.directory, '/package.json')
|
id: find-packages
|
||||||
uses: actions/setup-node@v4
|
working-directory: src
|
||||||
with:
|
|
||||||
node-version: '18'
|
|
||||||
registry-url: 'https://registry.npmjs.org'
|
|
||||||
|
|
||||||
- name: Setup Python
|
|
||||||
if: endsWith(matrix.directory, '/pyproject.toml')
|
|
||||||
run: uv python install
|
|
||||||
|
|
||||||
- name: Release package
|
|
||||||
id: release
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
# Create unique hash for this directory
|
cat << 'EOF' > find_packages.py
|
||||||
dir_hash=$(echo "${{ matrix.directory }}" | sha256sum | awk '{print $1}')
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
from itertools import chain
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# Run git diff first to show changes
|
packages = []
|
||||||
echo "Changes since last release:"
|
|
||||||
git diff --name-only "${{ needs.prepare.outputs.last_release }}" -- "${{ matrix.directory }}" || true
|
|
||||||
|
|
||||||
# Run the release
|
print("Starting package detection...")
|
||||||
output=$(uv run --script scripts/release.py "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" 2>&1)
|
print(f"Using LAST_RELEASE: {os.environ['LAST_RELEASE']}")
|
||||||
exit_code=$?
|
|
||||||
|
|
||||||
echo "Release output (exit code: $exit_code):"
|
# Find all directories containing package.json or pyproject.toml
|
||||||
echo "$output"
|
paths = chain(Path('.').glob('*/package.json'), Path('.').glob('*/pyproject.toml'))
|
||||||
|
for path in paths:
|
||||||
|
print(f"\nChecking path: {path}")
|
||||||
|
# Check for changes in .py or .ts files
|
||||||
|
# Run git diff from the specific directory
|
||||||
|
cmd = ['git', 'diff', '--name-only', f'{os.environ["LAST_RELEASE"]}..HEAD', '--', '.']
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, cwd=path.parent)
|
||||||
|
|
||||||
# Extract package info if successful
|
# Check if any .py or .ts files were changed
|
||||||
if [ $exit_code -eq 0 ]; then
|
changed_files = result.stdout.strip().split('\n')
|
||||||
pkg_info=$(echo "$output" | grep -o -E "[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+" || true)
|
print(f"Changed files found: {changed_files}")
|
||||||
else
|
|
||||||
echo "Release failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -z "$pkg_info" ]; then
|
has_changes = any(f.endswith(('.py', '.ts')) for f in changed_files if f)
|
||||||
echo "Released package: $pkg_info"
|
if has_changes:
|
||||||
|
print(f"Adding package: {path.parent}")
|
||||||
|
packages.append(str(path.parent))
|
||||||
|
|
||||||
# Create outputs directory
|
print(f"\nFinal packages list: {packages}")
|
||||||
mkdir -p ./outputs
|
|
||||||
|
|
||||||
# Save both package info and full changes
|
# Write output
|
||||||
echo "$pkg_info" > "./outputs/${dir_hash}_info"
|
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
|
||||||
echo "dir_hash=${dir_hash}" >> $GITHUB_OUTPUT
|
f.write(f"packages={json.dumps(packages)}\n")
|
||||||
|
EOF
|
||||||
|
|
||||||
# Log what we're saving
|
LAST_RELEASE=${{ needs.detect-last-release.outputs.last_release }} uv run --script --python 3.12 find_packages.py
|
||||||
echo "Saved package info to ./outputs/${dir_hash}_info:"
|
|
||||||
cat "./outputs/${dir_hash}_info"
|
|
||||||
else
|
|
||||||
echo "No release needed for this package"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Set artifact name
|
|
||||||
if: steps.release.outputs.dir_hash
|
|
||||||
id: artifact
|
|
||||||
run: |
|
|
||||||
# Replace forward slashes with dashes
|
|
||||||
SAFE_DIR=$(echo "${{ matrix.directory }}" | tr '/' '-')
|
|
||||||
echo "name=release-outputs-${SAFE_DIR}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
if: steps.release.outputs.dir_hash
|
|
||||||
with:
|
|
||||||
name: ${{ steps.artifact.outputs.name }}
|
|
||||||
path: ./outputs/${{ steps.release.outputs.dir_hash }}*
|
|
||||||
|
|
||||||
create-tag:
|
create-tag:
|
||||||
needs: [prepare, release]
|
needs: [detect-packages, create-tag-name]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/download-artifact@v4
|
- name: Create release
|
||||||
with:
|
|
||||||
pattern: release-outputs-src-*
|
|
||||||
merge-multiple: true
|
|
||||||
path: outputs
|
|
||||||
|
|
||||||
- name: Create tag and release
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
if [ -d outputs ]; then
|
# Configure git
|
||||||
# Collect package info
|
git config --global user.name "GitHub Actions"
|
||||||
find outputs -name "*_info" -exec cat {} \; > packages.txt
|
git config --global user.email "actions@github.com"
|
||||||
|
|
||||||
if [ -s packages.txt ]; then
|
# Get packages array
|
||||||
DATE=$(date +%Y.%m.%d)
|
PACKAGES='${{ needs.detect-packages.outputs.packages }}'
|
||||||
echo "Creating tag v${DATE}"
|
|
||||||
|
|
||||||
# Generate comprehensive release notes
|
if [ "$(echo "$PACKAGES" | jq 'length')" -gt 0 ]; then
|
||||||
{
|
# Generate comprehensive release notes
|
||||||
echo "# Release ${DATE}"
|
{
|
||||||
echo ""
|
echo "# Release ${{ needs.create-tag-name.outputs.tag_name }}"
|
||||||
echo "## Updated Packages"
|
echo ""
|
||||||
while IFS= read -r line; do
|
echo "## Updated Packages"
|
||||||
echo "- $line"
|
echo "$PACKAGES" | jq -r '.[]' | while read -r package; do
|
||||||
done < packages.txt
|
echo "- $package"
|
||||||
} > notes.md
|
done
|
||||||
|
} > notes.md
|
||||||
|
|
||||||
# Create and push tag
|
# Create and push tag
|
||||||
git tag -a "v${DATE}" -m "Release ${DATE}"
|
git tag -a "${{ needs.create-tag-name.outputs.tag_name }}" -m "Release ${{ needs.create-tag-name.outputs.tag_name }}"
|
||||||
git push origin "v${DATE}"
|
git push origin "${{ needs.create-tag-name.outputs.tag_name }}"
|
||||||
|
|
||||||
# Create GitHub release
|
# Create GitHub release
|
||||||
gh release create "v${DATE}" \
|
gh release create "${{ needs.create-tag-name.outputs.tag_name }}" \
|
||||||
--title "Release ${DATE}" \
|
--title "Release ${{ needs.create-tag-name.outputs.tag_name }}" \
|
||||||
--notes-file notes.md
|
--notes-file notes.md
|
||||||
else
|
|
||||||
echo "No packages need release"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "No release artifacts found"
|
echo "No packages need release"
|
||||||
fi
|
fi
|
||||||
Loading…
Reference in a new issue