Skip to content

Commit 75eb4f2

Browse files
committed
ci: Sync with latest developments
1 parent 97dbad9 commit 75eb4f2

File tree

9 files changed

+157
-80
lines changed

9 files changed

+157
-80
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101

102102
runs-on: ubuntu-22.04
103103

104-
name: ${{ matrix.package }}
104+
name: 'rcc-dev: ${{ matrix.package }}'
105105

106106
# Begin custom: services
107107
# End custom: services
@@ -147,4 +147,4 @@ jobs:
147147

148148
- uses: ./.github/workflows/check
149149
with:
150-
results: ${{ matrix.package }}
150+
results: ${{ matrix.package }}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ on:
1313
branches:
1414
- main
1515
- master
16+
workflow_dispatch:
17+
inputs:
18+
ref:
19+
description: "Branch or tag to check out"
20+
required: false
21+
default: "main"
22+
merge_group:
23+
types:
24+
- checks_requested
1625
schedule:
1726
- cron: "10 0 * * *"
1827

1928
concurrency:
20-
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.sha }}-${{ github.base_ref || '' }}
29+
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.ref || github.head_ref || github.sha }}-${{ github.base_ref || '' }}
2130
cancel-in-progress: true
2231

2332
name: rcc
@@ -35,6 +44,8 @@ jobs:
3544

3645
steps:
3746
- uses: actions/checkout@v4
47+
with:
48+
ref: ${{ inputs.ref }}
3849

3950
- uses: ./.github/workflows/rate-limit
4051
with:
@@ -59,6 +70,9 @@ jobs:
5970
- uses: ./.github/workflows/versions-matrix
6071
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
6172

73+
- uses: ./.github/workflows/dep-suggests-matrix
74+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
75+
6276
- uses: ./.github/workflows/update-snapshots
6377
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
6478

@@ -71,6 +85,8 @@ jobs:
7185
- id: commit
7286
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
7387
uses: ./.github/workflows/commit
88+
with:
89+
token: ${{ secrets.GITHUB_TOKEN }}
7490

7591
- uses: ./.github/workflows/check
7692
with:
@@ -151,7 +167,7 @@ jobs:
151167

152168
runs-on: ${{ matrix.os }}
153169

154-
name: ${{ matrix.os }} (${{ matrix.r }}) ${{ matrix.desc }}
170+
name: 'rcc: ${{ matrix.os }} (${{ matrix.r }}) ${{ matrix.desc }}'
155171

156172
# Begin custom: services
157173
# End custom: services
@@ -212,7 +228,7 @@ jobs:
212228
use-public-rspm: true
213229

214230
- id: set-matrix
215-
uses: ./.github/workflows/dep-matrix-suggests
231+
uses: ./.github/workflows/dep-suggests-matrix-read
216232

217233
check-suggests-matrix:
218234
runs-on: ubuntu-22.04
Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: "Action to commit changes to the repository"
2+
inputs:
3+
token:
4+
description: "GitHub token"
5+
required: true
26
outputs:
37
sha:
48
description: "SHA of generated commit"
@@ -7,23 +11,47 @@ outputs:
711
runs:
812
using: "composite"
913
steps:
10-
- name: Commit if changed
14+
- name: Commit if changed, create a PR if protected
1115
id: commit
16+
env:
17+
GITHUB_TOKEN: ${{ inputs.token }}
1218
run: |
1319
set -x
1420
if [ -n "$(git status --porcelain)" ]; then
1521
echo "Changed"
16-
git fetch
17-
if [ -n "${GITHUB_HEAD_REF}" ]; then
22+
protected=${{ github.ref_protected }}
23+
if [ "${protected}" = "true" ]; then
24+
current_branch=$(git branch --show-current)
25+
new_branch=gha-commit
26+
git checkout -b ${new_branch}
1827
git add .
19-
git stash save
20-
git switch ${GITHUB_HEAD_REF}
21-
git merge origin/${GITHUB_BASE_REF} --no-edit
22-
git stash pop
28+
git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
29+
# Force-push, used in only one place
30+
# Alternative: separate branch names for each usage
31+
git push -u origin HEAD -f
32+
33+
existing_pr=$(gh pr list --state open --base main --head ${new_branch} --json number --jq '.[] | .number')
34+
if [ -n "${existing_pr}" ]; then
35+
echo "Existing PR: ${existing_pr}"
36+
else
37+
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}"
38+
fi
39+
40+
gh workflow run rcc -f ref=$(git rev-parse HEAD)
41+
else
42+
git fetch
43+
if [ -n "${GITHUB_HEAD_REF}" ]; then
44+
git add .
45+
git stash save
46+
git switch ${GITHUB_HEAD_REF}
47+
git merge origin/${GITHUB_BASE_REF} --no-edit
48+
git stash pop
49+
fi
50+
git add .
51+
git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
52+
git push -u origin HEAD
2353
fi
24-
git add .
25-
git commit -m "chore: Auto-update from GitHub Actions"$'\n'$'\n'"Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
26-
git push -u origin HEAD
27-
echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
2854
fi
55+
# Unconditionally set the output because it could come from a manually triggered run
56+
echo sha=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
2957
shell: bash

.github/workflows/dep-matrix-suggests/action.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Actions to read a matrix with all suggested packages, computed with the dep-suggests-matrix action"
2+
outputs:
3+
matrix:
4+
description: "Generated matrix"
5+
value: ${{ steps.set-matrix.outputs.matrix }}
6+
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Install json2yaml
11+
run: |
12+
sudo npm install -g json2yaml
13+
shell: bash
14+
15+
- id: set-matrix
16+
run: |
17+
# Empty contents if no suggested packages
18+
matrix=$(cat .github/dep-suggests-matrix.json || true)
19+
if [ -n "$matrix" ]; then
20+
echo $matrix | jq .
21+
echo $matrix | json2yaml
22+
fi
23+
echo "matrix=$matrix" | tee -a $GITHUB_OUTPUT
24+
shell: bash
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# FIXME: Dynamic lookup by parsing https://svn.r-project.org/R/tags/
2+
get_deps <- function() {
3+
# Determine package dependencies
4+
if (!requireNamespace("desc", quietly = TRUE)) {
5+
install.packages("desc")
6+
}
7+
8+
deps_df <- desc::desc_get_deps()
9+
deps_df_optional <- deps_df$package[deps_df$type %in% c("Suggests", "Enhances")]
10+
deps_df_hard <- deps_df$package[deps_df$type %in% c("Depends", "Imports", "LinkingTo")]
11+
deps_df_base <- unlist(tools::standard_package_names(), use.names = FALSE)
12+
13+
packages <- sort(deps_df_optional)
14+
packages <- intersect(packages, rownames(available.packages()))
15+
16+
# Too big to fail, or can't be avoided:
17+
off_limits <- c("testthat", "rmarkdown", "rcmdcheck", deps_df_hard, deps_df_base)
18+
off_limits_dep <- unlist(tools::package_dependencies(off_limits, recursive = TRUE, which = "strong"))
19+
setdiff(packages, c(off_limits, off_limits_dep))
20+
}
21+
22+
if (Sys.getenv("GITHUB_BASE_REF") != "") {
23+
print(Sys.getenv("GITHUB_BASE_REF"))
24+
has_diff <- (system("git diff ${{ github.event.pull_request.base.sha }}... | egrep '^[+][^+]' | grep -q ::") == 0)
25+
if (has_diff) {
26+
system("git diff ${{ github.event.pull_request.base.sha }}... | egrep '^[+][^+]' | grep -q ::")
27+
packages <- get_deps()
28+
} else {
29+
writeLines("No changes using :: found, not checking without suggested packages")
30+
packages <- character()
31+
}
32+
} else {
33+
packages <- get_deps()
34+
}
35+
36+
if (length(packages) > 0) {
37+
json <- paste0(
38+
'{"package":[',
39+
paste0('"', packages, '"', collapse = ","),
40+
']}'
41+
)
42+
} else {
43+
json <- character()
44+
}
45+
46+
writeLines(json, ".github/dep-suggests-matrix.json")
47+
writeLines(json)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: "Actions to compute a matrix with all suggested packages"
2+
outputs:
3+
matrix:
4+
description: "Generated matrix"
5+
value: ${{ steps.set-matrix.outputs.matrix }}
6+
7+
runs:
8+
using: "composite"
9+
steps:
10+
- id: set-matrix
11+
run: |
12+
Rscript ./.github/workflows/dep-suggests-matrix/action.R
13+
shell: bash

.github/workflows/revdep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767

6868
runs-on: ubuntu-22.04
6969

70-
name: ${{ matrix.package }}
70+
name: 'revdep: ${{ matrix.package }}'
7171

7272
# Begin custom: services
7373
# End custom: services

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ inputs:
44
sha:
55
description: 'SHA to update'
66
required: true
7-
state:
8-
description: 'state to update'
9-
required: true
107

118
runs:
129
using: "composite"
@@ -24,11 +21,19 @@ runs:
2421
-H "X-GitHub-Api-Version: 2022-11-28" \
2522
repos/${{ github.repository }}/actions/runs/${{ github.run_id }} | jq -r .html_url)
2623
27-
gh api \
28-
--method POST \
24+
# Check if a failing status has been set already
25+
status=$(gh api \
2926
-H "Accept: application/vnd.github+json" \
3027
-H "X-GitHub-Api-Version: 2022-11-28" \
31-
repos/${{ github.repository }}/statuses/${{ inputs.sha }} \
32-
-f "state=${{ job.status }}" -f "target_url=$html_url" -f "description=${{ github.workflow }} / ${{ github.job }}" -f "context=actions-sync"
28+
repos/${{ github.repository }}/commits/${{ inputs.sha }}/status | jq -r .state)
29+
30+
if [ "${status}" != "error" ] && [ "${status}" != "failure" ]; then
31+
gh api \
32+
--method POST \
33+
-H "Accept: application/vnd.github+json" \
34+
-H "X-GitHub-Api-Version: 2022-11-28" \
35+
repos/${{ github.repository }}/statuses/${{ inputs.sha }} \
36+
-f "state=${{ job.status }}" -f "target_url=$html_url" -f "description=${{ github.workflow }} / ${{ github.job }}" -f "context=actions-sync"
37+
fi
3338
fi
3439
shell: bash

0 commit comments

Comments
 (0)