-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (105 loc) · 3.85 KB
/
version-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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"
package_name_without_scope=${package_name#@api-client-sdk-streamline-sample/}
if [[ "$package_name_without_scope" == "products-api-client" || "$package_name_without_scope" == "users-api-client" ]]; then
gh workflow run release-base.yml \
-f package-name="$package_name" \
-f version="$version" \
-f type="sdk"
elif [[ "$package_name_without_scope" == "products-api" || "$package_name_without_scope" == "users-api" ]]; then
gh workflow run release-base.yml \
-f package-name="$package_name" \
-f version="$version" \
-f type="api"
else
gh workflow run release-base.yml \
-f package-name="$package_name" \
-f version="$version"
fi
echo "Release workflow triggered for $package_name"
done