-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (61 loc) · 2.42 KB
/
deploy-shiny.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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()