Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 80 additions & 137 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
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'))
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.changes }}
matrix: ${{ steps.build-matrix.outputs.matrix }}
has_changes: ${{ steps.build-matrix.outputs.has_changes }}
bump: ${{ steps.version.outputs.bump }}
steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -47,7 +48,6 @@ jobs:
with:
base: ${{ github.event.pull_request.base.sha }}
ref: ${{ github.event.pull_request.head.sha }}
list-files: shell
filters: |
pkg_core:
- 'packages/core/lib/**'
Expand Down Expand Up @@ -98,13 +98,61 @@ jobs:
- 'packages/schemas/package.json'
- 'packages/schemas/README.md'

- name: Debug filter output
- name: Build dynamic matrix
id: build-matrix
run: |
echo "Changed packages: ${{ steps.filter.outputs.changes }}"
# Package mapping: filterKey -> name, npmName
declare -A PKG_NAMES=(
["pkg_core"]="core"
["pkg_amqp"]="amqp"
["pkg_sqs"]="sqs"
["pkg_sns"]="sns"
["pkg_kafka"]="kafka"
["pkg_gcp_pubsub"]="gcp-pubsub"
["pkg_gcs_payload_store"]="gcs-payload-store"
["pkg_s3_payload_store"]="s3-payload-store"
["pkg_metrics"]="metrics"
["pkg_outbox_core"]="outbox-core"
["pkg_redis_message_deduplication_store"]="redis-message-deduplication-store"
["pkg_schemas"]="schemas"
)

CHANGED='${{ steps.filter.outputs.changes }}'
echo "Changed filters: $CHANGED"

# Build matrix JSON array
MATRIX="["
FIRST=true

for key in "${!PKG_NAMES[@]}"; do
if echo "$CHANGED" | grep -q "\"$key\""; then
NAME="${PKG_NAMES[$key]}"
NPM_NAME="@message-queue-toolkit/${NAME}"

if [ "$FIRST" = true ]; then
FIRST=false
else
MATRIX+=","
fi

MATRIX+="{\"name\":\"${NAME}\",\"npmName\":\"${NPM_NAME}\"}"
fi
done

MATRIX+="]"

echo "Generated matrix: $MATRIX"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT

if [ "$MATRIX" = "[]" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi

bump-versions:
needs: detect-changes
if: needs.detect-changes.outputs.changed != '[]'
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -129,45 +177,23 @@ jobs:

- name: Bump versions for changed packages
env:
CHANGED: ${{ needs.detect-changes.outputs.changed }}
MATRIX: ${{ needs.detect-changes.outputs.matrix }}
BUMP: ${{ needs.detect-changes.outputs.bump }}
run: |
echo "Changed packages: $CHANGED"
echo "Packages to bump: $MATRIX"
echo "Version bump type: $BUMP"

# Map of filterKey to package directory
declare -A PACKAGES=(
["pkg_core"]="core"
["pkg_amqp"]="amqp"
["pkg_sqs"]="sqs"
["pkg_sns"]="sns"
["pkg_kafka"]="kafka"
["pkg_gcp_pubsub"]="gcp-pubsub"
["pkg_gcs_payload_store"]="gcs-payload-store"
["pkg_s3_payload_store"]="s3-payload-store"
["pkg_metrics"]="metrics"
["pkg_outbox_core"]="outbox-core"
["pkg_redis_message_deduplication_store"]="redis-message-deduplication-store"
["pkg_schemas"]="schemas"
)

BUMPED_PACKAGES=""
for key in "${!PACKAGES[@]}"; do
if echo "$CHANGED" | grep -q "\"$key\""; then
PKG_DIR="${PACKAGES[$key]}"
echo "Bumping version for $PKG_DIR..."
cd "packages/$PKG_DIR"
OLD_VERSION=$(node -p "require('./package.json').version")
npm version "$BUMP" --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo " $OLD_VERSION -> $NEW_VERSION"
BUMPED_PACKAGES="$BUMPED_PACKAGES $PKG_DIR"
cd ../..
fi
# Parse matrix JSON and bump each package
echo "$MATRIX" | jq -r '.[] | .name' | while read -r PKG_NAME; do
echo "Bumping version for $PKG_NAME..."
cd "packages/$PKG_NAME"
OLD_VERSION=$(node -p "require('./package.json').version")
npm version "$BUMP" --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo " $OLD_VERSION -> $NEW_VERSION"
cd ../..
done

echo "Bumped packages:$BUMPED_PACKAGES"

- name: Commit and push version changes
run: |
git add packages/*/package.json
Expand All @@ -180,6 +206,7 @@ jobs:

publish:
needs: [detect-changes, bump-versions]
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -188,120 +215,54 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- name: core
filterKey: pkg_core
npmName: '@message-queue-toolkit/core'

- name: amqp
filterKey: pkg_amqp
npmName: '@message-queue-toolkit/amqp'

- name: sqs
filterKey: pkg_sqs
npmName: '@message-queue-toolkit/sqs'

- name: sns
filterKey: pkg_sns
npmName: '@message-queue-toolkit/sns'

- name: kafka
filterKey: pkg_kafka
npmName: '@message-queue-toolkit/kafka'

- name: gcp-pubsub
filterKey: pkg_gcp_pubsub
npmName: '@message-queue-toolkit/gcp-pubsub'

- name: gcs-payload-store
filterKey: pkg_gcs_payload_store
npmName: '@message-queue-toolkit/gcs-payload-store'

- name: s3-payload-store
filterKey: pkg_s3_payload_store
npmName: '@message-queue-toolkit/s3-payload-store'

- name: metrics
filterKey: pkg_metrics
npmName: '@message-queue-toolkit/metrics'

- name: outbox-core
filterKey: pkg_outbox_core
npmName: '@message-queue-toolkit/outbox-core'

- name: redis-message-deduplication-store
filterKey: pkg_redis_message_deduplication_store
npmName: '@message-queue-toolkit/redis-message-deduplication-store'

- name: schemas
filterKey: pkg_schemas
npmName: '@message-queue-toolkit/schemas'
package: ${{ fromJson(needs.detect-changes.outputs.matrix) }}

concurrency:
group: publish-${{ matrix.name }}
group: publish-${{ matrix.package.name }}
cancel-in-progress: false

steps:
- name: Check if should publish
id: gate
run: |
CHANGED='${{ needs.detect-changes.outputs.changed }}'
echo "Changed packages: $CHANGED"
if echo "$CHANGED" | grep -q '"${{ matrix.filterKey }}"'; then
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "✓ Changes detected in ${{ matrix.name }}"
else
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "⊗ No changes in ${{ matrix.name }}"
fi

- name: Checkout Repository
if: steps.gate.outputs.should_publish == 'true'
uses: actions/checkout@v5
with:
ref: main

- name: Setup Node
if: steps.gate.outputs.should_publish == 'true'
uses: actions/setup-node@v6
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false

- name: Get version
if: steps.gate.outputs.should_publish == 'true'
id: version
working-directory: packages/${{ matrix.name }}
working-directory: packages/${{ matrix.package.name }}
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Publishing version: $VERSION"
echo "Publishing ${{ matrix.package.npmName }}@$VERSION"

- name: Install dependencies
if: steps.gate.outputs.should_publish == 'true'
run: npm install --ignore-scripts

- name: Build package
if: steps.gate.outputs.should_publish == 'true'
run: npm run build -- --filter=${{ matrix.npmName }}
run: npm run build -- --filter=${{ matrix.package.npmName }}

- name: Publish to npm
if: steps.gate.outputs.should_publish == 'true'
working-directory: packages/${{ matrix.name }}
working-directory: packages/${{ matrix.package.name }}
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Summary
if: steps.gate.outputs.should_publish == 'true'
run: |
echo "### Published ${{ matrix.npmName }}@${{ steps.version.outputs.version }} :rocket:" >> $GITHUB_STEP_SUMMARY
echo "### Published ${{ matrix.package.npmName }}@${{ steps.version.outputs.version }} :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[View on npm](https://www.npmjs.com/package/${{ matrix.npmName }})" >> $GITHUB_STEP_SUMMARY
echo "[View on npm](https://www.npmjs.com/package/${{ matrix.package.npmName }})" >> $GITHUB_STEP_SUMMARY

create-tags:
needs: [detect-changes, bump-versions, publish]
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -321,31 +282,13 @@ jobs:

- name: Create tags for published packages
env:
CHANGED: ${{ needs.detect-changes.outputs.changed }}
MATRIX: ${{ needs.detect-changes.outputs.matrix }}
run: |
declare -A PACKAGES=(
["pkg_core"]="core"
["pkg_amqp"]="amqp"
["pkg_sqs"]="sqs"
["pkg_sns"]="sns"
["pkg_kafka"]="kafka"
["pkg_gcp_pubsub"]="gcp-pubsub"
["pkg_gcs_payload_store"]="gcs-payload-store"
["pkg_s3_payload_store"]="s3-payload-store"
["pkg_metrics"]="metrics"
["pkg_outbox_core"]="outbox-core"
["pkg_redis_message_deduplication_store"]="redis-message-deduplication-store"
["pkg_schemas"]="schemas"
)

for key in "${!PACKAGES[@]}"; do
if echo "$CHANGED" | grep -q "\"$key\""; then
PKG_DIR="${PACKAGES[$key]}"
VERSION=$(node -p "require('./packages/$PKG_DIR/package.json').version")
TAG="@message-queue-toolkit/${PKG_DIR}@${VERSION}"
echo "Creating tag: $TAG"
git tag "$TAG" || echo "Tag $TAG already exists"
fi
echo "$MATRIX" | jq -r '.[] | .name' | while read -r PKG_NAME; do
VERSION=$(node -p "require('./packages/$PKG_NAME/package.json').version")
TAG="@message-queue-toolkit/${PKG_NAME}@${VERSION}"
echo "Creating tag: $TAG"
git tag "$TAG" || echo "Tag $TAG already exists"
done

- name: Push tags
Expand Down
2 changes: 1 addition & 1 deletion packages/gcp-pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"peerDependencies": {
"@google-cloud/pubsub": "^5.2.0",
"@message-queue-toolkit/core": ">=24.0.0",
"@message-queue-toolkit/core": ">=24.2.0",
"zod": ">=3.25.76 <5.0.0"
},
"devDependencies": {
Expand Down
Loading