Skip to content

Publish

Publish #20

Workflow file for this run

name: Publish
on:
workflow_dispatch:
permissions:
id-token: write
contents: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 24
cache: 'npm'
registry-url: 'https://registry.npmjs.org/'
provenance: false
- name: Configure Git
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com"
- name: Bump version
id: bump-version
run: |
npm version patch --no-git-tag-version
echo "new_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
echo "package_name=$(node -p "require('./package.json').name")" >> $GITHUB_OUTPUT
- name: Update npm to latest
run: npm install -g npm@latest
- name: Install dependencies
run: npm ci
- name: Build package
run: npm run build
- name: Run tests
run: npm test
- name: Publish package
run: npm publish --access public --provenance=false
- name: Commit and push version bump
run: |
git add package.json package-lock.json
git commit -m "Bump version to ${{ steps.bump-version.outputs.new_version }} [skip ci]"
git pull --rebase --autostash
git push
- name: Verify published package
run: |
PACKAGE_NAME="${{ steps.bump-version.outputs.package_name }}"
PACKAGE_VERSION="${{ steps.bump-version.outputs.new_version }}"
# Create temp directory and try installing
TEMP_DIR=$(mktemp -d)
echo "Created temp directory: $TEMP_DIR"
cd "$TEMP_DIR"
npm init -y
# Retry npm install until the version is available (registry propagation can lag)
echo "Waiting for $PACKAGE_NAME@$PACKAGE_VERSION to be available on npm registry..."
for i in {1..100}; do
if npm install "$PACKAGE_NAME@$PACKAGE_VERSION" 2>/dev/null; then
echo "Package available and installed on attempt $i"
break
fi
echo "Attempt $i: Package not yet available, waiting 5s..."
sleep 5
if [ "$i" -eq 100 ]; then
echo "❌ Package never became available after 100 attempts"
exit 1
fi
done
# Verify installation succeeded
NODE_MODULES_PATH="node_modules/$PACKAGE_NAME"
if [ -d "$NODE_MODULES_PATH" ]; then
INSTALLED_VERSION=$(node -p "require('./$NODE_MODULES_PATH/package.json').version")
if [ "$INSTALLED_VERSION" == "$PACKAGE_VERSION" ]; then
echo "✅ Successfully verified installation of $PACKAGE_NAME@$INSTALLED_VERSION"
else
echo "❌ Version mismatch: expected $PACKAGE_VERSION, got $INSTALLED_VERSION"
exit 1
fi
else
echo "❌ Package was not installed correctly"
exit 1
fi
# Cleanup
cd -
rm -rf "$TEMP_DIR"
- name: Notify Slack
if: always()
run: |
# Determine overall status
JOB_STATUS="${{ job.status }}"
PACKAGE_NAME="${{ steps.bump-version.outputs.package_name }}"
PACKAGE_VERSION="${{ steps.bump-version.outputs.new_version }}"
if [ "$JOB_STATUS" == "success" ]; then
OVERALL_STATUS="✅ *$PACKAGE_NAME Publish Succeeded!*"
COLOR="good"
else
OVERALL_STATUS="❌ *$PACKAGE_NAME Publish Failed!*"
COLOR="danger"
fi
# Get commit info
COMMIT_MSG=$(git log -1 --pretty=%B | head -1)
COMMIT_AUTHOR=$(git log -1 --pretty=%an)
COMMIT_SHA=$(git rev-parse --short HEAD)
curl -X POST "${{ secrets.GENESYS_SLACK_WEBHOOK_URL }}" \
-H 'Content-Type: application/json' \
-d "{
\"attachments\": [
{
\"color\": \"$COLOR\",
\"title\": \"$OVERALL_STATUS\",
\"text\": \"$PACKAGE_NAME publish workflow completed\",
\"fields\": [
{
\"title\": \"Version\",
\"value\": \"$PACKAGE_VERSION\",
\"short\": true
},
{
\"title\": \"Status\",
\"value\": \"$JOB_STATUS\",
\"short\": true
},
{
\"title\": \"Commit\",
\"value\": \"<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|$COMMIT_SHA: $COMMIT_MSG>\",
\"short\": false
},
{
\"title\": \"Author\",
\"value\": \"$COMMIT_AUTHOR\",
\"short\": true
}
],
\"footer\": \"GitHub Actions\",
\"footer_icon\": \"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png\",
\"actions\": [
{
\"type\": \"button\",
\"text\": \"View Workflow\",
\"url\": \"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"
}
]
}
]
}"