Skip to content

Commit

Permalink
Start water updates [patch]
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyenni committed Sep 11, 2023
1 parent deda3f9 commit 3426226
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
48 changes: 25 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Install packages, update data, test, and archive
# Install packages, update data, test, and archive

name: CI

Expand All @@ -17,7 +17,7 @@ on:
jobs:
build:
if: contains(toJson(github.event.commits), '[skip ci]') == false

runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
Expand All @@ -26,64 +26,66 @@ jobs:
matrix:
config:
- {os: ubuntu-latest, r: '4.2.2', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 3

- uses: r-lib/actions/setup-r@v2

- name: Cache R packages
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-2-${{ hashFiles('.github/depends.Rds') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('.github/R-version') }}-2-
- name: Install system dependencies
run: sudo apt-get install libgit2-dev libcurl4-openssl-dev libudunits2-dev libgdal-dev libnetcdf-dev libgeos-dev libproj-dev

run: |
sudo apt remove libudunits2-dev libgdal-dev libgeos-dev libproj-dev
sudo apt-get install libgit2-dev libcurl4-openssl-dev libudunits2-dev libgdal-dev libnetcdf-dev libgeos-dev libproj-dev
- name: Install packages
run: Rscript install-packages.R
run: Rscript install-packages.R

- name: Update data
run: Rscript update-data.R

- name: Test
run: Rscript testthat.R

- name: Check for new files
id: check_files
run: |
if [[ -z "$(git status --porcelain)" ]] ; then
if [[ -z "$(git status --porcelain)" ]] ; then
echo "Git status is empty"
echo "diff=FALSE" >> $GITHUB_OUTPUT
else
else
echo "diff=TRUE" >> $GITHUB_OUTPUT
fi
- name: Bump version
id: version
env:
env:
LOG: ${{ github.event_name == 'pull_request' && '$(git log --no-merges --format=%B -n 1 HEAD^2)' || '$(git log --no-merges --format=%B -n 1 HEAD)' }}
CRON: ${{ github.event_name == 'schedule' && 'TRUE' || 'FALSE' }}
run: |
R -e "source('version_bump.R'); bump_version('${{ env.LOG }}', ${{ env.CRON }}, ${{ steps.check_files.outputs.diff }})"
if echo "$(git status --porcelain)" | grep -q version.txt ; then
if echo "$(git status --porcelain)" | grep -q version.txt ; then
echo "Version changed"
echo "new_ver=TRUE" >> $GITHUB_OUTPUT
else
else
echo "No version bump"
echo "new_ver=FALSE" >> $GITHUB_OUTPUT
fi
- name: Setup Tag
if: github.event_name != 'pull_request' && steps.version.outputs.new_ver == 'TRUE'
id: tagging
Expand All @@ -92,18 +94,18 @@ jobs:
echo "tag=$value" >> $GITHUB_OUTPUT
value="v${value}"
echo "release=$value" >> $GITHUB_OUTPUT
- name: Tag new version for release
if: github.event_name != 'pull_request' && steps.version.outputs.new_ver == 'TRUE'
env:
env:
JOB_TAGS: ${{ github.event_name == 'schedule' && '[skip ci] [cron]' || '[skip ci]' }}
uses: EndBug/add-and-commit@v9
with:
author_name: Weecology Deploy Bot
author_email: [email protected]
message: "Update data and trigger archive: GitHub Build ${{ github.run_number }} ${{ env.JOB_TAGS }}"
tag: ${{ steps.tagging.outputs.tag }}

- name: Create Release
if: github.event_name != 'pull_request' && steps.version.outputs.new_ver == 'TRUE'
id: create_release
Expand Down
13 changes: 11 additions & 2 deletions DataCleaningScripts/get_water_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ get_eden_data <- function() {

wader::download_eden_depths()

covariate_data <- read.table("../Water/eden_covariates.csv", header = TRUE, sep = ",")
new_data <- wader::get_eden_covariates()
new_data2 <- wader::get_eden_covariates(level="all")
new_data3 <- wader::get_eden_covariates(level="wcas")
Expand All @@ -18,18 +19,26 @@ all_data <- dplyr::bind_rows(new_data,new_data2,new_data3) %>%
dplyr::select(-geometry) %>%
tidyr::pivot_wider(names_from="variable", values_from="value") %>%
dplyr::arrange("year", "region")
new_covariates <- all_data %>%
merge(dplyr::filter(covariate_data, !date %in% all_data$year)) %>%
dplyr::arrange("year", "region")

depth_data <- wader::get_eden_depths() %>%
depth_data <- read.table("../Water/eden_depth.csv", header = TRUE, sep = ",") %>%
dplyr::mutate(date=as.Date(date))
new_depths <- wader::get_eden_depths() %>%
dplyr::bind_rows(wader::get_eden_depths(level="all")) %>%
dplyr::bind_rows(wader::get_eden_depths(level="wcas")) %>%
dplyr::mutate(date=as.Date(date))
new_depths <- new_depths %>%
merge(dplyr::filter(depth_data, !date %in% new_depths$date)) %>%
dplyr::arrange("date", "region")

file.remove(dir(path=file.path(get_default_data_path(), 'EvergladesWadingBird/Water'), pattern="_.*_depth.nc"))

return(list(new_covariates=new_covariates, new_depths=new_depths))
}

#' Appends new water data
#' Writes new water data
#'
#'

Expand Down
2 changes: 1 addition & 1 deletion install-packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if ("pacman" %in% rownames(installed.packages()) == FALSE) install.packages("pac

# Install packages required for analysis

pacman::p_load(git2r, httr, semver, testthat, yaml,
pacman::p_load(git2r, httr, semver, sf, testthat, yaml,
dplyr, lubridate, remotes)

remotes::install_github("weecology/wader")
2 changes: 1 addition & 1 deletion update-data.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
message("Updating weather station data")
source("DataCleaningScripts/get_new_weather.R"); append_weather()
# source("DataCleaningScripts/get_water_data.R"); update_water()
source("DataCleaningScripts/get_water_data.R"); update_water()

0 comments on commit 3426226

Please sign in to comment.