Skip to content

Commit 4b0b357

Browse files
authored
Reusable workflow to avoid code duplication (#13)
1 parent 159acfa commit 4b0b357

File tree

2 files changed

+98
-79
lines changed

2 files changed

+98
-79
lines changed

.github/workflows/roxygen-helloworld.yaml

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,8 @@ name: Run roxygen2 on R package bican.mccarroll.helloworld and commit changes
1111
permissions: read-all
1212

1313
jobs:
14-
document:
15-
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
16-
name: document
17-
runs-on: ubuntu-latest
18-
env:
19-
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
20-
permissions:
21-
contents: write
22-
steps:
23-
- uses: actions/checkout@v4
24-
25-
- uses: r-lib/actions/pr-fetch@v2
26-
with:
27-
repo-token: ${{ secrets.GITHUB_TOKEN }}
28-
29-
- uses: r-lib/actions/setup-r@v2
30-
with:
31-
use-public-rspm: true
32-
33-
- uses: r-lib/actions/setup-r-dependencies@v2
34-
with:
35-
working-directory: R/bican.mccarroll.helloworld
36-
extra-packages: any::roxygen2
37-
needs: pr-document
38-
39-
- name: Document
40-
run: |
41-
setwd("R/bican.mccarroll.helloworld")
42-
roxygen2::roxygenise()
43-
shell: Rscript {0}
44-
45-
- name: commit
46-
run: |
47-
git config --local user.name "$GITHUB_ACTOR"
48-
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
49-
cd R/bican.mccarroll.helloworld
50-
git add man/\* NAMESPACE
51-
git commit -m 'Document'
52-
53-
- uses: r-lib/actions/pr-push@v2
54-
with:
55-
repo-token: ${{ secrets.GITHUB_TOKEN }}
56-
57-
style:
58-
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }}
59-
name: style
60-
runs-on: ubuntu-latest
61-
env:
62-
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
63-
permissions:
64-
contents: write
65-
steps:
66-
- uses: actions/checkout@v4
67-
68-
- uses: r-lib/actions/pr-fetch@v2
69-
with:
70-
repo-token: ${{ secrets.GITHUB_TOKEN }}
71-
72-
- uses: r-lib/actions/setup-r@v2
73-
74-
- name: Install dependencies
75-
run: install.packages("styler")
76-
shell: Rscript {0}
77-
78-
- name: Style
79-
run: styler::style_pkg()
80-
shell: Rscript {0}
81-
82-
- name: commit
83-
run: |
84-
git config --local user.name "$GITHUB_ACTOR"
85-
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
86-
cd R/bican.mccarroll.helloworld
87-
git add \*.R
88-
git commit -m 'Style'
89-
90-
- uses: r-lib/actions/pr-push@v2
91-
with:
92-
repo-token: ${{ secrets.GITHUB_TOKEN }}
14+
call-roxygen-reusable:
15+
uses: ./.github/workflows/roxygen-reusable.yml
16+
with:
17+
package_name: bican.mccarroll.helloworld
18+
secrets: inherit
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Workflow derived from dplyr/.github/workflows/pr-commands.yaml
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
workflow_call:
5+
inputs:
6+
package_name:
7+
required: true
8+
type: string
9+
10+
name: Run roxygen2 on R package and commit changes
11+
12+
permissions: read-all
13+
14+
jobs:
15+
document:
16+
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
17+
name: document
18+
runs-on: ubuntu-latest
19+
env:
20+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
21+
permissions:
22+
contents: write
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: r-lib/actions/pr-fetch@v2
27+
with:
28+
repo-token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- uses: r-lib/actions/setup-r@v2
31+
with:
32+
use-public-rspm: true
33+
34+
- uses: r-lib/actions/setup-r-dependencies@v2
35+
with:
36+
working-directory: R/${{ inputs.package_name }}
37+
extra-packages: any::roxygen2
38+
needs: pr-document
39+
40+
- name: Document
41+
run: |
42+
setwd("R/${{ inputs.package_name }}")
43+
roxygen2::roxygenise()
44+
shell: Rscript {0}
45+
46+
- name: commit
47+
run: |
48+
git config --local user.name "$GITHUB_ACTOR"
49+
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
50+
cd R/${{ inputs.package_name }}
51+
git add man/\* NAMESPACE
52+
git commit -m 'Document'
53+
54+
- uses: r-lib/actions/pr-push@v2
55+
with:
56+
repo-token: ${{ secrets.GITHUB_TOKEN }}
57+
58+
style:
59+
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }}
60+
name: style
61+
runs-on: ubuntu-latest
62+
env:
63+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
64+
permissions:
65+
contents: write
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- uses: r-lib/actions/pr-fetch@v2
70+
with:
71+
repo-token: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- uses: r-lib/actions/setup-r@v2
74+
75+
- name: Install dependencies
76+
run: install.packages("styler")
77+
shell: Rscript {0}
78+
79+
- name: Style
80+
run: styler::style_pkg()
81+
shell: Rscript {0}
82+
83+
- name: commit
84+
run: |
85+
git config --local user.name "$GITHUB_ACTOR"
86+
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
87+
cd R/${{ inputs.package_name }}
88+
git add \*.R
89+
git commit -m 'Style'
90+
91+
- uses: r-lib/actions/pr-push@v2
92+
with:
93+
repo-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)