I am trying to setup a github action but I have an invalid yaml syntax on line 20 run: echo "Merged PR detected: ${{ github.event.pull_request.head.ref }}"
:
<code>name: Auto Delete Feature Branch
on:
pull_request:
types: [closed]
branches:
- develop
push:
branches:
- develop
jobs:
delete-branch:
runs-on: ubuntu-latest
steps:
- name: Check if it's a merged PR
if: github.event.pull_request.merged == true
id: check_merge
run: echo "Merged PR detected: ${{ github.event.pull_request.head.ref }}"
- name: Set branch name from merged PR
if: github.event.pull_request.merged == true
id: set_branch_name_from_pr
run: echo "::set-output name=BRANCH_NAME::${{ github.event.pull_request.head.ref }}"
- name: Set branch name from commit message
if: github.event.pull_request.merged != true
id: set_branch_name_from_commit
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MESSAGE" =~ Merge branch 'feature/([^']+)' ]]; then
echo "::set-output name=BRANCH_NAME::feature/${BASH_REMATCH[1]}"
else
echo "::set-output name=BRANCH_NAME::"
fi
- name: Delete feature branch
if: steps.set_branch_name_from_pr.outputs.BRANCH_NAME != '' || steps.set_branch_name_from_commit.outputs.BRANCH_NAME != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME=${{ steps.set_branch_name_from_pr.outputs.BRANCH_NAME || steps.set_branch_name_from_commit.outputs.BRANCH_NAME }}
if [[ $BRANCH_NAME == feature/* ]]; then
git push origin --delete $BRANCH_NAME
else
echo "No feature branch to delete"
fi
</code>
<code>name: Auto Delete Feature Branch
on:
pull_request:
types: [closed]
branches:
- develop
push:
branches:
- develop
jobs:
delete-branch:
runs-on: ubuntu-latest
steps:
- name: Check if it's a merged PR
if: github.event.pull_request.merged == true
id: check_merge
run: echo "Merged PR detected: ${{ github.event.pull_request.head.ref }}"
- name: Set branch name from merged PR
if: github.event.pull_request.merged == true
id: set_branch_name_from_pr
run: echo "::set-output name=BRANCH_NAME::${{ github.event.pull_request.head.ref }}"
- name: Set branch name from commit message
if: github.event.pull_request.merged != true
id: set_branch_name_from_commit
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MESSAGE" =~ Merge branch 'feature/([^']+)' ]]; then
echo "::set-output name=BRANCH_NAME::feature/${BASH_REMATCH[1]}"
else
echo "::set-output name=BRANCH_NAME::"
fi
- name: Delete feature branch
if: steps.set_branch_name_from_pr.outputs.BRANCH_NAME != '' || steps.set_branch_name_from_commit.outputs.BRANCH_NAME != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME=${{ steps.set_branch_name_from_pr.outputs.BRANCH_NAME || steps.set_branch_name_from_commit.outputs.BRANCH_NAME }}
if [[ $BRANCH_NAME == feature/* ]]; then
git push origin --delete $BRANCH_NAME
else
echo "No feature branch to delete"
fi
</code>
name: Auto Delete Feature Branch
on:
pull_request:
types: [closed]
branches:
- develop
push:
branches:
- develop
jobs:
delete-branch:
runs-on: ubuntu-latest
steps:
- name: Check if it's a merged PR
if: github.event.pull_request.merged == true
id: check_merge
run: echo "Merged PR detected: ${{ github.event.pull_request.head.ref }}"
- name: Set branch name from merged PR
if: github.event.pull_request.merged == true
id: set_branch_name_from_pr
run: echo "::set-output name=BRANCH_NAME::${{ github.event.pull_request.head.ref }}"
- name: Set branch name from commit message
if: github.event.pull_request.merged != true
id: set_branch_name_from_commit
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MESSAGE" =~ Merge branch 'feature/([^']+)' ]]; then
echo "::set-output name=BRANCH_NAME::feature/${BASH_REMATCH[1]}"
else
echo "::set-output name=BRANCH_NAME::"
fi
- name: Delete feature branch
if: steps.set_branch_name_from_pr.outputs.BRANCH_NAME != '' || steps.set_branch_name_from_commit.outputs.BRANCH_NAME != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME=${{ steps.set_branch_name_from_pr.outputs.BRANCH_NAME || steps.set_branch_name_from_commit.outputs.BRANCH_NAME }}
if [[ $BRANCH_NAME == feature/* ]]; then
git push origin --delete $BRANCH_NAME
else
echo "No feature branch to delete"
fi
I am quite new to yaml so I don’t know what is wrong with this syntax. I tried using a linter on the internet and it says Nested mappings are not allowed in compact mappings at line 20, column 12 but I could not find what it means.