Skip to content

Commit 993390a

Browse files
authored
Update version_bump.yml
1 parent bb1f9af commit 993390a

File tree

1 file changed

+12
-78
lines changed

1 file changed

+12
-78
lines changed

.github/workflows/version_bump.yml

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
#name: "Version Increment"
2-
#
3-
#on:
4-
# # Run this action on any Pull Request raised against ARM
5-
# # pull_request:
6-
# # Ensure changes re-run the version script (i.e. title change)
7-
# types: [opened, edited, synchronize]
8-
# # Don't run on changes to the below paths
9-
# paths-ignore:
10-
# - 'arm_wiki/**'
11-
# - '.github/**'
12-
#
13-
# # Allows you to run this workflow manually from the Actions tab
14-
# workflow_dispatch:
151
on:
162
pull_request:
173

@@ -41,10 +27,8 @@ jobs:
4127
- name: Determine new version
4228
id: determine-version
4329
env:
44-
# Safely get title (avoid injection attacks)
4530
PR_TITLE: ${{ github.event.pull_request.title }}
4631
run: |
47-
# Set Title environment flag to false
4832
TITLE_FLAG="false"
4933
VERSION_TYPE="false"
5034
@@ -59,19 +43,15 @@ jobs:
5943
TITLE_FLAG="true"
6044
fi
6145
62-
# If Feature or Bugfix update the version
6346
if [[ "$TITLE_FLAG" == "true" ]]; then
64-
# Abort script if version file missing
6547
if [[ ! -f VERSION ]]; then
6648
echo "VERSION file not found! Aborting."
6749
exit 1
6850
fi
6951
70-
# Get branch version
7152
BRANCH_VERSION=$(cat VERSION)
7253
echo "Branch Version: $BRANCH_VERSION"
7354
74-
# Get the main version and split into VERSION_PARTS
7555
IFS='.' read -r -a VERSION_PARTS <<< "$MAIN_VERSION"
7656
if [[ "$VERSION_TYPE" == "minor" ]]; then
7757
VERSION_PARTS[1]=$((VERSION_PARTS[1]+1))
@@ -84,70 +64,24 @@ jobs:
8464
echo "New Version: " $NEW_VERSION
8565
fi
8666
87-
# Set variables to global environment variables for later
8867
echo "TITLE_FLAG=$TITLE_FLAG" >> $GITHUB_ENV
8968
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
9069
echo "VERSION_TYPE=$VERSION_TYPE" >> $GITHUB_ENV
9170
echo "BRANCH_VERSION=$BRANCH_VERSION" >> $GITHUB_ENV
9271
72+
- name: Debug GITHUB_TOKEN
73+
run: echo "GITHUB_TOKEN is: ${{ secrets.GITHUB_TOKEN }}"
74+
9375
- name: Comment on PR with no spam
9476
uses: actions/github-script@v8
77+
env:
78+
TITLE_FLAG: ${{ env.TITLE_FLAG }}
79+
PR_TITLE: ${{ env.PR_TITLE }}
80+
NEW_VERSION: ${{ env.NEW_VERSION }}
81+
MAIN_VERSION: ${{ env.MAIN_VERSION }}
82+
BRANCH_VERSION: ${{ env.BRANCH_VERSION }}
83+
VERSION_TYPE: ${{ env.VERSION_TYPE }}
9584
with:
96-
github-token: ${{ secrets.VERSION_BOT }}
85+
github-token: ${{ secrets.GITHUB_TOKEN }}
9786
script: |
98-
// Retrieve variables from the environment
99-
const titleFlag = process.env.TITLE_FLAG;
100-
const prNumber = context.issue.number;
101-
const prTitle = process.env.PR_TITLE;
102-
const newVersion = process.env.NEW_VERSION;
103-
const currentVersion = process.env.MAIN_VERSION;
104-
const branchVersion = process.env.BRANCH_VERSION;
105-
const versionType = process.env.VERSION_TYPE;
106-
107-
// Prepare the message based on the title flag
108-
let prBody;
109-
if (titleFlag === "false") {
110-
prBody = `ARM Version Bot\n **PR title:** ${prTitle}\n **No valid version flag found**. PR title must include either [FEATURE] or [BUGFIX] to auto-increment the version.\n **Please update the PR title** and re-run the workflow.`;
111-
} else {
112-
prBody = `ARM Version Bot:\n **PR title:** ${prTitle}\n **Current version:** ${currentVersion}\n **Required Version:** ${newVersion}\n **PR Version:** ${branchVersion}\n **Release version:** ${versionType}`;
113-
}
114-
115-
// Get existing comments
116-
const { data: comments } = await github.rest.issues.listComments({
117-
owner: context.repo.owner,
118-
repo: context.repo.repo,
119-
issue_number: prNumber,
120-
per_page: 100
121-
});
122-
123-
// Check for existing version bot comments
124-
const botComment = comments.find(comment =>
125-
comment.user.type === 'Bot' &&
126-
comment.body.includes('Version Bot')
127-
);
128-
129-
// Generate PR comment if not already there
130-
if (botComment) {
131-
// Check if comment aligns with expected output, otherwise update
132-
if (botComment.body !== prBody) {
133-
// Update the existing comment
134-
await github.rest.issues.updateComment({
135-
owner: context.repo.owner,
136-
repo: context.repo.repo,
137-
comment_id: botComment.id,
138-
body: prBody
139-
});
140-
console.log('Updated existing Version Bot comment.');
141-
} else {
142-
console.log('No comment update needed.');
143-
}
144-
} else {
145-
// Creating new comment, no previous comments found
146-
console.log('Creating new comment');
147-
await github.rest.issues.createComment({
148-
owner: context.repo.owner,
149-
repo: context.repo.repo,
150-
issue_number: prNumber,
151-
body: prBody
152-
})
153-
}
87+
// Your script as before

0 commit comments

Comments
 (0)