Auto Commit with Custom Branch #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Commit with Custom Branch | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch_name: | |
| description: 'Enter the new branch name' | |
| required: true | |
| type: string | |
| jobs: | |
| execute-and-commit: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Execute upgrade_hwameistor-operator.sh with input | |
| run: | | |
| cd ./charts/hwameistor-operator | |
| chmod +x upgrade_hwameistor-operator.sh | |
| ./upgrade_hwameistor-operator.sh "${{ github.event.inputs.branch_name }}" | |
| - name: Configure Git User | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| - name: Create and Push Custom Branch | |
| run: | | |
| NEW_BRANCH="${{ github.event.inputs.branch_name }}" | |
| if git ls-remote --exit-code --heads origin "$NEW_BRANCH"; then | |
| echo "Error: Branch $NEW_BRANCH already exists!" | |
| exit 1 | |
| fi | |
| git checkout -b "$NEW_BRANCH" | |
| if git status --porcelain; then | |
| git add . | |
| git commit -m "Auto-commit: $NEW_BRANCH" | |
| git push origin "$NEW_BRANCH" | |
| echo "Successfully pushed to $NEW_BRANCH" | |
| else | |
| echo "No changes to commit" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |