Skip to content

Ingest daily temperatures #33

Ingest daily temperatures

Ingest daily temperatures #33

Workflow file for this run

# workflow to update daily ocean temps
on:
# check at 7am AEST every day of the month
schedule:
- cron: '0 21 * * *'
workflow_dispatch:
inputs:
overwrite:
description: "If true, overwrite existing observations. Default to false (add new obs only)."
type: boolean
default: false
name: Ingest daily 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.DAILY_IS_STALE=TRUE if new obs are available
- name: Check if update is required
id: check-update
run: Rscript R/check-daily.r
# analyses sets env.DAILY_UPDATED=TRUE and end.DAILY_UPDATE_TIME=...
# when they successfully run
# (R puts out uppercase strings for env vars, not actual bools)
- name: Run the daily analysis (scheduled update)
if: github.event_name == 'schedule' && (env.DAILY_IS_STALE == 'TRUE')
run: Rscript R/ingest-daily.r --overwrite=true
- name: Run the daily analysis (manual)
if: github.event_name == 'workflow_dispatch' || inputs.overwrite
run: Rscript R/ingest-daily.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/daily/*
git add data/last-daily-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.DAILY_UPDATED == 'TRUE'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v$(date +'%Y-%m-%d %H:%M:%S')" \
--repo="$GITHUB_REPOSITORY" \
--title="Daily and 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.DAILY_RUN_END }}",
"outcome_emoji": "${{ (env.DAILY_IS_STALE == 'FALSE') && '⏰' || (env.DAILY_UPDATED == 'TRUE') && '✅' || '❓' }}",
"outcome_long": "${{ (env.DAILY_IS_STALE == 'FALSE') && 'Update skipped (no new obs)' || (env.DAILY_UPDATED == 'TRUE') && 'New daily 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: daily ingest"
}