Ingest monthly temperatures #429
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
# workflow to update monthly ocean temps | |
on: | |
# check at 9am AEST every day of the month | |
schedule: | |
- cron: '0 23 * * *' | |
workflow_dispatch: | |
inputs: | |
overwrite: | |
description: "If true, overwrite existing observations. Default to false (add new obs only)." | |
type: boolean | |
default: false | |
name: Ingest monthly temperatures | |
jobs: | |
ingest: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: renv | |
# - uses: r-lib/actions/setup-pandoc@v2 | |
- name: Install Linux system dependencies | |
run: | | |
sudo apt update | |
sudo apt-get install libcurl4-openssl-dev | |
sudo apt-get install libssl-dev | |
sudo apt-get install libharfbuzz-dev libfribidi-dev | |
sudo apt install libgdal-dev | |
sudo apt install nco | |
sudo apt install cdo | |
- name: Restore packages with renv | |
uses: r-lib/actions/setup-renv@v2 | |
# export cdo path so that r can find it | |
- name: Find cdo | |
run: | | |
echo "CDO_PATH=$(which cdo)" >> $GITHUB_ENV | |
- name: Report cdo location | |
run: echo CDO location is $(which cdo) | |
# sets env.MONTHLY_IS_STALE=TRUE if new obs are available | |
- name: Check if update is required | |
id: check-update | |
run: Rscript R/check-monthly.r | |
# analysis sets env.MONTHLY_UPDATED=TRUE and end.MONTHLY_UPDATE_TIME=... | |
# when it successfully runs | |
# (R puts out uppercase strings for env vars, not actual bools) | |
- name: Run the analysis (scheduled update) | |
if: github.event_name == 'schedule' && (env.MONTHLY_IS_STALE == 'TRUE') | |
run: Rscript R/ingest-monthly.r --overwrite=true | |
- name: Run the analysis (manual) | |
if: github.event_name == 'workflow_dispatch' && (env.MONTHLY_IS_STALE == 'TRUE') || inputs.overwrite | |
run: | | |
Rscript R/ingest-monthly.r \ | |
--overwrite=${{ inputs.overwrite }} | |
# commit and push | |
- name: Commit and push updated results | |
run: | | |
git config --local user.name actions-user | |
git config --local user.email "[email protected]" | |
git add data/monthly/* | |
git add data/monthly-all.csv | |
git add data/last-monthly-update.txt | |
git diff-index --quiet HEAD || git commit -m "Ingest new results via GitHub Actions" | |
git push | |
# make a release if there's new data | |
- name: Publish release | |
if: env.MONTHLY_UPDATED == 'TRUE' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh release create "v$(date +'%Y-%m-%d')" \ | |
--repo="$GITHUB_REPOSITORY" \ | |
--title="Monthly global ocean surface temperatures: v$(date +'%Y-%m-%d')" \ | |
--generate-notes | |
- name: Update Slack | |
uses: slackapi/[email protected] | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
with: | |
payload: | | |
{ | |
"event_type": "${{ github.event_name }}", | |
"run_end": "${{ env.MONTHLY_RUN_END }}", | |
"outcome_emoji": "${{ (env.MONTHLY_IS_STALE == 'FALSE') && '⏰' || (env.MONTHLY_UPDATED == 'TRUE') && '✅' || '❓' }}", | |
"outcome_long": "${{ (env.MONTHLY_IS_STALE == 'FALSE') && 'Update skipped (no new obs)' || (env.MONTHLY_UPDATED == 'TRUE') && 'New observations added!' || 'Workflow successfully executed, but the analysis script did not sign off properly. Something may not be right—this should be followed up.' }}", | |
"workflow_name": "Ocean data tracker: monthly ingest" | |
} |