Version Packages (#102) #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Version and Release | |
on: | |
push: | |
branches: [main] | |
paths: | |
- '.changeset/**' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
packages: write | |
issues: write | |
pull-requests: write | |
actions: write | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
version-packages: | |
name: Version Packages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'npm' | |
- name: Install Dependencies | |
run: npm ci | |
- name: Lint | |
run: npm run lint | |
- name: Build | |
run: npm run build | |
- name: Test | |
run: npm run test | |
- name: Create Version PR | |
uses: changesets/action@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
github-releases: | |
name: Create GitHub Releases | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check for Changesets File Deletions | |
id: check-changesets | |
run: | | |
DELETED_CHANGESETS=$(git diff --name-status HEAD^ HEAD | grep "^D.*\.changeset/.*\.md$" || true) | |
if [ -z "$DELETED_CHANGESETS" ]; then | |
echo "No changeset files were deleted - skipping releases" | |
exit 0 | |
fi | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Dispatch Release Workflows | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
declare -A version_changes | |
echo "Scanning for version changes..." | |
for package_file in $(git diff --name-only HEAD^ HEAD | grep "package.json" | grep -v "node_modules"); do | |
package_name=$(jq -r '.name' "$package_file") | |
new_version=$(jq -r '.version' "$package_file") | |
old_version=$(git show HEAD^:"$package_file" 2>/dev/null | jq -r '.version' || echo "") | |
if [[ ! "$package_name" =~ ^@api-client-sdk-streamline-sample/ ]]; then | |
echo "Skipping package $package_name" | |
continue | |
fi | |
if [[ "$new_version" != "$old_version" ]]; then | |
echo "Package $package_name version change detected:" | |
echo " $old_version → $new_version" | |
version_changes["$package_name"]="$new_version" | |
fi | |
done | |
if [ ${#version_changes[@]} -eq 0 ]; then | |
echo "No version changes detected" | |
exit 0 | |
fi | |
for package_name in "${!version_changes[@]}"; do | |
version="${version_changes[$package_name]}" | |
echo "Creating release for $package_name v$version" | |
gh workflow run release-base.yml \ | |
-f package-name="$package_name" \ | |
-f version="$version" \ | |
-f type="api" | |
echo "Release workflow triggered for $package_name" | |
done |