Skip to content

Commit 3d8c33c

Browse files
committed
feat: enhance release workflow with artifact collection and job output handling
1 parent 111806d commit 3d8c33c

File tree

1 file changed

+99
-28
lines changed

1 file changed

+99
-28
lines changed

.github/workflows/release.yml

Lines changed: 99 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ jobs:
2121
- name: Find package directories
2222
id: set-matrix
2323
run: |
24+
# Find all package.json and pyproject.toml files, excluding root
2425
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]')
2526
echo "matrix=${DIRS}" >> $GITHUB_OUTPUT
27+
echo "Found directories: ${DIRS}"
2628
2729
- name: Get last release hash
2830
id: last-release
2931
run: |
3032
HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
3133
echo "hash=${HASH}" >> $GITHUB_OUTPUT
34+
echo "Using last release hash: ${HASH}"
3235
3336
release:
3437
needs: prepare
@@ -50,54 +53,122 @@ jobs:
5053
- uses: astral-sh/setup-uv@v5
5154

5255
- name: Setup Node.js
53-
if: endsWith(matrix.directory, 'package.json')
56+
if: endsWith(matrix.directory, '/package.json')
5457
uses: actions/setup-node@v4
5558
with:
5659
node-version: '18'
5760
registry-url: 'https://registry.npmjs.org'
5861

5962
- name: Setup Python
60-
if: endsWith(matrix.directory, 'pyproject.toml')
63+
if: endsWith(matrix.directory, '/pyproject.toml')
6164
run: uv python install
6265

6366
- name: Release package
67+
id: release
6468
env:
6569
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6670
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
67-
run: uv run --script scripts/release.py "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" >> "$GITHUB_OUTPUT"
71+
run: |
72+
# Create unique hash for this directory
73+
dir_hash=$(echo "${{ matrix.directory }}" | sha256sum | awk '{print $1}')
74+
75+
# Run git diff first to show changes
76+
echo "Changes since last release:"
77+
git diff --name-only "${{ needs.prepare.outputs.last_release }}" -- "${{ matrix.directory }}" || true
78+
79+
# Run the release
80+
output=$(uv run --script scripts/release.py "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" 2>&1)
81+
exit_code=$?
82+
83+
echo "Release output (exit code: $exit_code):"
84+
echo "$output"
85+
86+
# Extract package info if successful
87+
if [ $exit_code -eq 0 ]; then
88+
pkg_info=$(echo "$output" | grep -o -E "[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+" || true)
89+
else
90+
echo "Release failed"
91+
exit 1
92+
fi
93+
94+
if [ ! -z "$pkg_info" ]; then
95+
echo "Released package: $pkg_info"
96+
97+
# Create outputs directory
98+
mkdir -p ./outputs
99+
100+
# Save both package info and full changes
101+
echo "$pkg_info" > "./outputs/${dir_hash}_info"
102+
echo "dir_hash=${dir_hash}" >> $GITHUB_OUTPUT
103+
104+
# Log what we're saving
105+
echo "Saved package info to ./outputs/${dir_hash}_info:"
106+
cat "./outputs/${dir_hash}_info"
107+
else
108+
echo "No release needed for this package"
109+
fi
68110
69-
create-release:
111+
- name: Set artifact name
112+
if: steps.release.outputs.dir_hash
113+
id: artifact
114+
run: |
115+
# Replace forward slashes with dashes
116+
SAFE_DIR=$(echo "${{ matrix.directory }}" | tr '/' '-')
117+
echo "name=release-outputs-${SAFE_DIR}" >> $GITHUB_OUTPUT
118+
119+
- uses: actions/upload-artifact@v4
120+
if: steps.release.outputs.dir_hash
121+
with:
122+
name: ${{ steps.artifact.outputs.name }}
123+
path: ./outputs/${{ steps.release.outputs.dir_hash }}*
124+
125+
create-tag:
70126
needs: [prepare, release]
71127
runs-on: ubuntu-latest
72128
permissions:
73129
contents: write
74130
steps:
75131
- uses: actions/checkout@v4
76132

77-
- name: Create Release
133+
- uses: actions/download-artifact@v4
134+
with:
135+
pattern: release-outputs-src-*
136+
merge-multiple: true
137+
path: outputs
138+
139+
- name: Create tag and release
78140
env:
79141
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80142
run: |
81-
# Check if there's output from release step
82-
if [ -s "$GITHUB_OUTPUT" ]; then
83-
DATE=$(date +%Y.%m.%d)
84-
85-
# Create git tag
86-
git tag -s -a -m"automated release v${DATE}" "v${DATE}"
87-
git push origin "v${DATE}"
88-
89-
# Create release notes
90-
echo "# Release ${DATE}" > notes.md
91-
echo "" >> notes.md
92-
echo "## Updated Packages" >> notes.md
93-
94-
# Read updated packages from github output
95-
while IFS= read -r line; do
96-
echo "- ${line}" >> notes.md
97-
done < "$GITHUB_OUTPUT"
98-
99-
# Create GitHub release
100-
gh release create "v${DATE}" \
101-
--title "Release ${DATE}" \
102-
--notes-file notes.md
103-
fi
143+
if [ -d outputs ]; then
144+
# Collect package info
145+
find outputs -name "*_info" -exec cat {} \; > packages.txt
146+
147+
if [ -s packages.txt ]; then
148+
DATE=$(date +%Y.%m.%d)
149+
echo "Creating tag v${DATE}"
150+
151+
# Generate comprehensive release notes
152+
{
153+
echo "# Release ${DATE}"
154+
echo ""
155+
echo "## Updated Packages"
156+
while IFS= read -r line; do
157+
echo "- $line"
158+
done < packages.txt
159+
} > notes.md
160+
161+
# Create and push tag
162+
git tag -a "v${DATE}" -m "Release ${DATE}"
163+
git push origin "v${DATE}"
164+
165+
# Create GitHub release
166+
gh release create "v${DATE}" \
167+
--title "Release ${DATE}" \
168+
--notes-file notes.md
169+
else
170+
echo "No packages need release"
171+
fi
172+
else
173+
echo "No release artifacts found"
174+
fi

0 commit comments

Comments
 (0)