refresh-data #2349
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
name: refresh-data | |
on: | |
workflow_dispatch: | |
inputs: | |
tags: | |
description: | |
"run from cmdline" | |
schedule: | |
- cron: '30 1 * * THU' | |
push: | |
branches: | |
- master | |
- main | |
jobs: | |
refresh-data: | |
runs-on: ubuntu-latest | |
env: | |
R_CONFIG_ACTIVE: github | |
GITHUB_PAT: ${{ secrets.DJPRDASHDATA_PAT }} | |
PG_MASTER_USER: ${{ secrets.PG_MASTER_USER }} | |
PG_MASTER_PW: ${{ secrets.PG_MASTER_PW }} | |
PG_READ_OPEN_USER: ${{ secrets.PG_READ_OPEN_USER }} | |
PG_READ_OPEN_PW: ${{ secrets.PG_READ_OPEN_PW }} | |
IVI_REGIONS: ${{ vars.IVI_REGIONS }} | |
IVI_ANZSCO4: ${{ vars.IVI_ANZSCO4 }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Installing extra system dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y --fix-missing libcurl4-openssl-dev | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: 'renv' # The R version to download (if necessary) and use. | |
- uses: r-lib/actions/setup-renv@v2 | |
- uses: r-lib/actions/setup-pandoc@v2 | |
- name: Get Github action IP | |
id: ip | |
uses: haythem/[email protected] | |
- name: Set AWS environment variables | |
run: | | |
echo "AWS_DEFAULT_REGION=ap-southeast-2" >> $GITHUB_ENV | |
echo "AWS_SG_NAME=sg-0b7365fabbbc1c55b" >> $GITHUB_ENV | |
- name: Add Github Actions IP to Security group | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 5432 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }} | |
- name: Get data | |
run: Rscript -e 'source(here::here("data-raw", "refresh_data.R"), echo = TRUE)' | |
- name: Render README | |
run: Rscript -e 'rmarkdown::render(here::here("README.Rmd"))' | |
- name: Commit | |
run: | | |
git config --global user.name 'Henry McMillan' | |
git config --global user.email '[email protected]' | |
git add . | |
git commit -m 'refreshing data' || echo "No changes to commit" | |
git push --force origin main || echo "No changes to commit" | |
- name: Remove Github Actions IP from security group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 5432 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }} | |
if: always() |