forked from mendix/native-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (103 loc) · 4.79 KB
/
UpdateMinimumMxVersion.yml
File metadata and controls
129 lines (103 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Update Minimum MX Version
on:
workflow_dispatch
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 }}