@@ -11,53 +11,76 @@ outputs:
1111runs :
1212 using : " composite"
1313 steps :
14+ - name : Check for changes
15+ id : check
16+ run : |
17+ set -x
18+ if [ -n "$(git status --porcelain)" ]; then
19+ echo "has_changes=true" | tee -a $GITHUB_OUTPUT
20+ else
21+ echo "has_changes=false" | tee -a $GITHUB_OUTPUT
22+ fi
23+ shell : bash
24+
1425 - name : Commit if changed, create a PR if protected
1526 id : commit
27+ if : steps.check.outputs.has_changes == 'true'
1628 env :
1729 GITHUB_TOKEN : ${{ inputs.token }}
1830 run : |
1931 set -x
20- if [ -n "$(git status --porcelain)" ]; then
21- echo "Changed"
22- protected=${{ github.ref_protected }}
23- foreign=${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
24- if [ "${foreign}" = "true" ]; then
25- # https://github.com/krlmlr/actions-sync/issues/44
26- echo "Can't push to foreign branch"
27- elif [ "${protected}" = "true" ]; then
28- current_branch=$(git branch --show-current)
29- new_branch=gha-commit-$(git rev-parse --short HEAD)
30- git checkout -b ${new_branch}
31- git add .
32- git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
33- # Force-push, used in only one place
34- # Alternative: separate branch names for each usage
35- git push -u origin HEAD -f
36-
37- existing_pr=$(gh pr list --state open --base main --head ${new_branch} --json number --jq '.[] | .number')
38- if [ -n "${existing_pr}" ]; then
39- echo "Existing PR: ${existing_pr}"
40- else
41- gh pr create --base main --head ${new_branch} --title "chore: Auto-update from GitHub Actions" --body "Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
42- fi
32+ protected=${{ github.ref_protected }}
33+ foreign=${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
34+ is_pr=${{ github.event_name == 'pull_request' }}
35+ if [ "${is_pr}" = "true" ]; then
36+ # Running on a PR - will use reviewdog in next step
37+ echo "Code changes detected on PR, will suggest changes via reviewdog"
38+ echo "use_reviewdog=true" | tee -a $GITHUB_OUTPUT
39+ git reset HEAD
40+ git status
41+ elif [ "${foreign}" = "true" ]; then
42+ # https://github.com/krlmlr/actions-sync/issues/44
43+ echo "Can't push to foreign branch"
44+ elif [ "${protected}" = "true" ]; then
45+ current_branch=$(git branch --show-current)
46+ new_branch=gha-commit-$(git rev-parse --short HEAD)
47+ git checkout -b ${new_branch}
48+ git add .
49+ git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
50+ # Force-push, used in only one place
51+ # Alternative: separate branch names for each usage
52+ git push -u origin HEAD -f
4353
44- gh workflow run rcc -f ref=$(git rev-parse HEAD)
45- gh pr merge --merge --auto
54+ existing_pr=$(gh pr list --state open --base main --head ${new_branch} --json number --jq '.[] | .number')
55+ if [ -n "${existing_pr}" ]; then
56+ echo "Existing PR: ${existing_pr}"
4657 else
47- git fetch
48- if [ -n "${GITHUB_HEAD_REF}" ]; then
49- git add .
50- git stash save
51- git switch ${GITHUB_HEAD_REF}
52- git merge origin/${GITHUB_BASE_REF} --no-edit
53- git stash pop
54- fi
55- git add .
56- git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
57- git push -u origin HEAD
58+ gh pr create --base main --head ${new_branch} --title "chore: Auto-update from GitHub Actions" --body "Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
59+ fi
5860
59- # Only set output if changed
60- echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
61+ gh workflow run rcc -f ref=$(git rev-parse HEAD)
62+ gh pr merge --merge --auto
63+ else
64+ git fetch
65+ if [ -n "${GITHUB_HEAD_REF}" ]; then
66+ git add .
67+ git stash save
68+ git switch ${GITHUB_HEAD_REF}
69+ git merge origin/${GITHUB_BASE_REF} --no-edit
70+ git stash pop
6171 fi
72+ git add .
73+ git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
74+ git push -u origin HEAD
75+
76+ # Only set output if changed
77+ echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
6278 fi
6379 shell : bash
80+
81+ - name : Suggest changes via reviewdog
82+ if : steps.commit.outputs.use_reviewdog == 'true'
83+ uses : krlmlr/action-suggester@main
84+ with :
85+ github_token : ${{ inputs.token }}
86+ tool_name : " rcc"
0 commit comments