Skip to content

Commit

Permalink
Add GitHub CI workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsnow committed Jul 4, 2023
1 parent 13df399 commit 4f2bb70
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.xls filter=lfs diff=lfs merge=lfs -text
*.xlsx filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.geojson filter=lfs diff=lfs merge=lfs -text
*.csv filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
DESCRIPTION text eol=lf
68 changes: 68 additions & 0 deletions .github/workflows/R-CMD-check.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:
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/[email protected]
with:
path: ptaxsim.db.bz2
key: ${{ format('{0}-{1}', needs.prepare-ptaxsim.outputs.PTAXSIM_VERSION, hashFiles('DESCRIPTION')) }}
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
31 changes: 31 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -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
65 changes: 65 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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('DESCRIPTION')) }}
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/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
30 changes: 30 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
54 changes: 54 additions & 0 deletions .github/workflows/prepare-ptaxsim.yaml
Original file line number Diff line number Diff line change
@@ -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('DESCRIPTION')) }}
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('DESCRIPTION')) }}
enableCrossOsArchive: true
68 changes: 68 additions & 0 deletions .github/workflows/test-coverage.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:
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('DESCRIPTION')) }}
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

0 comments on commit 4f2bb70

Please sign in to comment.