Skip to content

Update Minimum MX Version #4

Update Minimum MX Version

Update Minimum MX Version #4

name: Update Minimum MX Version
on:
workflow_dispatch:
inputs:
package_path:
description: "Select the package to update"
required: true
type: choice
options:
- packages/jsActions/mobile-resources-native
- packages/jsActions/nanoflow-actions-native
new_version:
description: "New minimumMXVersion value"
required: true
type: string
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup Node.js
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
with:
node-version: "20"
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Update minimumMXVersion
id: update-version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Read package.json file
PACKAGE_JSON="${{ inputs.package_path }}/package.json"
CURRENT_VERSION=$(node -p "require('./$PACKAGE_JSON').marketplace.minimumMXVersion")
# Convert current version to major.minor.x format (ignoring build number)
CURRENT_VERSION_X=$(echo $CURRENT_VERSION | sed -E 's/^([0-9]+)\.([0-9]+)\.[0-9]+(\.[0-9]+)?/\1.\2.x/')
# Create branch for minimumMXVersion update
MIN_VERSION_BRANCH="update-min-version/${{ inputs.new_version }}"
git checkout -b $MIN_VERSION_BRANCH
# Update package.json - only minimumMXVersion
node -e "
const fs = require('fs');
const path = require('path');
const packageJson = require('./$PACKAGE_JSON');
packageJson.marketplace.minimumMXVersion = '${{ inputs.new_version }}';
fs.writeFileSync(
path.resolve('./$PACKAGE_JSON'),
JSON.stringify(packageJson, null, 2)
);
"
# Commit changes
git add $PACKAGE_JSON
git commit -m "chore: update minimumMXVersion to ${{ inputs.new_version }}"
# Push branch
git push origin $MIN_VERSION_BRANCH
# Create PR for minimumMXVersion update
gh pr create \
--title "chore: update minimumMXVersion to ${{ inputs.new_version }}" \
--body "This PR updates the minimumMXVersion to ${{ inputs.new_version }} in ${{ inputs.package_path }}" \
--base main \
--head $MIN_VERSION_BRANCH
# Get PR URL by listing PRs and finding the one with our branch
PR_URL=$(gh pr list --head $MIN_VERSION_BRANCH --json url --jq '.[0].url')
# Switch back to main branch for creating the second branch
git checkout main
git pull origin main
# Create new branch for branchName update from main
BRANCH_NAME="version/$CURRENT_VERSION_X"
git checkout -b $BRANCH_NAME
# Update package.json in new branch - only branchName
node -e "
const fs = require('fs');
const path = require('path');
const packageJson = require('./$PACKAGE_JSON');
packageJson.testProject.branchName = 'mx/$CURRENT_VERSION_X';
fs.writeFileSync(
path.resolve('./$PACKAGE_JSON'),
JSON.stringify(packageJson, null, 2)
);
"
# Commit changes in new branch
git add $PACKAGE_JSON
git commit -m "chore: update branchName to mx/$CURRENT_VERSION_X"
# Push new branch
git push origin $BRANCH_NAME
# Set outputs for other steps
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "min_version_branch=$MIN_VERSION_BRANCH" >> $GITHUB_OUTPUT
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
- name: Send Slack notification for first PR
uses: ./.github/actions/slack-notification
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
message: |
🚀 *Minimum MX Version Update*
*Package:* ${{ inputs.package_path }}
*Current Version:* ${{ steps.update-version.outputs.current_version }}
*New Version:* ${{ inputs.new_version }}
*PR:* <${{ steps.update-version.outputs.pr_url }}|View PR>
*Branch:* ${{ steps.update-version.outputs.min_version_branch }}
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Send Slack notification for second branch
uses: ./.github/actions/slack-notification
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
message: |
🔄 *Branch Name Update*
*Package:* ${{ inputs.package_path }}
*Current Version:* ${{ steps.update-version.outputs.current_version }}
*New Version:* ${{ inputs.new_version }}
*Branch:* ${{ steps.update-version.outputs.branch_name }}
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}