diff --git a/examples/README.Rmd b/examples/README.Rmd index 61616b57e..64eba9f53 100644 --- a/examples/README.Rmd +++ b/examples/README.Rmd @@ -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: @@ -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")` diff --git a/examples/README.md b/examples/README.md index dd0a1ed0d..2084e7df0 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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: @@ -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 "$GITHUB_ACTOR@users.noreply.github.com" + 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 "$GITHUB_ACTOR@users.noreply.github.com" + 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")` diff --git a/examples/document.yaml b/examples/document.yaml new file mode 100644 index 000000000..9a772c085 --- /dev/null +++ b/examples/document.yaml @@ -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 "$GITHUB_ACTOR@users.noreply.github.com" + git add man/\* NAMESPACE + git commit -m "Update documentation" || echo "No changes to commit" + git pull --ff-only + git push origin diff --git a/examples/style.yaml b/examples/style.yaml new file mode 100644 index 000000000..f0bb30cba --- /dev/null +++ b/examples/style.yaml @@ -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 "$GITHUB_ACTOR@users.noreply.github.com" + git add R/\* + git commit -m "Style code" || echo "No changes to commit" + git pull --ff-only + git push origin