Skip to content

Commit 82b142e

Browse files
jennybckrlmlrgithub-actions[bot]
authored
feat: is_vscode_project looks for .vscode/settings.json instead of just .vscode/ (#163)
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kirill Müller <krlmlr@users.noreply.github.com> Co-authored-by: Kirill Müller <kirill@cynkra.com>
1 parent 4032a5a commit 82b142e

File tree

5 files changed

+74
-46
lines changed

5 files changed

+74
-46
lines changed

.github/workflows/commit/action.yml

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,76 @@ outputs:
1111
runs:
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"

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,24 @@ runs:
5656
if: ${{ steps.run-tests.outputs.changed }}
5757
id: check-changed
5858
run: |
59-
echo "changed=$(git status --porcelain -- tests/testthat/_snaps | head -n 1)" >> $GITHUB_OUTPUT
59+
set -x
60+
if [ "${{ github.event_name}}" != "pull_request" ] ; then
61+
echo "changed=$(git status --porcelain -- tests/testthat/_snaps | head -n 1)" | tee -a $GITHUB_OUTPUT
62+
fi
6063
shell: bash
6164

6265
- name: Derive branch name
6366
if: ${{ steps.check-changed.outputs.changed }}
6467
id: matrix-desc
6568
run: |
69+
set -x
6670
config=$(echo '${{ toJSON(matrix) }}' | jq -c .)
67-
echo "text=$(echo ${config})" >> $GITHUB_OUTPUT
68-
echo "branch=$(echo ${config} | sed -r 's/[^0-9a-zA-Z]+/-/g;s/^-//;s/-$//')" >> $GITHUB_OUTPUT
71+
echo "text=$(echo ${config})" | tee -a $GITHUB_OUTPUT
72+
echo "branch=$(echo ${config} | sed -r 's/[^0-9a-zA-Z]+/-/g;s/^-//;s/-$//')" | tee -a $GITHUB_OUTPUT
6973
shell: bash
7074

7175
- name: Create pull request
76+
# Fall through if PR, will use reviewdog/action-suggester in the commit action
7277
if: ${{ steps.check-changed.outputs.changed }}
7378
id: cpr
7479
uses: peter-evans/create-pull-request@v6

R/root.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ has_basename <- function(basename, subdir = NULL) {
313313
is_rstudio_project <- has_file_pattern("[.]Rproj$", contents = "^Version: ", n = 1L)
314314

315315
#' @export
316-
is_vscode_project <- has_dir(".vscode")
316+
is_vscode_project <- has_file(".vscode/settings.json")
317317

318318
#' @export
319319
is_r_package <- has_file("DESCRIPTION", contents = "^Package: ")
@@ -401,7 +401,7 @@ str.root_criteria <- function(object, ...) {
401401
"is_rstudio_project"
402402

403403
#' @details
404-
#' `is_vscode_project` looks for a `.vscode` directory.
404+
#' `is_vscode_project` looks for a `.vscode/settings.json` file.
405405
#'
406406
#' @format NULL
407407
#' @rdname criteria

man/criteria.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/root.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
Root criterion: contains a file matching '[.]Rproj$' with contents matching '^Version: ' in the first line
4646
4747
$is_vscode_project
48-
Root criterion: contains a directory '.vscode'
48+
Root criterion: contains a file '.vscode/settings.json'
4949
5050
$is_r_package
5151
Root criterion: contains a file 'DESCRIPTION' with contents matching '^Package: '
@@ -101,7 +101,7 @@
101101
Output
102102
List of 13
103103
$ is_rstudio_project : chr "Root criterion: contains a file matching '[.]Rproj$' with contents matching '^Version: ' in the first line"
104-
$ is_vscode_project : chr "Root criterion: contains a directory '.vscode'"
104+
$ is_vscode_project : chr "Root criterion: contains a file '.vscode/settings.json'"
105105
$ is_r_package : chr "Root criterion: contains a file 'DESCRIPTION' with contents matching '^Package: '"
106106
$ is_remake_project : chr "Root criterion: contains a file 'remake.yml'"
107107
$ is_pkgdown_project : chr [1:7] "Root criterion: one of" "- contains a file '_pkgdown.yml'" "- contains a file '_pkgdown.yaml'" "- contains a file 'pkgdown/_pkgdown.yml'" ...

0 commit comments

Comments
 (0)