Building Standards Dashboard Deployment Workflow #1028
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: Building Standards Dashboard Deployment Workflow | |
# # Controls when the workflow will run | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
download_transform_write: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: | |
- 'pypy-3.7' | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- uses: actions/cache@v3 | |
id: cache-venv # name for referring later | |
with: | |
path: ./venv/ # what we cache: the virtualenv | |
# The cache key depends on requirements.txt | |
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }} | |
restore-keys: | | |
${{ runner.os }}-venv- | |
- run: | | |
python -m venv venv | |
ls | |
. ./venv/bin/activate | |
pip install -r requirements.txt | |
if: steps.cache-venv.outputs.cache-hit != 'true' | |
# downloads the package lists from the repositories and "updates" them to get information on the newest versions | |
- run: sudo apt-get update -y | |
# this is needed for installing r packages. | |
- run: sudo apt-get install libcurl4-openssl-dev | |
- run: ls -l | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: '4.0.2' | |
# Enable RStudio Package Manager to speed up package installation | |
use-public-rspm: true | |
- name: setup renv | |
uses: r-lib/actions/setup-renv@v2 | |
with: | |
cache-version: 1 | |
- name: install rsconnect | |
run: | | |
install.packages("remotes") | |
library(remotes) | |
remotes::install_version("rsconnect", "0.8.29") | |
shell: Rscript {0} | |
# creates config file for python script | |
- name: create config file for python script from github secrets | |
run: | | |
cat << EOF > config.ini | |
[DEFAULT] | |
api_key = ${{ secrets.SMART_SURVEY_API_KEY }} | |
api_secret_key = ${{ secrets.SMART_SURVEY_API_KEY_SECRET }} | |
survey_id = ${{ secrets.SURVEY_ID }} | |
EOF | |
# Note that you have to activate the virtualenv in every step | |
# because GitHub actions doesn't preserve the environment | |
- name: Activate python venv and run script to get survey data | |
run: | | |
. ./venv/bin/activate | |
python data_getter.py | |
- name: Authorize and deploy app | |
run: | | |
rsconnect::setAccountInfo('${{ secrets.RSCONNECT_USER }}', '${{ secrets.RSCONNECT_TOKEN }}', '${{ secrets.RSCONNECT_SECRET }}') | |
rsconnect::deployApp(appName='is-building-standards-ncs', logLevel="verbose") | |
shell: Rscript {0} | |
# messages for teams channel | |
- name: Notify dedicated teams channel success | |
if: success() | |
uses: jdcargile/ms-teams-notification@v1.3 | |
with: | |
github-token: ${{ github.token }} # this will use the runner's token. | |
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }} | |
notification-summary: ${{ github.repository }} has been ran successfully. | |
notification-color: 06ab00 | |
- name: Notify dedicated teams channel failure | |
if: failure() | |
uses: jdcargile/ms-teams-notification@v1.3 | |
with: | |
github-token: ${{ github.token }} # this will use the runner's token. | |
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }} | |
notification-summary: ${{ github.repository }} has workflow has failed. | |
notification-color: FF0000 |