Skip to content

targets

targets #4196

Workflow file for this run

# MIT License
# Copyright (c) 2021 Eli Lilly and Company
# Author: William Michael Landau (will.landau at gmail)
# Edited by Adam Wilson (adamw at buffalo)
# Written with help from public domain (CC0 1.0 Universal) workflow files by Jim Hester:
# * https://github.com/r-lib/actions/blob/master/examples/check-full.yaml
# * https://github.com/r-lib/actions/blob/master/examples/blogdown.yaml
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
on:
push:
branches:
- main
- master
- dev-jiyeon
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
schedule:
# - cron: '1 0 * * 0' # runs every Sunday at 00:01
- cron: '0 0 * * *' # runs every day at midnight
# - cron: '0 */6 * * *' # run every 6th hour
name: targets
jobs:
targets:
runs-on: ubuntu-24.04 #ubuntu-22.04
container: adamwilsonlab/emma:latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: ~/.local/share/renv
ACTIONS_RUNNER_DEBUG: true
PYTHONPATH: /opt/conda/envs/r-reticulate/bin/python
RETICULATE_PYTHON: /opt/conda/envs/r-reticulate/bin/python
# GARGLE_AUTH_FILE: secrets/ee-wilsonlab-emma-ef416058504a.json
GOOGLE_APPLICATION_CREDENTIALS: secrets/ee-wilsonlab-emma-ef416058504a.json
steps:
- uses: actions/checkout@v2
with:
ref: main
lfs: true
- name: Whitelist directory
run: git config --global --add safe.directory /__w/emma_envdata/emma_envdata
- name: Checkout LFS objects
run: git lfs checkout
continue-on-error: true
# - name: List files in scratch_code
# run: ls -lh scratch_code/
# - name: Setup Python
# uses: actions/setup-python@v2
# with:
# python-version: '3.x'
# - name: Install Python Dependencies
# run: |
# pip install earthengine-api
# pip install -r requirements.txt # If you have other dependencies listed in a requirements file
# - name: Verify Python Installation
# run: |
# python -m pip show earthengine-api
# python -c "import ee; print(ee.__version__)"
# # - name: Install Linux system dependencies
# # if: runner.os == 'Linux'
# # run: |
# # sudo apt-get update
- name: Install Google Cloud SDK in container
run: |
apt-get update
apt-get install -y curl apt-transport-https ca-certificates gnupg
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" \
| tee /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
apt-get update
apt-get install -y google-cloud-cli=492.0.0-0
- name: DECRYPT rgee SECRETS
run: ./.github/decrypt_secret.sh
env:
RGEE_SECRET: ${{ secrets.RGEE_SECRET }}
continue-on-error: true
# - name: List files in secrets
# run: ls -lh secrets/
# - name: Check git settings
# run:
# git config --get http.postBuffer
# continue-on-error: true
# - name: Display Service Account JSON
# run: |
# echo "=== Service Account JSON ==="
# cat secrets/ee-wilsonlab-emma-ef416058504a.json
# echo "============================"
- name: Install Earth Engine API 1.5.4 in r-reticulate env
run: |
/opt/conda/envs/r-reticulate/bin/pip install --upgrade earthengine-api==0.1.370 #0.1.381
# conda install -n r-reticulate -y -c conda-forge earthengine-api=1.5.4
- name: Verify EE API version
run: |
/opt/conda/envs/r-reticulate/bin/pip show earthengine-api
- name: Install R Package Dependencies
run: |-
Rscript -e "questionr::qscan(list.files(pattern='*.R',recursive=T), load = TRUE, detail = TRUE)" # this scans all scripts and installs any needed packages
# - name: Upgrade rgee to latest from GitHub
# run: |
# Rscript -e "if (!requireNamespace('devtools', quietly = TRUE)) install.packages('devtools')"
# Rscript -e 'devtools::install_github("r-spatial/rgee", ref="v.1.1.5")'
# - name: Install rgee v1.1.5 from CRAN Archive
# run: |
# Rscript -e 'if (!requireNamespace("remotes", quietly=TRUE)) install.packages("remotes", repos="https://cloud.r-project.org")'
# Rscript -e 'remotes::install_version("rgee", version="1.1.5", repos="https://cloud.r-project.org")'
- name: Install rgee from bmaitner/rgee
run: Rscript -e 'devtools::install_github(repo = "bmaitner/rgee", ref = "noninteractive_auth")'
- name: Parse _targets.R
run: Rscript -e "parse('_targets.R')"
- name: Cache packages
uses: actions/cache@v3
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
restore-keys: ${{ runner.os }}-renv-
- name: Authenticate to GCP
run: |
# write the JSON secret to disk
# activate the service account (no --scopes flag)
gcloud auth activate-service-account \
--key-file="secrets/ee-wilsonlab-emma-ef416058504a.json" \
--project=ee-wilsonlab-emma \
--quiet
- name: Add r-reticulate env to PATH
run: echo "/opt/conda/envs/r-reticulate/bin" >> $GITHUB_PATH
# - name: Authenticate Earth Engine
# run: earthengine authenticate \
# --service_account \
# --quiet \
# #--key_file=${{ runner.temp }}/gee-key.json
# - name: Authenticate to GCP (ADC with scopes)
# run: |
# gcloud auth application-default login \
# --project=ee-wilsonlab-emma \
# --scopes=https://www.googleapis.com/auth/cloud-platform \
# --quiet
# - name: Restore packages
# shell: Rscript {0}
# run: |
# if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
# renv::restore()
- name: Check if previous runs exists
id: runs-exist
run: git ls-remote --exit-code --heads origin targets-runs
continue-on-error: true
- name: Checkout previous run
if: steps.runs-exist.outcome == 'success'
uses: actions/checkout@v2
with:
ref: targets-runs
fetch-depth: 1
path: .targets-runs
lfs: 'true' #attempting to fix issue with target-committed lfs files not being treated as lfs
- name: Restore output files from the previous run
if: steps.runs-exist.outcome == 'success'
run: |
for (dest in scan(".targets-runs/.targets-files", what = character())) {
source <- file.path(".targets-runs", dest)
if (!file.exists(dirname(dest))) dir.create(dirname(dest), recursive = TRUE)
if (file.exists(source)) file.rename(source, dest)
}
shell: Rscript {0}
# - name: Find credential JSON
# run: |
# echo "Searching for ee-wilsonlab-emma-ef416058504a.json ..."
# find / -name 'ee-wilsonlab-emma-ef416058504a.json' 2>/dev/null || true
# - name: Run targets pipeline
# run: |
# Sys.setenv(HOME="/home/rstudio")
# cmdstanr::set_cmdstan_path("/home/rstudio/.cmdstanr/cmdstan-2.28.1")
# cmdstanr::check_cmdstan_toolchain()
# #cmdstanr::install_cmdstan()
# targets::tar_make()
# shell: Rscript {0}
# - name: Run targets pt 1
# run: |
# Sys.setenv(HOME="/home/rstudio")
# cmdstanr::set_cmdstan_path("/home/rstudio/.cmdstanr/cmdstan-2.28.1")
# cmdstanr::check_cmdstan_toolchain()
# #cmdstanr::install_cmdstan()
# shell: Rscript {0}
- name: Verify credentials
run: |
./.github/decrypt_secret.sh
# ls ~/.config/earthengine
# /usr/bin/earthengine -h
# echo " main dir"
# ls
# echo "scratch dir"
# ls scratch_code
# echo "secrets dir"
# ls secrets
env:
RGEE_SECRET: ${{ secrets.RGEE_SECRET }}
GD_SECRET: ${{ secrets.GD_SECRET }}
continue-on-error: true
# - name: Install custom rgee
# run: |
# # added below on april 9 from https://github.com/r-spatial/rgee/issues/353#issuecomment-1983765552
# library(reticulate)
# py_config() # see the name of your conda (python) environment, in my case "r-reticulate"
# reticulate::py_install('earthengine-api==0.1.370', envname='r-reticulate')
# # Check the installation of "earthengine-api" with
# py_list_packages()
# pyl <- py_list_packages()
# pyl[pyl$package == "earthengine-api", ]
# # check python version with
# py_run_string("import sys; print(sys.version)")
# devtools::install_github(repo = "bmaitner/rgee", ref = "noninteractive_auth")
# - name: Install custom rgee
# run: |
# Rscript -e "library(reticulate)"
# Rscript -e "reticulate::py_install('earthengine-api==0.1.370', envname='r-reticulate')"
# Rscript -e "pyl <- py_list_packages(); print(pyl[pyl$package == 'earthengine-api', ])"
# Rscript -e "reticulate::py_run_string('import sys; print(sys.version)')"
# Rscript -e "devtools::install_github(repo = 'bmaitner/rgee', ref = 'noninteractive_auth')"
# shell: Rscript {0}
# - name: Print environment
# run: env
# - name: Print R session info
# run: Rscript -e 'sessionInfo()'
# - name: “Set up gcloud CLI”
# uses: google-github-actions/setup-gcloud@v1
# with:
# project_id: ${{ secrets.GCP_PROJECT }}
# service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Run targets pt 2
run: |
#reticulate::use_python('/usr/bin/python3')
#rgee::ee_set_pyenv('/usr/bin/python3','r-reticulate', confirm = F)
#targets::tar_destroy(destroy = "all",ask = FALSE) #uncomment to reset
targets::tar_make()
shell: Rscript {0}
- name: Identify files that the targets pipeline produced
run: git ls-files -mo --exclude=renv > .targets-files
- name: Create the runs branch if it does not already exist
if: steps.runs-exist.outcome != 'success'
run: git checkout --orphan targets-runs
- name: Put the worktree in the runs branch if the latter already exists
if: steps.runs-exist.outcome == 'success'
run: |
rm -r .git
mv .targets-runs/.git .
rm -r .targets-runs
- name: update md
run: |
webshot::install_phantomjs()
knitr::knit("README.Rmd")
shell: Rscript {0}
- name: Upload latest run
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
rm -r .gitignore .github/workflows
git lfs track _targets/objects/* #use git LFS to track the targets output (larger files)
git lfs track data/raw_data/*
git lfs track data/* #use git LFS to track the data output (larger files)
git lfs track "raw_data/**" #use git LFS to track raw_data output (larger files)
git lfs track "data/**"
git lfs track _targets/metadata/* #track metadata
git lfs track *.tif
git add .gitattributes
git add --all -- ':!renv' ':!*json'
for file in $(git ls-files ':!*.json' -mo --exclude=renv)
do
git add -f $file
done
git commit -am "Run pipeline"
git push origin targets-runs
# Move the loop below up two lines (after git add) to commit large files.
- name: Prepare failure artifact
if: failure()
run: rm -rf .git .github .targets-files .targets-runs
- name: Post failure artifact
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: .