FRED #89
This file contains hidden or 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
| # pulls FRED data and saves to repo | |
| # https://fred.stlouisfed.org/series/GDPDEF | |
| # required deflator for species value | |
| name: FRED | |
| on: | |
| schedule: | |
| # uses UTC/GMT time (+ 5 hrs) | |
| - cron: "0 0 20 * *" # Every Month (Day 20) at 0000 hrs = 0500 UTC. WPU0223 updates on 16th | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| # GITHUB_PAT: ${{ secrets.GH_RELEASE }} | |
| R_REMOTES_NO_ERRORS_FROM_WARNINGS: false | |
| steps: | |
| # Generate a short-lived token using GitHub App credentials | |
| - name: Generate GitHub App Token | |
| id: get_workflow_token | |
| uses: actions/create-github-app-token@v3.2.0 | |
| with: | |
| client-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - name: Checkout repo | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ steps.get_workflow_token.outputs.token }} | |
| persist-credentials: true | |
| - name: set up pandoc | |
| uses: r-lib/actions/setup-pandoc@v2 | |
| - name: Install command line packages | |
| run: | | |
| sudo apt update | |
| sudo apt-get install -y libcurl4-openssl-dev libgit2-dev unixodbc-dev build-essential | |
| shell: bash | |
| - name: Set up R | |
| uses: r-lib/actions/setup-r@v2 | |
| with: | |
| r-version: '4.4.0' | |
| - name: Install packages | |
| run: | | |
| install.packages(c("pak","fredr", "tidyr", "here","dplyr","lubridate","rmarkdown","ggplot2")) | |
| pak::pak("NOAA-EDAB/comlandr") | |
| shell: Rscript {0} | |
| - name: Read, pull, and compare | |
| env: | |
| API_KEY: ${{ secrets.FREDAPI }} | |
| # reads in data from inst/extdata/fred | |
| run: | | |
| oldFred <- readRDS("inst/extdata/fred/fred.rds") | |
| source(here::here("data-raw/get_fred.R")) | |
| source(here::here("data-raw/compare_fred_data.R")) | |
| newFred <- get_fred() | |
| saveRDS(newFred,"inst/extdata/fred/fred.rds") | |
| comp <- compare_fred_data(oldFred,newFred) | |
| rmarkdown::render(here::here("data-raw/sendAsEmail.Rmd"), | |
| params = comp) | |
| shell: Rscript {0} | |
| # Send email indicating if anything has changed | |
| - name: Send email | |
| uses: dawidd6/action-send-mail@v14 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 465 | |
| username: ${{ secrets.AB_MAIL_USERNAME }} | |
| password: ${{ secrets.AB_MAIL_PASSWORD }} | |
| subject: Github Actions job result | |
| to: andrew.beet@noaa.gov | |
| from: 'comlandr FRED update <noreply@gmail.com>' | |
| envelope_from: ${{ secrets.AB_MAIL_USERNAME }} | |
| #body: file://${{github.workspace}}/data-raw/datapull.txt | |
| html_body: file://${{github.workspace}}/data-raw/sendAsEmail.html | |
| - name: commit data files | |
| run: | | |
| git config user.name github-actions | |
| git config user.email github-actions@github.com | |
| git add inst/extdata/fred/fred.rds | |
| git add data-raw/datapull.txt | |
| git commit -m "automated commit from getFred.yaml" | |
| git push | |