.github/workflows/workflow.yml #143
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
on: | |
push: | |
branches: main | |
paths: | |
- 'Dockerfile' | |
- '**.R' | |
- 'data-raw/**' | |
- 'inst/**' | |
schedule: | |
- cron: '00 00 * * *' | |
jobs: | |
import_data: | |
runs-on: ubuntu-latest | |
outputs: | |
new_data: ${{ steps.commit_results.outputs.new_data }} | |
permissions: | |
contents: write | |
steps: | |
- name: Set up R and enable P3M | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
use-public-rspm: true | |
- name: Install dependencies | |
run: | | |
Rscript -e 'install.packages(c( | |
"dplyr", | |
"googlesheets4", | |
"janitor", | |
"purrr", | |
"readr", | |
"stringr", | |
"tibble", | |
"tidyr", | |
"tidyselect", | |
"usethis" | |
))' | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Import data | |
run: Rscript -e 'source("data-raw/external-data.R")' | |
- name: Refresh data | |
run: Rscript -e 'source("data-raw/internal-data.R")' | |
- name: Commit results | |
id: commit_results | |
run: | | |
new_data=true | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions" | |
git add 'data-raw/data.csv' 'R/sysdata.rda' | |
git commit -m 'Data updated' || new_data=false | |
git push origin || echo "No changes to commit" | |
echo "new_data=$new_data" >> "$GITHUB_OUTPUT" | |
deploy: | |
needs: import_data | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check env | |
env: | |
NEW_DATA: ${{ needs.import_data.outputs.new_data }} | |
EVENT_NAME: ${{ github.event_name }} | |
run: | | |
echo "event_name=$EVENT_NAME" | |
echo "new_data=$NEW_DATA" | |
- name: DigitalOcean App Platform deployment | |
if: ${{ (needs.import_data.outputs.new_data == 'true' && github.event_name == 'schedule') || github.event_name == 'push' }} | |
uses: digitalocean/[email protected] | |
with: | |
app_name: climbwith | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} |