Skip to content

Commit 15a67db

Browse files
committed
Auto Commit with Custom Branch
Signed-off-by: panyintian.fu <1416297674@qq.com>
1 parent ab34cca commit 15a67db

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

.github/workflows/Auto-Commit.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Auto Commit with Custom Branch
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch_name:
7+
description: 'Enter the new branch name'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
execute-and-commit:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout main branch
16+
uses: actions/checkout@v4
17+
with:
18+
ref: main
19+
20+
- name: Execute test.sh with input
21+
run: |
22+
cd ./storage-charts-repackage/charts/hwameistor-operator
23+
chmod +x upgrade_hwameistor-operator.sh
24+
./upgrade_hwameistor-operator.sh "${{ github.event.inputs.branch_name }}"
25+
26+
- name: Configure Git User
27+
run: |
28+
git config --global user.name "GitHub Actions"
29+
git config --global user.email "actions@github.com"
30+
31+
- name: Create and Push Custom Branch
32+
run: |
33+
34+
NEW_BRANCH="${{ github.event.inputs.branch_name }}"
35+
36+
37+
if [[ ! "$NEW_BRANCH" =~ ^[a-zA-Z0-9_-]+$ ]]; then
38+
echo "Error: Invalid branch name!"
39+
exit 1
40+
fi
41+
42+
43+
if git ls-remote --exit-code --heads origin "$NEW_BRANCH"; then
44+
echo "Error: Branch $NEW_BRANCH already exists!"
45+
exit 1
46+
fi
47+
48+
git checkout -b "$NEW_BRANCH"
49+
50+
if git status --porcelain; then
51+
git add .
52+
git commit -m "Auto-commit: $NEW_BRANCH"
53+
git push origin "$NEW_BRANCH"
54+
echo "Successfully pushed to $NEW_BRANCH"
55+
else
56+
echo "No changes to commit"
57+
fi
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

charts/hwameistor-operator/upgrade_hwameistor-operator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## hwameistor-operator repo: https://github.com/hwameistor/hwameistor-operator
33

44
# /bin/bash
5-
5+
set -x
66
releaseVersion=$1
77

88
[ "$releaseVersion" == "" ] && \

0 commit comments

Comments
 (0)