From b15491ef59684c287445489bf26705bc44f77a67 Mon Sep 17 00:00:00 2001 From: Dan Snow Date: Mon, 3 Jul 2023 16:47:19 +0000 Subject: [PATCH] Add GitHub CI workflows More GitHub CI workflows --- .github/workflows/R-CMD-check.yaml | 68 ++++++++++++++++++++++++++ .github/workflows/lint.yaml | 31 ++++++++++++ .github/workflows/pkgdown.yaml | 65 ++++++++++++++++++++++++ .github/workflows/pre-commit.yaml | 30 ++++++++++++ .github/workflows/prepare-ptaxsim.yaml | 54 ++++++++++++++++++++ .github/workflows/test-coverage.yaml | 68 ++++++++++++++++++++++++++ 6 files changed, 316 insertions(+) create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 .github/workflows/pre-commit.yaml create mode 100644 .github/workflows/prepare-ptaxsim.yaml create mode 100644 .github/workflows/test-coverage.yaml diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..a36b3bf --- /dev/null +++ b/.github/workflows/R-CMD-check.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: + workflow_dispatch: + pull_request: + push: + branches: [main, master] + +name: R-CMD-check + +jobs: + prepare-ptaxsim: + uses: ./.github/workflows/prepare-ptaxsim.yaml + secrets: inherit + + R-CMD-check: + needs: prepare-ptaxsim + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + PTAXSIM_DB_PATH: ${{ github.workspace }}/ptaxsim.db + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - name: Restore database cache + uses: actions/cache/restore@v3.3.1 + with: + path: ptaxsim.db.bz2 + key: ${{ format('{0}-{1}', needs.prepare-ptaxsim.outputs.PTAXSIM_VERSION, hashFiles(format('{0}/DESCRIPTION', github.workspace ))) }} + fail-on-cache-miss: true + enableCrossOsArchive: true + + - name: Unpack database + run: | + bzip2 -d ${{ github.workspace }}/ptaxsim.db.bz2 + shell: bash + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..0a0a503 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,31 @@ +# 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: + pull_request: + push: + branches: [main, master] + +name: lint + +jobs: + lint: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr, local::. + needs: lint + + - name: Lint + run: lintr::lint_package() + shell: Rscript {0} + env: + LINTR_ERROR_ON_LINT: true diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..b07bba4 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,65 @@ +# 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: + workflow_dispatch: + pull_request: + push: + branches: [main, master] + release: + types: [published] + +name: pkgdown + +jobs: + prepare-ptaxsim: + uses: ./.github/workflows/prepare-ptaxsim.yaml + secrets: inherit + + pkgdown: + needs: prepare-ptaxsim + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + PTAXSIM_DB_PATH: ${{ github.workspace }}/ptaxsim.db + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Restore database cache + uses: actions/cache/restore@v3 + with: + path: ptaxsim.db.bz2 + key: ${{ format('{0}-{1}', needs.prepare-ptaxsim.outputs.PTAXSIM_VERSION, hashFiles(format('{0}/DESCRIPTION', github.workspace ))) }} + fail-on-cache-miss: true + + - name: Unpack database + run: | + bzip2 -d ${{ github.workspace }}/ptaxsim.db.bz2 + shell: bash + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..a11452f --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,30 @@ +on: + pull_request: + push: + branches: [main, master] + +name: pre-commit + +jobs: + pre-commit: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + RENV_CONFIG_CACHE_ENABLED: false + R_CACHE_ROOTPATH: ~/.cache/pre-commit + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr, any::styler, local::. + + - uses: actions/setup-python@v4 + with: + python-version: 3.x + + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/prepare-ptaxsim.yaml b/.github/workflows/prepare-ptaxsim.yaml new file mode 100644 index 0000000..c5c767e --- /dev/null +++ b/.github/workflows/prepare-ptaxsim.yaml @@ -0,0 +1,54 @@ +on: + workflow_call: + inputs: + PTAXSIM_DB_BASE_URL: + required: false + type: string + default: "s3://ccao-data-public-us-east-1/ptaxsim" + outputs: + PTAXSIM_VERSION: + description: "PTAXSIM database version" + value: ${{ jobs.download-db.outputs.output1 }} + +jobs: + download-db: + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + outputs: + output1: ${{ steps.version_db.outputs.PTAXSIM_VERSION }} + + steps: + - uses: actions/checkout@v3 + + - id: version_db + name: Get database version + run: | + echo "PTAXSIM_VERSION=$(grep -Po "(?<=Wants_DB_Version: )[0-9]*\.[0-9]*\.[0-9]*" ${{ github.workspace }}/DESCRIPTION)" >> $GITHUB_ENV + echo "PTAXSIM_VERSION=$(grep -Po "(?<=Wants_DB_Version: )[0-9]*\.[0-9]*\.[0-9]*" ${{ github.workspace }}/DESCRIPTION)" >> $GITHUB_OUTPUT + + - id: check_db + name: Check database cache + uses: actions/cache/restore@v3 + with: + path: ptaxsim.db.bz2 + key: ${{ format('{0}-{1}', env.PTAXSIM_VERSION, hashFiles(format('{0}/DESCRIPTION', github.workspace ))) }} + lookup-only: true + + - id: fetch_db + name: Fetch database file + if: steps.check_db.outputs.cache-hit != 'true' + run: | + aws s3 cp ${{ inputs.PTAXSIM_DB_BASE_URL }}/ptaxsim-${{ env.PTAXSIM_VERSION }}.db.bz2 ${{ github.workspace }}/ptaxsim.db.bz2 + shell: bash + + - id: save_db + name: Save database cache + uses: actions/cache/save@v3 + if: steps.check_db.outputs.cache-hit != 'true' + with: + path: ptaxsim.db.bz2 + key: ${{ format('{0}-{1}', env.PTAXSIM_VERSION, hashFiles(format('{0}/DESCRIPTION', github.workspace ))) }} + enableCrossOsArchive: true diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..9bb2a02 --- /dev/null +++ b/.github/workflows/test-coverage.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: + workflow_dispatch: + pull_request: + push: + branches: [main, master] + +name: test-coverage + +jobs: + prepare-ptaxsim: + uses: ./.github/workflows/prepare-ptaxsim.yaml + secrets: inherit + + test-coverage: + needs: prepare-ptaxsim + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + PTAXSIM_DB_PATH: ${{ github.workspace }}/ptaxsim.db + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Restore database cache + uses: actions/cache/restore@v3 + with: + path: ptaxsim.db.bz2 + key: ${{ format('{0}-{1}', needs.prepare-ptaxsim.outputs.PTAXSIM_VERSION, hashFiles(format('{0}/DESCRIPTION', github.workspace ))) }} + fail-on-cache-miss: true + + - name: Unpack database + run: | + bzip2 -d ${{ github.workspace }}/ptaxsim.db.bz2 + shell: bash + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package