From a8531aa4c8639fac05cf2f952635f41656c72b6b Mon Sep 17 00:00:00 2001 From: Kevin Cazelles Date: Tue, 20 Jun 2023 14:37:24 -0400 Subject: [PATCH] Add release workflow --- .github/workflows/R-CMD-build-release.yaml | 28 ++++++++++++ .github/workflows/R-CMD-build.yaml | 52 ---------------------- .github/workflows/R-CMD-check-all.yaml | 11 +---- .github/workflows/R-CMD-check.yaml | 5 +-- .gitignore | 1 + README.md | 6 ++- dockerfile | 11 ++--- install_pkg.R | 2 + makefile | 6 +++ testpkg01/DESCRIPTION | 3 ++ testpkg01/NAMESPACE | 2 +- testpkg01/R/hello.R | 5 --- testpkg01/R/hello_co2.R | 5 +++ testpkg01/man/{hello.Rd => hello_co2.Rd} | 8 ++-- 14 files changed, 61 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/R-CMD-build-release.yaml delete mode 100644 .github/workflows/R-CMD-build.yaml create mode 100644 .gitignore create mode 100644 install_pkg.R create mode 100644 makefile delete mode 100644 testpkg01/R/hello.R create mode 100644 testpkg01/R/hello_co2.R rename testpkg01/man/{hello.Rd => hello_co2.Rd} (52%) diff --git a/.github/workflows/R-CMD-build-release.yaml b/.github/workflows/R-CMD-build-release.yaml new file mode 100644 index 0000000..056a3ac --- /dev/null +++ b/.github/workflows/R-CMD-build-release.yaml @@ -0,0 +1,28 @@ +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release-event-release +on: + release: + types: [published] + +name: build-and-release + +jobs: + buildRPkgs: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v4 + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + - name: build archives + run: make rpkgs + - name: Create docker image + run: make docker + + buildDocker: + needs: buildRPkgs + runs-on: ubuntu-latest + steps: + - uses: docker/setup-buildx-action@v2 \ No newline at end of file diff --git a/.github/workflows/R-CMD-build.yaml b/.github/workflows/R-CMD-build.yaml deleted file mode 100644 index f7ac095..0000000 --- a/.github/workflows/R-CMD-build.yaml +++ /dev/null @@ -1,52 +0,0 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples -on: - workflow_call: - inputs: - pkg-path: - required: true - type: string - -name: R-CMD-check - -jobs: - R-CMD-check: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - R_KEEP_PKG_SOURCE: yes - steps: - - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v2 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: rcmdcheck, any::covr, any::goodpractice, any::lintr - working-directory: ${{ inputs.pkg-path }} - - - uses: r-lib/actions/check-r-package@v2 - with: - working-directory: ${{ inputs.pkg-path }} - - - name: Code coverage - run: covr::package_coverage() - shell: Rscript {0} - working-directory: ${{ inputs.pkg-path }} - - - name: Good practices - run: | - goodpractice::gp(checks = c( - "cyclocomp", - "no_import_package_as_a_whole", - "no_export_pattern" - )) - shell: Rscript {0} - working-directory: ${{ inputs.pkg-path }} - - - name: Lint - run: | - library(lintr) - lint_package(linters = with_defaults(object_name_linter("camelCase"), line_length_linter(160L), object_length_linter(length = 60L))) - shell: Rscript {0} - working-directory: ${{ inputs.pkg-path }} \ No newline at end of file diff --git a/.github/workflows/R-CMD-check-all.yaml b/.github/workflows/R-CMD-check-all.yaml index c6003d7..5fca463 100644 --- a/.github/workflows/R-CMD-check-all.yaml +++ b/.github/workflows/R-CMD-check-all.yaml @@ -1,4 +1,3 @@ -# see https://github.com/dorny/paths-filter on: push: branches: [main, master] @@ -17,7 +16,7 @@ jobs: packages: ${{ steps.filter.outputs.changes }} steps: # For pull requests it's not necessary to checkout the code - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dorny/paths-filter@v2 id: filter with: @@ -26,7 +25,7 @@ jobs: testpkg02: 'testpkg02/**' # JOB to build and test each of modified packages - buildPackages: + checkPackages: needs: changes # https://github.com/dorny/paths-filter/issues/66 if: ${{ needs.changes.outputs.packages != '[]' && needs.changes.outputs.packages != '' }} @@ -39,9 +38,3 @@ jobs: secrets: inherit with: pkg-path: ${{ matrix.package }} - - buildDocker: - runs-on: ubuntu-latest - needs: buildPackages - steps: - - uses: docker/setup-buildx-action@v2 diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 5f6be0a..3c7744f 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -15,7 +15,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true @@ -50,6 +50,3 @@ jobs: lint_package(linters = with_defaults(object_name_linter("camelCase"), line_length_linter(160L), object_length_linter(length = 60L))) shell: Rscript {0} working-directory: ${{ inputs.pkg-path }} - - - name: Build archive - run: R CMD build ${{ inputs.pkg-path }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c32b546 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.tar.gz \ No newline at end of file diff --git a/README.md b/README.md index be2b3f3..8dc7541 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # monoRepoR -Test repo to apply the same worklows on several packages in a mono repo. + +Demo repo to apply the same worklows on several packages in a mono repo. ## Generating test packages ```R # create testpkg01 -usethis::create_package("testpkg01") # NB: this prompts a message that requires an answer +## NB: the command line below prompts a message that requires an answer +usethis::create_package("testpkg01") usethis::use_mit_license() devtools::load_all() devtools::document() diff --git a/dockerfile b/dockerfile index 43d3cf0..44817e6 100644 --- a/dockerfile +++ b/dockerfile @@ -2,10 +2,7 @@ FROM rocker/r-ubuntu:22.04 RUN apt-get update \ && apt-get dist-upgrade -y \ - && apt-get install -y \ - default-jdk git apt-transport-https gpg-agent openssh-server \ - unixodbc unixodbc-dev libaio1 libaio-dev curl netbase \ - r-cran-anytime r-cran-cli r-cran-data.table r-cran-dbi r-cran-dplyr \ - r-cran-fontawesome - && apt-get autoremove -y \ - && apt-get autoclean -y \ No newline at end of file + && apt-get install -y r-cran-anytime + +COPY *.tar.gz install_pkg.R ./ +RUN Rscript install_pkg.R diff --git a/install_pkg.R b/install_pkg.R new file mode 100644 index 0000000..d345b1d --- /dev/null +++ b/install_pkg.R @@ -0,0 +1,2 @@ +pkg <- list.files(path = ".", pattern = "^test*\\.tar\\.gz") +lapply(pkg, install.packages, repos = NULL, type = "source") \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..a0875cb --- /dev/null +++ b/makefile @@ -0,0 +1,6 @@ +rpkgs: + R CMD build testpkg01 + R CMD build testpkg02 + +docker: + docker build -t ex_custom_docker . \ No newline at end of file diff --git a/testpkg01/DESCRIPTION b/testpkg01/DESCRIPTION index 6bf7a30..97b997c 100644 --- a/testpkg01/DESCRIPTION +++ b/testpkg01/DESCRIPTION @@ -9,3 +9,6 @@ License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 +Imports: + datasets, + utils diff --git a/testpkg01/NAMESPACE b/testpkg01/NAMESPACE index 01843dc..0088f7f 100644 --- a/testpkg01/NAMESPACE +++ b/testpkg01/NAMESPACE @@ -1,3 +1,3 @@ # Generated by roxygen2: do not edit by hand -export(hello) +export(hello_co2) diff --git a/testpkg01/R/hello.R b/testpkg01/R/hello.R deleted file mode 100644 index db5044e..0000000 --- a/testpkg01/R/hello.R +++ /dev/null @@ -1,5 +0,0 @@ -#' Hello world -#' @export -hello <- function() { - "Hello World 2!" -} \ No newline at end of file diff --git a/testpkg01/R/hello_co2.R b/testpkg01/R/hello_co2.R new file mode 100644 index 0000000..ab9c37d --- /dev/null +++ b/testpkg01/R/hello_co2.R @@ -0,0 +1,5 @@ +#' Hello world +#' @export +hello_co2 <- function() { + utils::head(datasets::CO2) +} \ No newline at end of file diff --git a/testpkg01/man/hello.Rd b/testpkg01/man/hello_co2.Rd similarity index 52% rename from testpkg01/man/hello.Rd rename to testpkg01/man/hello_co2.Rd index 3c9d2ff..788c08e 100644 --- a/testpkg01/man/hello.Rd +++ b/testpkg01/man/hello_co2.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/hello.R -\name{hello} -\alias{hello} +% Please edit documentation in R/hello_co2.R +\name{hello_co2} +\alias{hello_co2} \title{Hello world} \usage{ -hello() +hello_co2() } \description{ Hello world