|
| 1 | +name: Update Minimum MX Version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + package_path: |
| 7 | + description: "Select the package to update" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - packages/jsActions/mobile-resources-native |
| 12 | + - packages/jsActions/nanoflow-actions-native |
| 13 | + new_version: |
| 14 | + description: "New minimumMXVersion value" |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +jobs: |
| 19 | + update-version: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4 |
| 26 | + with: |
| 27 | + node-version: "20" |
| 28 | + |
| 29 | + - name: Configure Git |
| 30 | + run: | |
| 31 | + git config --global user.name "github-actions[bot]" |
| 32 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 33 | +
|
| 34 | + - name: Update minimumMXVersion |
| 35 | + id: update-version |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + run: | |
| 39 | + # Read package.json file |
| 40 | + PACKAGE_JSON="${{ inputs.package_path }}/package.json" |
| 41 | + CURRENT_VERSION=$(node -p "require('./$PACKAGE_JSON').marketplace.minimumMXVersion") |
| 42 | +
|
| 43 | + # Convert current version to major.minor.x format (ignoring build number) |
| 44 | + CURRENT_VERSION_X=$(echo $CURRENT_VERSION | sed -E 's/^([0-9]+)\.([0-9]+)\.[0-9]+(\.[0-9]+)?/\1.\2.x/') |
| 45 | +
|
| 46 | + # Create branch for minimumMXVersion update |
| 47 | + MIN_VERSION_BRANCH="update-min-version/${{ inputs.new_version }}" |
| 48 | + git checkout -b $MIN_VERSION_BRANCH |
| 49 | +
|
| 50 | + # Update package.json - only minimumMXVersion |
| 51 | + node -e " |
| 52 | + const fs = require('fs'); |
| 53 | + const path = require('path'); |
| 54 | + const packageJson = require('./$PACKAGE_JSON'); |
| 55 | + |
| 56 | + packageJson.marketplace.minimumMXVersion = '${{ inputs.new_version }}'; |
| 57 | + |
| 58 | + fs.writeFileSync( |
| 59 | + path.resolve('./$PACKAGE_JSON'), |
| 60 | + JSON.stringify(packageJson, null, 2) |
| 61 | + ); |
| 62 | + " |
| 63 | +
|
| 64 | + # Commit changes |
| 65 | + git add $PACKAGE_JSON |
| 66 | + git commit -m "chore: update minimumMXVersion to ${{ inputs.new_version }}" |
| 67 | +
|
| 68 | + # Push branch |
| 69 | + git push origin $MIN_VERSION_BRANCH |
| 70 | +
|
| 71 | + # Create PR for minimumMXVersion update |
| 72 | + gh pr create \ |
| 73 | + --title "chore: update minimumMXVersion to ${{ inputs.new_version }}" \ |
| 74 | + --body "This PR updates the minimumMXVersion to ${{ inputs.new_version }} in ${{ inputs.package_path }}" \ |
| 75 | + --base main \ |
| 76 | + --head $MIN_VERSION_BRANCH |
| 77 | +
|
| 78 | + # Get PR URL by listing PRs and finding the one with our branch |
| 79 | + PR_URL=$(gh pr list --head $MIN_VERSION_BRANCH --json url --jq '.[0].url') |
| 80 | +
|
| 81 | + # Switch back to main branch for creating the second branch |
| 82 | + git checkout main |
| 83 | + git pull origin main |
| 84 | +
|
| 85 | + # Create new branch for branchName update from main |
| 86 | + BRANCH_NAME="version/$CURRENT_VERSION_X" |
| 87 | + git checkout -b $BRANCH_NAME |
| 88 | +
|
| 89 | + # Update package.json in new branch - only branchName |
| 90 | + node -e " |
| 91 | + const fs = require('fs'); |
| 92 | + const path = require('path'); |
| 93 | + const packageJson = require('./$PACKAGE_JSON'); |
| 94 | + |
| 95 | + packageJson.testProject.branchName = 'mx/$CURRENT_VERSION_X'; |
| 96 | + |
| 97 | + fs.writeFileSync( |
| 98 | + path.resolve('./$PACKAGE_JSON'), |
| 99 | + JSON.stringify(packageJson, null, 2) |
| 100 | + ); |
| 101 | + " |
| 102 | +
|
| 103 | + # Commit changes in new branch |
| 104 | + git add $PACKAGE_JSON |
| 105 | + git commit -m "chore: update branchName to mx/$CURRENT_VERSION_X" |
| 106 | +
|
| 107 | + # Push new branch |
| 108 | + git push origin $BRANCH_NAME |
| 109 | +
|
| 110 | + # Set outputs for other steps |
| 111 | + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 112 | + echo "min_version_branch=$MIN_VERSION_BRANCH" >> $GITHUB_OUTPUT |
| 113 | + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 114 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 115 | +
|
| 116 | + - name: Send Slack notification for first PR |
| 117 | + uses: ./.github/actions/slack-notification |
| 118 | + with: |
| 119 | + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} |
| 120 | + message: | |
| 121 | + 🚀 *Minimum MX Version Update* |
| 122 | +
|
| 123 | + *Package:* ${{ inputs.package_path }} |
| 124 | + *Current Version:* ${{ steps.update-version.outputs.current_version }} |
| 125 | + *New Version:* ${{ inputs.new_version }} |
| 126 | + *PR:* <${{ steps.update-version.outputs.pr_url }}|View PR> |
| 127 | + *Branch:* ${{ steps.update-version.outputs.min_version_branch }} |
| 128 | + bot-token: ${{ secrets.SLACK_BOT_TOKEN }} |
| 129 | + |
| 130 | + - name: Send Slack notification for second branch |
| 131 | + uses: ./.github/actions/slack-notification |
| 132 | + with: |
| 133 | + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} |
| 134 | + message: | |
| 135 | + 🔄 *Branch Name Update* |
| 136 | +
|
| 137 | + *Package:* ${{ inputs.package_path }} |
| 138 | + *Current Version:* ${{ steps.update-version.outputs.current_version }} |
| 139 | + *New Version:* ${{ inputs.new_version }} |
| 140 | + *Branch:* ${{ steps.update-version.outputs.branch_name }} |
| 141 | + bot-token: ${{ secrets.SLACK_BOT_TOKEN }} |
0 commit comments