Skip to content

Commit 111806d

Browse files
committed
feat: use artifcats to collect mutliple job outputs into one
A matrix job cant have multiple outputs directly, see https://github.com/orgs/community/discussions/17245. Use the artifact workaround.
1 parent 9f86ee5 commit 111806d

File tree

1 file changed

+93
-24
lines changed

1 file changed

+93
-24
lines changed

β€Ž.github/workflows/release-check.yml

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ jobs:
1818
- name: Find package directories
1919
id: set-matrix
2020
run: |
21+
# Find all package.json and pyproject.toml files, excluding root
2122
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]')
2223
echo "matrix=${DIRS}" >> $GITHUB_OUTPUT
24+
echo "Found directories: ${DIRS}"
2325
2426
- name: Get last release hash
2527
id: last-release
2628
run: |
2729
HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
2830
echo "hash=${HASH}" >> $GITHUB_OUTPUT
31+
echo "Using last release hash: ${HASH}"
2932
3033
check-release:
3134
needs: prepare
3235
runs-on: ubuntu-latest
33-
outputs:
34-
release: ${{ steps.check.outputs.release }}
3536
strategy:
3637
matrix:
3738
directory: ${{ fromJson(needs.prepare.outputs.matrix) }}
@@ -45,46 +46,114 @@ jobs:
4546
- uses: astral-sh/setup-uv@v5
4647

4748
- name: Setup Node.js
48-
if: endsWith(matrix.directory, 'package.json')
49+
if: endsWith(matrix.directory, '/package.json')
4950
uses: actions/setup-node@v4
5051
with:
5152
node-version: '18'
5253

5354
- name: Setup Python
54-
if: endsWith(matrix.directory, 'pyproject.toml')
55+
if: endsWith(matrix.directory, '/pyproject.toml')
5556
run: uv python install
5657

5758
- name: Check release
5859
id: check
5960
run: |
60-
output=$(uv run --script scripts/release.py --dry-run "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" \
61-
| grep -o -E "[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+" || true)
62-
if [ ! -z "$output" ]; then
63-
echo "release<<EOF" >> $GITHUB_OUTPUT
64-
echo "$output" >> $GITHUB_OUTPUT
65-
echo "EOF" >> $GITHUB_OUTPUT
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"
66101
fi
67102
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+
68117
check-tag:
69118
needs: [prepare, check-release]
70119
runs-on: ubuntu-latest
71120
steps:
72121
- uses: actions/checkout@v4
73122

123+
- uses: actions/download-artifact@v4
124+
with:
125+
pattern: release-outputs-src-*
126+
merge-multiple: true
127+
path: outputs
128+
74129
- name: Simulate tag creation
75130
run: |
76-
echo "${{ needs.check-release.outputs.release }}" > packages.txt
77-
if [ -s packages.txt ]; then
78-
DATE=$(date +%Y.%m.%d)
79-
echo "πŸ” Dry run: Would create tag v${DATE} if this was a real release"
80-
81-
echo "# Release ${DATE}" > notes.md
82-
echo "" >> notes.md
83-
echo "## Updated Packages" >> notes.md
84-
while IFS= read -r line; do
85-
echo "- $line" >> notes.md
86-
done < packages.txt
87-
88-
echo "πŸ” Would create release with following notes:"
89-
cat notes.md
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"
90159
fi

0 commit comments

Comments
Β (0)