Skip to content

Commit

Permalink
Merge pull request #10 from jrdnbradford/tax-update-action
Browse files Browse the repository at this point in the history
Add GHA to check taxonomy
  • Loading branch information
jrdnbradford authored Jul 11, 2024
2 parents 69a907b + e02f688 commit 84dd1a6
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 3 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/taxonomy-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: taxonomy-check

on:
schedule:
- cron: '0 13 * * 1' # Weekly on Mondays at 9AM EST

env:
ISSUE_TITLE: 'eBird taxonomy different than expected'
ISSUE_BODY: |
This issue has been opened by the GitHub Action workflow `taxonomy-check`.
The `tax` dataset is different than data retrieved using `rebird::ebirdtaxonomy()`. Potential causes of this could include:
* an update to the eBird taxonomy
* issues with eBird's API
* different versions of R/packages resulting in data being loaded, retrieved, compared, and/or saved differently
Check if there has been an update to eBird's taxonomy data. If not, investigate the other potential causes.
jobs:
taxonomy-check-job:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
outputs:
result: ${{ steps.check-taxonomy.outputs.result }}
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-step
id: check-taxonomy
run: Rscript data-raw/tax_check.R

check-and-create-issue-job:
needs: taxonomy-check-job
if: needs.taxonomy-check-job.outputs.result == 'TRUE'
runs-on: ubuntu-latest
steps:
- name: check-issue-step
id: check-issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueTitle = process.env.ISSUE_TITLE;
const { owner, repo } = context.repo;
const issues = await github.rest.issues.listForRepo({
owner,
repo,
state: 'open',
});
const existingIssue = issues.data.find(issue => issue.title === issueTitle);
if (existingIssue) {
core.setOutput('exists', 'true');
} else {
core.setOutput('exists', 'false');
}
- name: create-issue-step
if: ${{ steps.check-issue.outputs.exists == 'false' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueTitle = process.env.ISSUE_TITLE;
const issueBody = process.env.ISSUE_BODY;
const { owner, repo } = context.repo;
await github.rest.issues.create({
owner,
repo,
title: issueTitle,
body: issueBody,
});
5 changes: 4 additions & 1 deletion R/ebirdtaxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@ ebirdtaxonomy <- function(cat=NULL, locale=NULL, species = NULL, key = NULL, ...
key <- ""
}

ebird_GET(paste0(ebase(), 'ref/taxonomy/ebird'), args, key = key, ...)
tax <- ebird_GET(paste0(ebase(), 'ref/taxonomy/ebird'), args, key = key, ...)
tax$comNameCodes <- sort_comma_separated(tax$comNameCodes)
tax$sciNameCodes <- sort_comma_separated(tax$sciNameCodes)
tax
}
12 changes: 12 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ ebird_GET <- function(url, args, key = NULL, ...){
}
}

sort_comma_separated <- function(x) {
sapply(strsplit(as.character(x), ","), function(x) {
x <- x[x != ""]
if (length(x) == 0) {
return(NA_character_)
} else if (length(x) == 1) {
return(x)
} else {
return(paste(sort(x), collapse = ","))
}
})
}
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ knitr::opts_chunk$set(
[![Codecov test coverage](https://codecov.io/gh/ropensci/rebird/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/rebird?branch=master)
[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/rebird)](https://github.com/r-hub/cranlogs.app)
[![cran version](https://www.r-pkg.org/badges/version/rebird)](https://cran.r-project.org/package=rebird/)
[![taxonomy-check](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml/badge.svg)](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml)
<!-- badges: end -->

`rebird` is a package to interface with the eBird webservices.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ coverage](https://codecov.io/gh/ropensci/rebird/branch/master/graph/badge.svg)](
downloads](https://cranlogs.r-pkg.org/badges/rebird)](https://github.com/r-hub/cranlogs.app)
[![cran
version](https://www.r-pkg.org/badges/version/rebird)](https://cran.r-project.org/package=rebird/)
[![taxonomy-check](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml/badge.svg)](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml)

<!-- badges: end -->

`rebird` is a package to interface with the eBird webservices.
Expand Down
4 changes: 2 additions & 2 deletions data-raw/tax.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# eBird taxonomy to look up species codes
#
# This creates the internal taxonomy data frame used by rebird, which
# is stored ind 'R/sysdata.rda'. We update the package in CRAN when
# This creates the taxonomy data frame used by rebird, which
# is stored in 'data/tax.rda'. We update the package in CRAN when
# the eBird taxonomy update is completed, but in the event you need
# to update the taxonomy yourself you can do so by running the code below.

Expand Down
21 changes: 21 additions & 0 deletions data-raw/tax_check.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env Rscript
compare_dataframes <- function(df1, df2) {
df1_sorted <- df1[do.call(order, df1),]
df2_sorted <- df2[do.call(order, df2),]
identical(df1_sorted, df2_sorted)
}

print("Loading current taxonomy...")
temp_env <- new.env()
data("tax", envir = temp_env)
old_tax <- temp_env$tax
paste("Current rebird taxonomy has", ncol(old_tax), "columns and", nrow(old_tax), "rows")

print("Retrieving taxonomy from eBird...")
new_tax <- rebird::ebirdtaxonomy()
paste("The latest taxonomy from eBird has", ncol(new_tax), "columns and", nrow(new_tax), "rows")

needs_update <- !(compare_dataframes(old_tax, new_tax))
print(paste("Needs update?:", needs_update))
if (needs_update) print("The next job to create an issue should run.")
cat(paste0("result=", needs_update), file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE)
Binary file modified data/tax.rda
Binary file not shown.

0 comments on commit 84dd1a6

Please sign in to comment.