diff --git a/.Rbuildignore b/.Rbuildignore index 6627b846..6c47ed1e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^r\.package\.example\.Rproj$ ^\.Rproj\.user$ ^LICENSE\.md$ +^.github$ diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 00000000..341ec75d --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,36 @@ +--- +name: Check ๐Ÿ›  + +on: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + branches: + - main + push: + branches: + - main + +# This reusable workflow from insightsengineering/r.pkg.template will run once a PR to main branch is created. +jobs: + job-setup: + name: Should we run R CMD check? + runs-on: ubuntu-latest + outputs: + check_out: ${{ steps.check.outputs.run_r_cmd_check }} + steps: + - name: To check or not to check? + id: check + run: | + echo "run_r_cmd_check=false" >> $GITHUB_OUTPUT + + r-cmd: + name: R CMD Check ๐Ÿงฌ + needs: job-setup + # Call a workflow from a given GitHub repository, from a given branch (or tag). + uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main + if: > + needs.job-setup.outputs.check_out == 'true' diff --git a/.github/workflows/simple.yaml b/.github/workflows/simple.yaml new file mode 100644 index 00000000..dcdd1d11 --- /dev/null +++ b/.github/workflows/simple.yaml @@ -0,0 +1,130 @@ +--- +name: Simple workflow + +on: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + branches: + - main + push: + branches: + - main + +env: + # additional flags for `R CMD CHECK` + EXTRA_CHECK_FLAGS: "--no-manual --no-vignettes" + # additional environmental vars for `R CMD CHECK` + # see manual here: https://rstudio.github.io/r-manuals/r-ints/Tools.html + _R_CHECK_TESTS_NLINES_: 0 + _R_CHECK_VIGNETTES_NLINES_: 0 + ENABLED_STEPS: | + checkout_repository +# setup_r +# setup_dependencies +# get_package_name +# build_r_package +# run_r_cmd_check +# upload_artifact + +jobs: + # First job. + hello-world-from-r: + name: Hello, world! + runs-on: ubuntu-latest + steps: + - name: Setup R ๐Ÿ”ง + uses: r-lib/actions/setup-r@v2 + + - name: Hello world! ๐Ÿ’ฌ + run: cat(paste0("Hello ", Sys.getenv("NAME"), "! ๐Ÿ‘‹")) + shell: Rscript {0} + env: + NAME: "Your name" + + # Second job - by default jobs will run in parallel, unless some dependencies + # are introduced between them. + build-and-check: + name: Build R package + runs-on: ubuntu-latest + steps: + - name: Checkout repo ๐Ÿ›Ž + # We're using an official GitHub Action. + uses: actions/checkout@v4.1.1 + if: contains(env.ENABLED_STEPS, 'checkout_repository') + with: + # Action inputs (arguments/parameters). + # In this case we clone the repository to the directory called the same + # as the repository name. + path: ${{ github.event.repository.name }} + + - name: Setup R ๐Ÿ”ง + if: contains(env.ENABLED_STEPS, 'setup_r') + # We're using a third-party GitHub Action. + uses: r-lib/actions/setup-r@v2 + + - name: Setup R dependencies ๐Ÿ”ง + # We're using a third-party GitHub Action. + uses: r-lib/actions/setup-r-dependencies@v2 + if: contains(env.ENABLED_STEPS, 'setup_dependencies') + with: + working-directory: ${{ github.event.repository.name }} + + # Get package name and version from DESCRIPTION so that we'll know + # what's the name of the tar.gz file with the built package. + # pkgbuild is set as an output which can be accessed by subsequent steps. + - name: Get package name ๐Ÿ“ฆ + if: contains(env.ENABLED_STEPS, 'get_package_name') + id: package-name + run: | + PKGBUILD="$(Rscript -e 'cat(sprintf("%s_%s.tar.gz",(dcf <- read.dcf("DESCRIPTION"))[,"Package"], dcf[,"Version"]))')" + echo "PKGBUILD = $PKGBUILD" + echo "pkgbuild=$PKGBUILD" >> $GITHUB_OUTPUT + shell: bash + working-directory: ${{ github.event.repository.name }} + + # Build a package stored in a directory called ${{ github.event.repository.name }} + # --no-manual --no-build-vignettes because this requires LaTeX. + - name: Build R package ๐Ÿ— + if: contains(env.ENABLED_STEPS, 'build_r_package') + run: | + R CMD build --no-manual --no-build-vignettes ${{ github.event.repository.name }} + ls -l + shell: bash + + # Check tar.gz package built in previous step. + # --no-manual --no-vignettes because this requires LaTeX. + - name: Run R CMD check ๐Ÿ + if: contains(env.ENABLED_STEPS, 'run_r_cmd_check') + run: | + env | grep -E '^_R' + echo "Let's run R CMD check..." + R CMD check ${EXTRA_CHECK_FLAGS} ${{ steps.package-name.outputs.pkgbuild }} + shell: bash + + - name: Get tar.gz file name + if: contains(env.ENABLED_STEPS, 'upload_artifact') + id: tar-gz + # Use our custom action. + uses: user-workshop-cicd/action-example@setup-action + with: + filename-beginning: ${{ github.event.repository.name }} + + # Upload tar.gz package as an artifact so it can be downloaded. + - name: Upload package build โคด + if: contains(env.ENABLED_STEPS, 'upload_artifact') + uses: actions/upload-artifact@v4 + with: + # Output of the custom action from the previous step + # are inputs of this action. + path: ${{ steps.tar-gz.outputs.full-filename }} + name: ${{ steps.tar-gz.outputs.full-filename }} + + call-reusable-workflow: + name: Reusable workflow โ™ป๏ธ + uses: user-workshop-cicd/r.pkg.template/.github/workflows/sample-reusable-workflow.yaml@sample-reusable-workflow + with: + name: Octocat diff --git a/tests/testthat/test-hello.R b/tests/testthat/test-hello.R index 0b2fa257..e3cfab2a 100644 --- a/tests/testthat/test-hello.R +++ b/tests/testthat/test-hello.R @@ -8,4 +8,4 @@ test_that("hello_cli() works", { test_that("fix me!!!", { expect_equal(1, 2) -}) \ No newline at end of file +})