Skip to content

Commit

Permalink
feat: use artifcats to collect mutliple job outputs into one
Browse files Browse the repository at this point in the history
A matrix job cant have multiple outputs directly, see
https://github.com/orgs/community/discussions/17245.

Use the artifact workaround.
  • Loading branch information
dsp-ant committed Jan 13, 2025
1 parent 9f86ee5 commit 7a4979e
Showing 1 changed file with 97 additions and 24 deletions.
121 changes: 97 additions & 24 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ jobs:
- 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
id: last-release
run: |
HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
echo "hash=${HASH}" >> $GITHUB_OUTPUT
echo "Using last release hash: ${HASH}"
check-release:
needs: prepare
runs-on: ubuntu-latest
outputs:
release: ${{ steps.check.outputs.release }}
strategy:
matrix:
directory: ${{ fromJson(needs.prepare.outputs.matrix) }}
Expand All @@ -45,46 +46,118 @@ jobs:
- uses: astral-sh/setup-uv@v5

- name: Setup Node.js
if: endsWith(matrix.directory, 'package.json')
if: endsWith(matrix.directory, '/package.json')
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Setup Python
if: endsWith(matrix.directory, 'pyproject.toml')
if: endsWith(matrix.directory, '/pyproject.toml')
run: uv python install

- name: Check release
id: check
run: |
output=$(uv run --script scripts/release.py --dry-run "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" \
| grep -o -E "[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+" || true)
if [ ! -z "$output" ]; then
echo "release<<EOF" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Create unique hash for this directory
dir_hash=$(echo "${{ matrix.directory }}" | sha256sum | awk '{print $1}')
# Determine package type by checking which file exists
if [ -f "${{ matrix.directory }}/package.json" ]; then
pkg_type="node"
pkg_file="package.json"
elif [ -f "${{ matrix.directory }}/pyproject.toml" ]; then
pkg_type="python"
pkg_file="pyproject.toml"
else
echo "Error: Neither package.json nor pyproject.toml found in ${{ matrix.directory }}"
exit 1
fi
echo "Checking $pkg_type package in ${{ matrix.directory }} (using $pkg_file)"
# Run release check script with verbose output
echo "Running release check against last release: ${{ needs.prepare.outputs.last_release }}"
output=$(uv run --script scripts/release.py --dry-run "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}")
echo "Release check output:"
echo "$output"
# Extract package info
pkg_info=$(echo "$output" | grep -o -E "[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+" || true)
if [ ! -z "$pkg_info" ]; then
echo "Found package that needs release: $pkg_info"
# Create outputs directory
mkdir -p ./outputs
# Save both package info and full changes
echo "$pkg_info" > "./outputs/${dir_hash}_info"
echo "$output" > "./outputs/${dir_hash}_changes"
echo "dir_hash=${dir_hash}" >> $GITHUB_OUTPUT
# Log what we're saving
echo "Saved package info to ./outputs/${dir_hash}_info:"
cat "./outputs/${dir_hash}_info"
echo "Saved full changes to ./outputs/${dir_hash}_changes:"
cat "./outputs/${dir_hash}_changes"
else
echo "No release needed for this package"
fi
- uses: actions/upload-artifact@v4
if: steps.check.outputs.dir_hash
with:
name: release-outputs-${{ matrix.directory }}
path: ./outputs/${{ steps.check.outputs.dir_hash }}*

check-tag:
needs: [prepare, check-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
pattern: release-outputs-*
merge-multiple: true
path: outputs

- name: Simulate tag creation
run: |
echo "${{ needs.check-release.outputs.release }}" > packages.txt
if [ -s packages.txt ]; then
DATE=$(date +%Y.%m.%d)
echo "πŸ” Dry run: Would create tag v${DATE} if this was a real release"
echo "# Release ${DATE}" > notes.md
echo "" >> notes.md
echo "## Updated Packages" >> notes.md
while IFS= read -r line; do
echo "- $line" >> notes.md
done < packages.txt
echo "πŸ” Would create release with following notes:"
cat notes.md
if [ -d outputs ]; then
# Collect package info
find outputs -name "*_info" -exec cat {} \; > packages.txt
# Collect detailed changes
find outputs -name "*_changes" -exec cat {} \; > changes.txt
if [ -s packages.txt ]; then
DATE=$(date +%Y.%m.%d)
echo "πŸ” Dry run: Would create tag v${DATE} if this was a real release"
# Generate comprehensive release notes
{
echo "# Release ${DATE}"
echo ""
echo "## Updated Packages"
while IFS= read -r line; do
echo "- $line"
done < packages.txt
echo ""
echo "## Detailed Changes"
echo '```'
cat changes.txt
echo '```'
} > notes.md
echo "πŸ” Would create release with following notes:"
cat notes.md
echo "πŸ” Would create tag v${DATE} with the above release notes"
echo "πŸ” Would create GitHub release from tag v${DATE}"
else
echo "No packages need release"
fi
else
echo "No release artifacts found"
fi

0 comments on commit 7a4979e

Please sign in to comment.