Skip to content

targets

targets #1405

Workflow file for this run

# classic
# MIT License
# Copyright (c) 2021 Eli Lilly and Company
# Author: William Michael Landau (will.landau at gmail)
# 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-adam
- 2025_website
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
schedule:
# - cron: '1 0 * * 0' #every sunday just after midnight
- cron: '0 0 * * *' #daily at midnight
name: targets
jobs:
targets:
runs-on: ubuntu-latest
container: adamwilsonlab/emma:latest
env:
GITHUB_PAT: ${{ secrets.GH_PAT_BSM }}
# RENV_PATHS_ROOT: ~/.local/share/renv
steps:
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
# - name: Maximize build space
# uses: easimon/maximize-build-space@master # https://github.com/easimon/maximize-build-space
# with:
# # root-reserve-mb: 512
# # swap-size-mb: 1024
# remove-dotnet: 'true'
# remove-android: 'true'
# remove-haskell: 'true'
- uses: actions/checkout@v4
with:
lfs: 'true'
fetch-depth: 0 # added
- name: Whitelist directory
run: git config --global --add safe.directory /__w/emma_report/emma_report
- name: Checkout LFS objects
run: git lfs checkout
continue-on-error: true
- name: Install R Package Dependencies
run: |-
Rscript -e "update.packages(ask = FALSE)"
Rscript -e "install.packages('geotargets', repos = c('https://ropensci.r-universe.dev', 'https://cran.r-project.org'))"
Rscript -e "questionr::qscan(list.files(pattern='*.R',recursive=T), load = TRUE, detail = TRUE)" # this scans all scripts and installs any needed packages
#- name: Authorize Github for R
# run: |-
# - name: Cache packages
# uses: actions/cache@v1
# with:
# path: ${{ env.RENV_PATHS_ROOT }}
# key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
# restore-keys: ${{ runner.os }}-renv-
# - 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 ${{ steps.extract_branch.outputs.branch }}-runs
continue-on-error: true
- name: Checkout previous run
if: steps.runs-exist.outcome == 'success'
uses: actions/checkout@v2
with:
ref: ${{ steps.extract_branch.outputs.branch }}-runs
fetch-depth: 1
path: .${{ steps.extract_branch.outputs.branch }}-runs
## This restore output is temporarily uncommented while debugging runs
# - name: Restore output files from the previous run
# if: steps.runs-exist.outcome == 'success'
# run: |
# for (dest in scan(".${{ steps.extract_branch.outputs.branch }}-runs/.targets-files", what = character())) {
# source <- file.path(".${{ steps.extract_branch.outputs.branch }}-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: Run targets pipeline
# run: targets::tar_make(callr_function = NULL)
# shell: Rscript {0}
# - name: Identify files that the targets pipeline produced
# run: git ls-files -mo --exclude=renv > .targets-files
- 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: |
pwd
ls
./.github/decrypt_secret.sh
ls ~/.config/earthengine
earthengine -h
env:
RGEE_SECRET: ${{ secrets.RGEE_SECRET }}
continue-on-error: true
# - name: check on files
# run: |
# file data/raw_data/ndvi_modis/2021_12_19.tif
# file data/raw_data/ndvi_modis/2022_01_01.tif
# continue-on-error: true
- name: Run targets pt 2
run: |
targets::tar_destroy(destroy = "all",ask = FALSE)
targets::tar_make()
shell: Rscript {0}
- name: Create the runs branch if it does not already exist
if: steps.runs-exist.outcome != 'success'
run: git checkout --orphan ${{ steps.extract_branch.outputs.branch }}-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 .${{ steps.extract_branch.outputs.branch }}-runs/.git .
rm -r .${{ steps.extract_branch.outputs.branch }}-runs
- name: Upload latest run
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
rm -r .github/workflows # .gitignore
git lfs track _targets/objects/* #use git LFS to track the targets output (larger files)
# git lfs track "data/**"
git add --all -- ':!renv'
for file in $(git ls-files -mo --exclude=renv)
do
git add -f $file
done
git commit -am "Run pipeline"
git push origin ${{ steps.extract_branch.outputs.branch }}-runs
# - name: Upload latest run (commit & push to <branch>-runs)
# run: |
# git config --local user.name "GitHub Actions"
# git config --local user.email "[email protected]"
# rm -r .github/workflows
# if [ -f .gitattributes ]; then
# git add .gitattributes
# git add --renormalize .
# fi
# git add --all -- ':!renv'
# # for file in $(git ls-files -mo --exclude-standard -- ':!:renv/*'); do
# # git add -f "$file" || true
# # done
# for file in $(git ls-files -moi --exclude-standard -- _targets/ data/ ':!:renv/*'); do
# git add -f "$file" || true
# done
# git commit -m "Run pipeline" || echo "Nothing to commit"
# git push origin ${{ steps.extract_branch.outputs.branch }}-runs
- name: Prepare failure artifact
if: failure()
run: rm -rf .git .github .targets-files .${{ steps.extract_branch.outputs.branch }}-runs
- name: Post failure artifact
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: .