Skip to content
24 changes: 24 additions & 0 deletions examples/README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Package workflows:
- [`lint`](#lint-workflow) - Run `lintr::lint_package()` on an R package.
- [`pr-commands`](#commands-workflow) - Adds `/document` and `/style` commands for pull requests.
- [`pkgdown`](#build-pkgdown-site) - Build a [pkgdown] site for an R package and deploy it to [GitHub Pages].
- [`document`](#document-package) - Run `roxygen2::roxygenise()` on an R package.
- [`style`](#style-package) - Run `styler::style_pkg()` on an R package.

RMarkdown workflows:

Expand Down Expand Up @@ -164,6 +166,28 @@ The inclusion of [`workflow_dispatch`](https://docs.github.com/en/actions/learn-
print_yaml("pkgdown.yaml")
```

## Document package

`usethis::use_github_action("document")`

This example documents an R package whenever a file in the `R/` directory changes, then commits and pushes the changes
to the same branch.

```{r echo = FALSE, results = "asis"}
print_yaml("document.yaml")
```

## Style package

`usethis::use_github_action("document")`

This example styles the R code in a package, then commits and pushes the changes
to the same branch.

```{r echo = FALSE, results = "asis"}
print_yaml("style.yaml")
```

## Build bookdown site

`usethis::use_github_action("bookdown")`
Expand Down
111 changes: 111 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Package workflows:
- [`pkgdown`](#build-pkgdown-site) - Build a
[pkgdown](https://pkgdown.r-lib.org/) site for an R package and
deploy it to [GitHub Pages](https://pages.github.com/).
- [`document`](#document-package) - Run `roxygen2::roxygenise()` on an
R package.
- [`style`](#style-package) - Run `styler::style_pkg()` on an R
package.

RMarkdown workflows:

Expand Down Expand Up @@ -525,6 +529,113 @@ jobs:
Rscript -e 'pkgdown::build_site(preview = FALSE, install = FALSE)'
```

## Document package

`usethis::use_github_action("document")`

This example documents an R package whenever a file in the `R/`
directory changes, then commits and pushes the changes to the same
branch.

``` yaml
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["R/**"]
pull_request:
paths: ["R/**"]

name: Document

jobs:
document:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: Commit and push changes
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add man/\* NAMESPACE
git commit -m "Update documentation" || echo "No changes to commit"
git pull --ff-only || echo "No remote changes"
git push origin || echo "No changes to commit"
```

## Style package

`usethis::use_github_action("document")`

This example styles the R code in a package, then commits and pushes the
changes to the same branch.

``` yaml
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["R/**"]
pull_request:
paths: ["R/**"]

name: Style

jobs:
style:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::styler

- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: Commit and push changes
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add R/\*
git commit -m "Style code" || echo "No changes to commit"
git pull --ff-only || echo "No remote changes"
git push origin || echo "No changes to commit"
```

## Build bookdown site

`usethis::use_github_action("bookdown")`
Expand Down
44 changes: 44 additions & 0 deletions examples/document.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["R/**"]
pull_request:
paths: ["R/**"]

name: Document

jobs:
document:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2
needs: roxygen2

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: Commit and push changes
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add man/\* NAMESPACE
git commit -m "Update documentation" || echo "No changes to commit"
git pull --ff-only
git push origin
68 changes: 68 additions & 0 deletions examples/style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["**.[rR]", "**.[rR]md", "**.[rR]markdown", "**.[rR]nw"]
pull_request:
paths: ["**.[rR]", "**.[rR]md", "**.[rR]markdown", "**.[rR]nw"]

name: Style

jobs:
style:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::styler
needs: styler

- name: Enable styler cache
run: styler::cache_activate()
shell: Rscript {0}

- name: Determine cache location
id: styler-location
run: |
cat(
"##[set-output name=location;]",
styler::cache_info(format = "tabular")$location,
"\n",
sep = ""
)
shell: Rscript {0}

- name: Cache styler
uses: actions/cache@v2
with:
path: ${{ steps.styler-location.outputs.location }}
key: ${{ runner.os }}-styler-${{ github.sha }}
restore-keys: |
${{ runner.os }}-styler-
${{ runner.os }}-

- name: Style
run: styler::style_pkg(filetype = c(".R", ".Rmd", ".Rmarkdown", ".Rnw"))
shell: Rscript {0}

- name: Commit and push changes
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add R/\*
git commit -m "Style code" || echo "No changes to commit"
git pull --ff-only
git push origin