Skip to content

Commit 9a06ccd

Browse files
committed
Auto Commit with Custom Branch
Signed-off-by: panyintian.fu <1416297674@qq.com>
1 parent 21907e1 commit 9a06ccd

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

.github/workflows/Auto-Commit.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
chmod +x ./charts/hwameistor-operator/upgrade_hwameistor-operator.s
23+
./charts/hwameistor-operator/upgrade_hwameistor-operator.sh "${{ github.event.inputs.branch_name }}"
24+
25+
- name: Configure Git User
26+
run: |
27+
git config --global user.name "GitHub Actions"
28+
git config --global user.email "actions@github.com"
29+
30+
- name: Create and Push Custom Branch
31+
run: |
32+
33+
NEW_BRANCH="${{ github.event.inputs.branch_name }}"
34+
35+
36+
if [[ ! "$NEW_BRANCH" =~ ^[a-zA-Z0-9_-]+$ ]]; then
37+
echo "Error: Invalid branch name!"
38+
exit 1
39+
fi
40+
41+
42+
if git ls-remote --exit-code --heads origin "$NEW_BRANCH"; then
43+
echo "Error: Branch $NEW_BRANCH already exists!"
44+
exit 1
45+
fi
46+
47+
git checkout -b "$NEW_BRANCH"
48+
49+
if git status --porcelain; then
50+
git add .
51+
git commit -m "Auto-commit: $NEW_BRANCH"
52+
git push origin "$NEW_BRANCH"
53+
echo "Successfully pushed to $NEW_BRANCH"
54+
else
55+
echo "No changes to commit"
56+
fi
57+
env:
58+
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)