Skip to content

Commit cdbf2dd

Browse files
authored
[MOO-1834]: Add workflow to update minimumMXVersion (#253)
2 parents bfcff26 + a20317e commit cdbf2dd

3 files changed

Lines changed: 173 additions & 11 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Slack Notification'
2+
description: 'Send notification to Slack channel'
3+
4+
inputs:
5+
channel-id:
6+
description: 'Slack channel ID'
7+
required: true
8+
message:
9+
description: 'Message to send'
10+
required: true
11+
bot-token:
12+
description: 'Slack bot token'
13+
required: true
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Send Slack notification
19+
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2
20+
with:
21+
channel-id: ${{ inputs.channel-id }}
22+
slack-message: ${{ inputs.message }}
23+
env:
24+
SLACK_BOT_TOKEN: ${{ inputs.bot-token }}

.github/workflows/MarketplaceRelease.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@ jobs:
4949
TAG: ${{ steps.variables.outputs.tag }}
5050
- name: "Send slack msg on failure"
5151
if: ${{ failure() }}
52-
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 # v2
53-
env:
54-
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
55-
SLACK_COLOR: ${{ job.status }}
56-
SLACK_ICON: ${{ secrets.BOT_IMAGE }}
57-
SLACK_MESSAGE: "Something went wrong while uploading version ${{ steps.scope.outputs._1 }} of package ${{ steps.scope.outputs._0 }} to the marketplace. <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|More info..>"
58-
SLACK_TITLE: ":warning: *Automation Failed*"
59-
SLACK_USERNAME: ${{ secrets.BOT_NAME }}
60-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
61-
SLACK_FOOTER: ${{ secrets.BOT_FOOTER }}
62-
MSG_MINIMAL: true
52+
uses: ./.github/actions/slack-notification
53+
with:
54+
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
55+
message: |
56+
:warning: *Automation Failed*
57+
58+
Something went wrong while uploading version ${{ steps.scope.outputs._1 }} of package ${{ steps.scope.outputs._0 }} to the marketplace. <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|More info..>
59+
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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

Comments
 (0)