|
| 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 |
0 commit comments