Botonic Publish #28
Workflow file for this run
This file contains hidden or 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: Botonic Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
version_type: | |
description: 'Type of version upgrade' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- 'patch' | |
- 'minor' | |
packages: | |
description: 'Select packages to deploy (comma-separated)' | |
required: true | |
type: string | |
default: '' | |
deploy_all: | |
description: 'Deploy all packages' | |
required: false | |
type: boolean | |
default: false | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
deploy: | |
name: Deploy with version bump | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.HT_BOTONIC_PUBLISH_APP_ID }} | |
private-key: ${{ secrets.HT_BOTONIC_PUBLISH_APP_PRIVATE_KEY }} | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
cache-dependency-path: '**/package-lock.json' | |
- name: Install dependencies | |
run: npm install | |
- name: Configure NPM | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
# Step 1: Setup helper functions | |
- name: Setup helper functions | |
id: helpers | |
run: | | |
# Copy the helper script to a temporary location for use | |
cp scripts/ci/botonic-publish.sh /tmp/botonic-publish.sh | |
chmod +x /tmp/botonic-publish.sh | |
echo "Utility functions setup complete" | |
# Step 2: Calculate new version | |
- name: Calculate new version | |
id: version | |
run: | | |
source /tmp/botonic-publish.sh | |
if [[ "${{ github.event.inputs.version_type }}" != "patch" ]]; then | |
# For major or minor updates, use botonic-core as reference | |
CURRENT_VERSION=$(get_core_version) | |
else | |
# For patch updates, find highest version | |
CURRENT_VERSION=$(find_highest_version) | |
fi | |
NEW_VERSION=$(calculate_new_version "$CURRENT_VERSION" "${{ github.event.inputs.version_type }}") | |
echo "Current version: $CURRENT_VERSION" | |
echo "New version will be: $NEW_VERSION" | |
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
# Step 4: Deploy selected packages | |
- name: Deploy selected packages | |
id: deploy-packages | |
if: ${{ github.event.inputs.deploy_all != 'true' }} | |
run: | | |
source /tmp/botonic-publish.sh | |
NEW_VERSION=${{ steps.version.outputs.new_version }} | |
DEPLOYED="" | |
# Convert comma-separated string to array | |
IFS=',' read -ra PACKAGES <<< "${{ github.event.inputs.packages }}" | |
# Deploy each selected package | |
for PKG in "${PACKAGES[@]}"; do | |
PKG=$(echo $PKG | xargs) # Trim whitespace | |
if [ -d "packages/$PKG" ]; then | |
deploy_package "$PKG" "$NEW_VERSION" | |
DEPLOYED="${DEPLOYED} $PKG" | |
fi | |
done | |
echo "deployed_packages=${DEPLOYED}" >> $GITHUB_OUTPUT | |
# Step 5: Deploy all packages (for all=true or major version upgrades) | |
- name: Deploy all packages | |
id: deploy-all | |
if: ${{ github.event.inputs.deploy_all == 'true' }} | |
run: | | |
source /tmp/botonic-publish.sh | |
NEW_VERSION=${{ steps.version.outputs.new_version }} | |
DEPLOYED="All packages" | |
# Deploy all packages | |
for PKG_DIR in packages/*; do | |
if [ -d "$PKG_DIR" ]; then | |
PACKAGE_NAME=$(basename $PKG_DIR) | |
deploy_package "$PACKAGE_NAME" "$NEW_VERSION" | |
fi | |
done | |
echo "deployed_packages=${DEPLOYED}" >> $GITHUB_OUTPUT | |
# Step 7: Deploy examples (for major version upgrades) | |
- name: Deploy examples | |
if: ${{ github.event.inputs.version_type == 'major' }} | |
run: | | |
source /tmp/botonic-publish.sh | |
NEW_VERSION=${{ steps.version.outputs.new_version }} | |
echo "Deploying examples for major version upgrade" | |
# Use the function to update dependencies and publish examples | |
version_and_publish_examples "$NEW_VERSION" | |
- name: Get GitHub App User ID | |
id: get-user-id | |
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
- run: | | |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' | |
# git commands like commit work using the bot user | |
- run: | | |
git add . | |
git commit -m "Auto-generated changes" | |
git push | |
- name: Commit version changes | |
run: | | |
git add . | |
git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}" | |
git push | |
# Step 9: Generate deployment summary | |
- name: Deployment summary | |
if: ${{ success() }} | |
run: | | |
echo "## Botonic Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
echo "Version upgrade: **${{ steps.version.outputs.new_version }}** (Type: ${{ github.event.inputs.version_type }})" >> $GITHUB_STEP_SUMMARY | |
if [[ "${{ github.event.inputs.deploy_all }}" == "true" || "${{ github.event.inputs.version_type }}" == "major" ]]; then | |
PACKAGES="All packages" | |
else | |
PACKAGES="${{ steps.deploy-packages.outputs.deployed_packages }}" | |
fi | |
echo "Deployed packages: $PACKAGES" >> $GITHUB_STEP_SUMMARY | |
echo "Deployment completed successfully at $(date)" >> $GITHUB_STEP_SUMMARY | |
- name: Sending Slack notification (success) | |
uses: rtCamp/action-slack-notify@v2 | |
if: success() | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TEAM_PLATFORM }} | |
SLACK_USERNAME: Github | |
SLACK_ICON_EMOJI: ':rocket:' | |
SLACK_CHANNEL: '#team-botonic' | |
SLACK_TITLE: 'Botonic version ${{ steps.version.outputs.new_version }} published succesfully' | |
MSG_MINIMAL: true | |
- name: Sending Slack notification (failure) | |
uses: rtCamp/action-slack-notify@v2 | |
if: failure() | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TEAM_PLATFORM }} | |
SLACK_USERNAME: Github | |
SLACK_ICON_EMOJI: ':bell:' | |
SLACK_COLOR: danger | |
SLACK_CHANNEL: '#team-botonic' | |
SLACK_TITLE: 'Botonic version ${{ steps.version.outputs.new_version }} failed to publish' | |
MSG_MINIMAL: true |