Skip to content

Commit

Permalink
Workflow push fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vatsal Gupta committed Nov 23, 2024
1 parent 0a72353 commit b624362
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions .github/workflows/shell-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,22 @@ jobs:
run:
shell: bash
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install shfmt
run: |
sudo apt-get install shfmt -y
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Format Shell Scripts
run: |
find . -type f -name "*.sh" -exec shfmt -w -i 4 {} \;
- name: Commit and Push Changes
run: |
# Check if there are any changes in the diff
git diff --exit-code || (
# Configure git with the bot's user details
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Get the branch name from the GitHub event (use the source branch of the PR)
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Checkout the branch
git checkout ${BRANCH_NAME}
# Stage the changes
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
# Commit changes if any are present
git commit -m "Format shell scripts with shfmt" || echo "No changes to commit"
# Push the changes to the correct branch (if not in a PR, this defaults to the current branch)
git push -f https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:${BRANCH_NAME}
git commit -m "Format shell scripts with shfmt"
git push -f
)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit b624362

Please sign in to comment.