Skip to content

Commit

Permalink
Merge pull request #14 from jrdnbradford/tax-update-action
Browse files Browse the repository at this point in the history
Tax update action
  • Loading branch information
jrdnbradford authored Jul 28, 2024
2 parents e482fa8 + 21e6b31 commit 56236ef
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 140 deletions.
34 changes: 10 additions & 24 deletions .github/workflows/taxonomy-version-check.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
name: taxonomy-version-check

on:
schedule:
- cron: '0 0 * 8-11 1' # Midnight on Mondays from August through November

env:
ISSUE_TITLE: 'eBird taxonomy has updated'
ISSUE_BODY: |
This issue has been opened by the GitHub Action workflow `taxonomy-version-check`.
There is an update to the eBird taxonomy. The `rebird::tax` dataset and documentation needs to be updated.
There is an update to the eBird taxonomy. The `rebird::tax` dataset and documentation needs to be updated.
on:
workflow_run:
workflows: ["R-CMD-check"]
types:
- completed

jobs:
taxonomy-version-check-job:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
outputs:
check-failed: ${{ steps.check-taxonomy-version.outputs.failed }}
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: checkout-step
uses: actions/checkout@v4

- name: setup-r-step
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
r-version: 'release'

- name: setup-r-dependencies-step
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: local::.

- name: check-taxonomy-version-step
id: check-taxonomy-version
run: |
Rscript -e "testthat::test_file('tests/testthat/test-data.R', load_package = 'source', stop_on_failure = TRUE)" && echo "failed=false" >> "$GITHUB_OUTPUT" || echo "failed=true" >> "$GITHUB_OUTPUT"
check-and-create-issue-job:
needs: taxonomy-version-check-job
if: needs.taxonomy-version-check-job.outputs.check-failed == 'true'
Expand Down
3 changes: 2 additions & 1 deletion R/ebirdtaxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ebirdtaxonomy <- function(cat=NULL, locale=NULL, species = NULL, key = NULL, ...
}

tax <- ebird_GET(paste0(ebase(), 'ref/taxonomy/ebird'), args, key = key, ...)
attr(tax, "version") <- ebirdtaxonomyversion(latest_only = TRUE)
latest <- subset(ebirdtaxonomyversion(), latest == TRUE)$authorityVer
attr(tax, "version") <- latest
tax
}
29 changes: 9 additions & 20 deletions R/ebirdtaxonomyversion.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
#' eBird Taxonomy Version
#'
#' Returns a data.frame of available version numbers of
#' the eBird taxonomy or the latest version number of the
#' taxonomy.
#' Returns a data.frame of available version numbers of the eBird taxonomy
#'
#' @param key eBird API key. You can obtain one from https://ebird.org/api/keygen.
#' @param key optional eBird API key. You can obtain one from https://ebird.org/api/keygen.
#' We strongly recommend storing it in your \code{.Renviron} file as an
#' environment variable called \code{EBIRD_KEY} to avoid having to constantly
#' environment variable called \code{EBIRD_KEY} to avoid having to constantly
#' supply the key, and to avoid accidentally sharing it publicly.
#' @param latest_only Whether to return only the latest version number
#' @param ... Curl options passed on to \code{\link[httr]{GET}}
#'
#' @return If `latest_only = FALSE`, a data.frame containing the collected information:
#'
#' @return data.frame containing the collected information:
#' @return "authorityVer": Character of version.
#' @return "latest": Boolean indicating whether `authorityVer` is the latest taxonomy version
#' @return If `latest_only = TRUE`, a character of the latest `authorityVer`
#'
#'
#' @export
#'
#'
#' @examples \dontrun{
#' ebirdtaxonomyversion()
#' ebirdtaxonomyversion(latest_only = TRUE)
#' }
#' @author Jordan Bradford \email{[email protected]}
#' @references \url{http://ebird.org/}
ebirdtaxonomyversion <- function(key = NULL, latest_only = FALSE, ...) {
ebirdtaxonomyversion <- function(key = NULL, ...) {
args <- list(fmt = 'json')

# Allow not using a key for this function
if (is.null(key) && !nzchar(Sys.getenv("EBIRD_KEY"))) {
key <- ""
}

versions <- ebird_GET(paste0(ebase(), 'ref/taxonomy/versions'), args, key = key, ...)
versions$authorityVer <- sub("0+$", "", as.character(versions$authorityVer))

if (latest_only) {
return(subset(versions, latest == TRUE)$authorityVer)
}
versions
ebird_GET(paste0(ebase(), 'ref/taxonomy/versions'), args, key = key, ...)
}
Binary file modified data/tax.rda
Binary file not shown.
20 changes: 7 additions & 13 deletions man/ebirdtaxonomyversion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 2 additions & 37 deletions tests/fixtures/ebirdtaxonomyversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ http_interactions:
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-type: application/json;charset=utf-8
date: Fri, 12 Jul 2024 18:08:45 GMT
date: Sun, 28 Jul 2024 15:11:38 GMT
expires: '0'
pragma: no-cache
server: Apache
Expand All @@ -32,40 +32,5 @@ http_interactions:
encoding: ''
file: no
string: '[{"authorityVer":2023.0,"latest":true},{"authorityVer":2022.0,"latest":false},{"authorityVer":2021.01,"latest":false},{"authorityVer":2021.0,"latest":false},{"authorityVer":2019.03,"latest":false},{"authorityVer":2019.02,"latest":false},{"authorityVer":2019.01,"latest":false},{"authorityVer":2019.0,"latest":false},{"authorityVer":2018.02,"latest":false},{"authorityVer":2018.01,"latest":false},{"authorityVer":2018.0,"latest":false},{"authorityVer":2017.02,"latest":false},{"authorityVer":2017.01,"latest":false},{"authorityVer":2017.0,"latest":false},{"authorityVer":2016.0,"latest":false},{"authorityVer":2015.0,"latest":false},{"authorityVer":1.55,"latest":false},{"authorityVer":1.54,"latest":false},{"authorityVer":1.53,"latest":false},{"authorityVer":1.52,"latest":false},{"authorityVer":1.051,"latest":false},{"authorityVer":1.05,"latest":false},{"authorityVer":1.049,"latest":false},{"authorityVer":1.048,"latest":false},{"authorityVer":1.0,"latest":false},{"authorityVer":0.9,"latest":false}]'
recorded_at: 2024-07-12 18:08:46 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
- request:
method: get
uri: https://ebird.org/ws2.0/ref/taxonomy/versions?fmt=json
body:
encoding: ''
string: ''
headers:
Accept: application/json, text/xml, application/xml, */*
X-eBirdApiToken: <<<redacted>>>
response:
status:
status_code: 200
category: Success
reason: OK
message: 'Success: (200) OK'
headers:
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-type: application/json;charset=utf-8
date: Fri, 12 Jul 2024 18:08:45 GMT
expires: '0'
pragma: no-cache
server: Apache
strict-transport-security: max-age=31536000 ; includeSubDomains
vary: Origin,Accept-Encoding,Access-Control-Request-Method,Access-Control-Request-Headers
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
content-length: '157'
body:
encoding: ''
file: no
string: '[{"authorityVer":2023.0,"latest":true},{"authorityVer":2022.0,"latest":false},{"authorityVer":2021.01,"latest":false},{"authorityVer":2021.0,"latest":false},{"authorityVer":2019.03,"latest":false},{"authorityVer":2019.02,"latest":false},{"authorityVer":2019.01,"latest":false},{"authorityVer":2019.0,"latest":false},{"authorityVer":2018.02,"latest":false},{"authorityVer":2018.01,"latest":false},{"authorityVer":2018.0,"latest":false},{"authorityVer":2017.02,"latest":false},{"authorityVer":2017.01,"latest":false},{"authorityVer":2017.0,"latest":false},{"authorityVer":2016.0,"latest":false},{"authorityVer":2015.0,"latest":false},{"authorityVer":1.55,"latest":false},{"authorityVer":1.54,"latest":false},{"authorityVer":1.53,"latest":false},{"authorityVer":1.52,"latest":false},{"authorityVer":1.051,"latest":false},{"authorityVer":1.05,"latest":false},{"authorityVer":1.049,"latest":false},{"authorityVer":1.048,"latest":false},{"authorityVer":1.0,"latest":false},{"authorityVer":0.9,"latest":false}]'
recorded_at: 2024-07-12 18:08:46 GMT
recorded_at: 2024-07-28 15:11:39 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
8 changes: 3 additions & 5 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
test_that("tax dataset version is latest version", {
latest_version <- ebirdtaxonomyversion(latest_only = TRUE)
temp_env <- new.env()
data("tax", envir = temp_env)
dataset_tax <- temp_env$tax
dataset_tax_version <- attr(dataset_tax, "version")
latest_version <- subset(ebirdtaxonomyversion(), latest == TRUE)$authorityVer
tax <- rebird::tax
dataset_tax_version <- attr(tax, "version")
expect_equal(latest_version, dataset_tax_version)
})
36 changes: 0 additions & 36 deletions tests/testthat/test-ebirdnotable.R

This file was deleted.

2 changes: 1 addition & 1 deletion tests/testthat/test-ebirdtaxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ vcr::use_cassette("ebirdtaxonomy", {
})

test_that("ebirdtaxonomy sets version attribute", {
latest_version <- ebirdtaxonomyversion(latest_only = TRUE)
latest_version <- subset(ebirdtaxonomyversion(), latest == TRUE)$authorityVer
version_value <- attr(ebirdtaxonomy(), "version")
expect_equal(latest_version, version_value)
})
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-ebirdtaxonomyversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ vcr::use_cassette("ebirdtaxonomyversion", {
expect_true(inherits(versions, "data.frame"))
expect_true(inherits(versions, "tbl_df"))
expect_equal(ncol(versions), 2)

latest_version <- ebirdtaxonomyversion(latest_only = TRUE)
expect_true(inherits(latest_version, "character"))
expect_true(all(c("authorityVer", "latest") %in% names(versions)))
})
})

0 comments on commit 56236ef

Please sign in to comment.