Skip to content

Commit 7ac91ac

Browse files
ci: Implement review workflows (#1675)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3de98e7 commit 7ac91ac

File tree

4 files changed

+112
-44
lines changed

4 files changed

+112
-44
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ jobs:
183183
echo -n "${{ steps.commit.outputs.sha }}" > rcc-smoke-sha.txt
184184
shell: bash
185185
186-
- uses: actions/upload-artifact@v4
186+
- uses: actions/upload-artifact@v5
187187
with:
188188
name: rcc-smoke-sha
189189
path: rcc-smoke-sha.txt

.github/workflows/commit/action.yml

Lines changed: 105 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,116 @@ runs:
2727
id: repo-state
2828
uses: ./.github/workflows/repo-state
2929

30-
- name: Commit if changed, create a PR if protected
31-
id: commit
32-
if: steps.check.outputs.has_changes == 'true'
30+
- name: Commit and create PR on protected branch
31+
if: steps.check.outputs.has_changes == 'true' && steps.repo-state.outputs.foreign == 'false' && steps.repo-state.outputs.protected == 'true'
3332
env:
3433
GITHUB_TOKEN: ${{ inputs.token }}
3534
run: |
3635
set -x
37-
protected=${{ steps.repo-state.outputs.protected }}
38-
foreign=${{ steps.repo-state.outputs.foreign }}
39-
is_pr=${{ steps.repo-state.outputs.is_pr }}
40-
if [ "${foreign}" = "true" ]; then
41-
# https://github.com/krlmlr/actions-sync/issues/44
42-
echo "Can't push to foreign branch"
43-
exit 1
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
53-
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}"
57-
else
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
60-
61-
gh workflow run rcc -f ref=$(git rev-parse HEAD)
62-
gh pr merge --merge --auto
36+
current_branch=$(git branch --show-current)
37+
new_branch=gha-commit-$(git rev-parse --short HEAD)
38+
git checkout -b ${new_branch}
39+
git add .
40+
git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
41+
# Force-push, used in only one place
42+
# Alternative: separate branch names for each usage
43+
git push -u origin HEAD -f
44+
45+
existing_pr=$(gh pr list --state open --base main --head ${new_branch} --json number --jq '.[] | .number')
46+
if [ -n "${existing_pr}" ]; then
47+
echo "Existing PR: ${existing_pr}"
6348
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
71-
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
49+
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}"
50+
fi
51+
52+
gh workflow run rcc -f ref=$(git rev-parse HEAD)
53+
gh pr merge --merge --auto
54+
shell: bash
7555

76-
# Only set output if changed
77-
echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
56+
- name: Commit and push on unprotected branch
57+
id: commit
58+
if: steps.check.outputs.has_changes == 'true' && steps.repo-state.outputs.foreign == 'false' && steps.repo-state.outputs.protected == 'false'
59+
env:
60+
GITHUB_TOKEN: ${{ inputs.token }}
61+
run: |
62+
set -x
63+
git fetch
64+
if [ -n "${GITHUB_HEAD_REF}" ]; then
65+
git add .
66+
git stash save
67+
git switch ${GITHUB_HEAD_REF}
68+
git merge origin/${GITHUB_BASE_REF} --no-edit
69+
git stash pop
7870
fi
71+
git add .
72+
git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
73+
git push -u origin HEAD
74+
75+
# Only set output if changed
76+
echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
77+
shell: bash
78+
79+
- name: Create patch file for foreign branch
80+
if: steps.check.outputs.has_changes == 'true' && steps.repo-state.outputs.foreign == 'true'
81+
run: |
82+
set -x
83+
git diff > changes.patch
84+
echo "Patch file created with uncommitted changes"
85+
cat changes.patch
86+
shell: bash
87+
88+
- name: Upload patch artifact
89+
if: steps.check.outputs.has_changes == 'true' && steps.repo-state.outputs.foreign == 'true'
90+
uses: actions/upload-artifact@v5
91+
with:
92+
name: changes-patch
93+
path: changes.patch
94+
95+
- name: Add patch summary on foreign branch
96+
if: steps.check.outputs.has_changes == 'true' && steps.repo-state.outputs.foreign == 'true'
97+
run: |
98+
cat << 'EOF' >> $GITHUB_STEP_SUMMARY
99+
## Formatting suggestions available
100+
101+
A patch file with formatting suggestions has been generated. Since this PR is from a forked repository, the changes cannot be pushed automatically.
102+
103+
You can apply the patch using one of these methods:
104+
105+
### Method 1: Apply via gh CLI
106+
107+
```bash
108+
# Download and apply the patch directly
109+
gh run download ${{ github.run_id }} --repo ${{ github.repository }} --name changes-patch && git apply changes.patch && rm changes.patch
110+
```
111+
112+
### Method 2: Download from workflow artifacts
113+
114+
1. Download the `changes-patch` artifact from this workflow run
115+
2. Extract and apply it:
116+
```bash
117+
git apply changes.patch
118+
```
119+
120+
### Method 3: View the patch
121+
122+
<details>
123+
<summary>Click to see the patch contents</summary>
124+
125+
```diff
126+
EOF
127+
128+
cat changes.patch >> $GITHUB_STEP_SUMMARY
129+
130+
cat << 'EOF' >> $GITHUB_STEP_SUMMARY
131+
```
132+
133+
</details>
134+
EOF
135+
shell: bash
136+
137+
- name: Fail on foreign branch
138+
if: steps.check.outputs.has_changes == 'true' && steps.repo-state.outputs.foreign == 'true'
139+
run: |
140+
echo "Exiting with failure due to foreign branch. Please apply the patch suggested in the action or PR comment."
141+
exit 1
79142
shell: bash

.github/workflows/covr/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ runs:
4040

4141
- name: Upload test results
4242
if: failure()
43-
uses: actions/upload-artifact@v4
43+
uses: actions/upload-artifact@v5
4444
with:
4545
name: coverage-test-failures
4646
path: ${{ runner.temp }}/package

.github/workflows/update-snapshots/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,8 @@ runs:
9292
run: |
9393
false
9494
shell: bash
95+
96+
- name: Reset Git changes
97+
run: |
98+
git reset -- tests/testthat/_snaps
99+
shell: bash

0 commit comments

Comments
 (0)