-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jrdnbradford/tax-update-action
Add GHA to check taxonomy
- Loading branch information
Showing
8 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.