1212 if : github.event.pull_request.merged == true && (contains(github.event.pull_request.labels.*.name, 'patch') || contains(github.event.pull_request.labels.*.name, 'minor') || contains(github.event.pull_request.labels.*.name, 'major'))
1313 runs-on : ubuntu-latest
1414 outputs :
15- changed : ${{ steps.filter.outputs.changes }}
15+ matrix : ${{ steps.build-matrix.outputs.matrix }}
16+ has_changes : ${{ steps.build-matrix.outputs.has_changes }}
1617 bump : ${{ steps.version.outputs.bump }}
1718 steps :
1819 - uses : actions/checkout@v5
4748 with :
4849 base : ${{ github.event.pull_request.base.sha }}
4950 ref : ${{ github.event.pull_request.head.sha }}
50- list-files : shell
5151 filters : |
5252 pkg_core:
5353 - 'packages/core/lib/**'
@@ -98,13 +98,61 @@ jobs:
9898 - 'packages/schemas/package.json'
9999 - 'packages/schemas/README.md'
100100
101- - name : Debug filter output
101+ - name : Build dynamic matrix
102+ id : build-matrix
102103 run : |
103- echo "Changed packages: ${{ steps.filter.outputs.changes }}"
104+ # Package mapping: filterKey -> name, npmName
105+ declare -A PKG_NAMES=(
106+ ["pkg_core"]="core"
107+ ["pkg_amqp"]="amqp"
108+ ["pkg_sqs"]="sqs"
109+ ["pkg_sns"]="sns"
110+ ["pkg_kafka"]="kafka"
111+ ["pkg_gcp_pubsub"]="gcp-pubsub"
112+ ["pkg_gcs_payload_store"]="gcs-payload-store"
113+ ["pkg_s3_payload_store"]="s3-payload-store"
114+ ["pkg_metrics"]="metrics"
115+ ["pkg_outbox_core"]="outbox-core"
116+ ["pkg_redis_message_deduplication_store"]="redis-message-deduplication-store"
117+ ["pkg_schemas"]="schemas"
118+ )
119+
120+ CHANGED='${{ steps.filter.outputs.changes }}'
121+ echo "Changed filters: $CHANGED"
122+
123+ # Build matrix JSON array
124+ MATRIX="["
125+ FIRST=true
126+
127+ for key in "${!PKG_NAMES[@]}"; do
128+ if echo "$CHANGED" | grep -q "\"$key\""; then
129+ NAME="${PKG_NAMES[$key]}"
130+ NPM_NAME="@message-queue-toolkit/${NAME}"
131+
132+ if [ "$FIRST" = true ]; then
133+ FIRST=false
134+ else
135+ MATRIX+=","
136+ fi
137+
138+ MATRIX+="{\"name\":\"${NAME}\",\"npmName\":\"${NPM_NAME}\"}"
139+ fi
140+ done
141+
142+ MATRIX+="]"
143+
144+ echo "Generated matrix: $MATRIX"
145+ echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
146+
147+ if [ "$MATRIX" = "[]" ]; then
148+ echo "has_changes=false" >> $GITHUB_OUTPUT
149+ else
150+ echo "has_changes=true" >> $GITHUB_OUTPUT
151+ fi
104152
105153 bump-versions :
106154 needs : detect-changes
107- if : needs.detect-changes.outputs.changed != '[] '
155+ if : needs.detect-changes.outputs.has_changes == 'true '
108156 runs-on : ubuntu-latest
109157 permissions :
110158 contents : write
@@ -129,45 +177,23 @@ jobs:
129177
130178 - name : Bump versions for changed packages
131179 env :
132- CHANGED : ${{ needs.detect-changes.outputs.changed }}
180+ MATRIX : ${{ needs.detect-changes.outputs.matrix }}
133181 BUMP : ${{ needs.detect-changes.outputs.bump }}
134182 run : |
135- echo "Changed packages : $CHANGED "
183+ echo "Packages to bump : $MATRIX "
136184 echo "Version bump type: $BUMP"
137185
138- # Map of filterKey to package directory
139- declare -A PACKAGES=(
140- ["pkg_core"]="core"
141- ["pkg_amqp"]="amqp"
142- ["pkg_sqs"]="sqs"
143- ["pkg_sns"]="sns"
144- ["pkg_kafka"]="kafka"
145- ["pkg_gcp_pubsub"]="gcp-pubsub"
146- ["pkg_gcs_payload_store"]="gcs-payload-store"
147- ["pkg_s3_payload_store"]="s3-payload-store"
148- ["pkg_metrics"]="metrics"
149- ["pkg_outbox_core"]="outbox-core"
150- ["pkg_redis_message_deduplication_store"]="redis-message-deduplication-store"
151- ["pkg_schemas"]="schemas"
152- )
153-
154- BUMPED_PACKAGES=""
155- for key in "${!PACKAGES[@]}"; do
156- if echo "$CHANGED" | grep -q "\"$key\""; then
157- PKG_DIR="${PACKAGES[$key]}"
158- echo "Bumping version for $PKG_DIR..."
159- cd "packages/$PKG_DIR"
160- OLD_VERSION=$(node -p "require('./package.json').version")
161- npm version "$BUMP" --no-git-tag-version
162- NEW_VERSION=$(node -p "require('./package.json').version")
163- echo " $OLD_VERSION -> $NEW_VERSION"
164- BUMPED_PACKAGES="$BUMPED_PACKAGES $PKG_DIR"
165- cd ../..
166- fi
186+ # Parse matrix JSON and bump each package
187+ echo "$MATRIX" | jq -r '.[] | .name' | while read -r PKG_NAME; do
188+ echo "Bumping version for $PKG_NAME..."
189+ cd "packages/$PKG_NAME"
190+ OLD_VERSION=$(node -p "require('./package.json').version")
191+ npm version "$BUMP" --no-git-tag-version
192+ NEW_VERSION=$(node -p "require('./package.json').version")
193+ echo " $OLD_VERSION -> $NEW_VERSION"
194+ cd ../..
167195 done
168196
169- echo "Bumped packages:$BUMPED_PACKAGES"
170-
171197 - name : Commit and push version changes
172198 run : |
173199 git add packages/*/package.json
@@ -180,6 +206,7 @@ jobs:
180206
181207 publish :
182208 needs : [detect-changes, bump-versions]
209+ if : needs.detect-changes.outputs.has_changes == 'true'
183210 runs-on : ubuntu-latest
184211 permissions :
185212 contents : read
@@ -188,120 +215,54 @@ jobs:
188215 strategy :
189216 fail-fast : false
190217 matrix :
191- include :
192- - name : core
193- filterKey : pkg_core
194- npmName : ' @message-queue-toolkit/core'
195-
196- - name : amqp
197- filterKey : pkg_amqp
198- npmName : ' @message-queue-toolkit/amqp'
199-
200- - name : sqs
201- filterKey : pkg_sqs
202- npmName : ' @message-queue-toolkit/sqs'
203-
204- - name : sns
205- filterKey : pkg_sns
206- npmName : ' @message-queue-toolkit/sns'
207-
208- - name : kafka
209- filterKey : pkg_kafka
210- npmName : ' @message-queue-toolkit/kafka'
211-
212- - name : gcp-pubsub
213- filterKey : pkg_gcp_pubsub
214- npmName : ' @message-queue-toolkit/gcp-pubsub'
215-
216- - name : gcs-payload-store
217- filterKey : pkg_gcs_payload_store
218- npmName : ' @message-queue-toolkit/gcs-payload-store'
219-
220- - name : s3-payload-store
221- filterKey : pkg_s3_payload_store
222- npmName : ' @message-queue-toolkit/s3-payload-store'
223-
224- - name : metrics
225- filterKey : pkg_metrics
226- npmName : ' @message-queue-toolkit/metrics'
227-
228- - name : outbox-core
229- filterKey : pkg_outbox_core
230- npmName : ' @message-queue-toolkit/outbox-core'
231-
232- - name : redis-message-deduplication-store
233- filterKey : pkg_redis_message_deduplication_store
234- npmName : ' @message-queue-toolkit/redis-message-deduplication-store'
235-
236- - name : schemas
237- filterKey : pkg_schemas
238- npmName : ' @message-queue-toolkit/schemas'
218+ package : ${{ fromJson(needs.detect-changes.outputs.matrix) }}
239219
240220 concurrency :
241- group : publish-${{ matrix.name }}
221+ group : publish-${{ matrix.package. name }}
242222 cancel-in-progress : false
243223
244224 steps :
245- - name : Check if should publish
246- id : gate
247- run : |
248- CHANGED='${{ needs.detect-changes.outputs.changed }}'
249- echo "Changed packages: $CHANGED"
250- if echo "$CHANGED" | grep -q '"${{ matrix.filterKey }}"'; then
251- echo "should_publish=true" >> $GITHUB_OUTPUT
252- echo "✓ Changes detected in ${{ matrix.name }}"
253- else
254- echo "should_publish=false" >> $GITHUB_OUTPUT
255- echo "⊗ No changes in ${{ matrix.name }}"
256- fi
257-
258225 - name : Checkout Repository
259- if : steps.gate.outputs.should_publish == 'true'
260226 uses : actions/checkout@v5
261227 with :
262228 ref : main
263229
264230 - name : Setup Node
265- if : steps.gate.outputs.should_publish == 'true'
266231 uses : actions/setup-node@v6
267232 with :
268233 node-version : 24.x
269234 registry-url : ' https://registry.npmjs.org'
270235 package-manager-cache : false
271236
272237 - name : Get version
273- if : steps.gate.outputs.should_publish == 'true'
274238 id : version
275- working-directory : packages/${{ matrix.name }}
239+ working-directory : packages/${{ matrix.package. name }}
276240 run : |
277241 VERSION=$(node -p "require('./package.json').version")
278242 echo "version=$VERSION" >> $GITHUB_OUTPUT
279- echo "Publishing version: $VERSION"
243+ echo "Publishing ${{ matrix.package.npmName }}@ $VERSION"
280244
281245 - name : Install dependencies
282- if : steps.gate.outputs.should_publish == 'true'
283246 run : npm install --ignore-scripts
284247
285248 - name : Build package
286- if : steps.gate.outputs.should_publish == 'true'
287- run : npm run build -- --filter=${{ matrix.npmName }}
249+ run : npm run build -- --filter=${{ matrix.package.npmName }}
288250
289251 - name : Publish to npm
290- if : steps.gate.outputs.should_publish == 'true'
291- working-directory : packages/${{ matrix.name }}
252+ working-directory : packages/${{ matrix.package.name }}
292253 run : npm publish --provenance --access public
293254 env :
294255 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
295256
296257 - name : Summary
297- if : steps.gate.outputs.should_publish == 'true'
298258 run : |
299- echo "### Published ${{ matrix.npmName }}@${{ steps.version.outputs.version }} :rocket:" >> $GITHUB_STEP_SUMMARY
259+ echo "### Published ${{ matrix.package. npmName }}@${{ steps.version.outputs.version }} :rocket:" >> $GITHUB_STEP_SUMMARY
300260 echo "" >> $GITHUB_STEP_SUMMARY
301- echo "[View on npm](https://www.npmjs.com/package/${{ matrix.npmName }})" >> $GITHUB_STEP_SUMMARY
261+ echo "[View on npm](https://www.npmjs.com/package/${{ matrix.package. npmName }})" >> $GITHUB_STEP_SUMMARY
302262
303263 create-tags :
304264 needs : [detect-changes, bump-versions, publish]
265+ if : needs.detect-changes.outputs.has_changes == 'true'
305266 runs-on : ubuntu-latest
306267 permissions :
307268 contents : write
@@ -321,31 +282,13 @@ jobs:
321282
322283 - name : Create tags for published packages
323284 env :
324- CHANGED : ${{ needs.detect-changes.outputs.changed }}
285+ MATRIX : ${{ needs.detect-changes.outputs.matrix }}
325286 run : |
326- declare -A PACKAGES=(
327- ["pkg_core"]="core"
328- ["pkg_amqp"]="amqp"
329- ["pkg_sqs"]="sqs"
330- ["pkg_sns"]="sns"
331- ["pkg_kafka"]="kafka"
332- ["pkg_gcp_pubsub"]="gcp-pubsub"
333- ["pkg_gcs_payload_store"]="gcs-payload-store"
334- ["pkg_s3_payload_store"]="s3-payload-store"
335- ["pkg_metrics"]="metrics"
336- ["pkg_outbox_core"]="outbox-core"
337- ["pkg_redis_message_deduplication_store"]="redis-message-deduplication-store"
338- ["pkg_schemas"]="schemas"
339- )
340-
341- for key in "${!PACKAGES[@]}"; do
342- if echo "$CHANGED" | grep -q "\"$key\""; then
343- PKG_DIR="${PACKAGES[$key]}"
344- VERSION=$(node -p "require('./packages/$PKG_DIR/package.json').version")
345- TAG="@message-queue-toolkit/${PKG_DIR}@${VERSION}"
346- echo "Creating tag: $TAG"
347- git tag "$TAG" || echo "Tag $TAG already exists"
348- fi
287+ echo "$MATRIX" | jq -r '.[] | .name' | while read -r PKG_NAME; do
288+ VERSION=$(node -p "require('./packages/$PKG_NAME/package.json').version")
289+ TAG="@message-queue-toolkit/${PKG_NAME}@${VERSION}"
290+ echo "Creating tag: $TAG"
291+ git tag "$TAG" || echo "Tag $TAG already exists"
349292 done
350293
351294 - name : Push tags
0 commit comments