Update DB and deploy #568
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: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
push: | |
branches: | |
- main | |
- master | |
name: Update DB and deploy | |
jobs: | |
deploy-shiny: | |
runs-on: ubuntu-latest | |
env: | |
R_CONFIG_ACTIVE: github | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
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 }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Installing extra system dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libcurl4-openssl-dev libudunits2-dev libxml2-dev libglpk-dev | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: 'renv' | |
- uses: r-lib/actions/setup-renv@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: Update database | |
run: | | |
Rscript -e "source('data-raw/create_dash_data.R')" | |
- name: Generate charts | |
run: | | |
Rscript -e "source('data-raw/generate_static_content.R')" | |
- name: Deploy to shinyapps.io | |
run: | | |
Rscript -e "rsconnect::setAccountInfo(name = 'djpr-spp', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')" | |
Rscript -e "source('data-raw/manual_deploy.R')" | |
- 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() |