Skip to content

Add latest map data

Add latest map data #4

name: build-map-data
run-name: Add ${{ inputs.year || 'latest' }} map data
on:
schedule:
# runs at noon UTC on the 1st of each month
- cron: '0 12 1 * *'
workflow_dispatch:
inputs:
year:
description: "Shape file year"
required: false
default: ''
jobs:
build:
runs-on: ubuntu-latest
env:
PUSHOVER_API_KEY: ${{ secrets.PUSHOVER_API_KEY }}
PUSHOVER_USER_KEY: ${{ secrets.PUSHOVER_USER_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
cache: 'pip'
- name: Install Python dependencies
run: pip install -r data-raw/scripts/requirements.txt
- name: Download shapefiles
id: dl-shp
run: |
python data-raw/scripts/shapefiles.py ${{ inputs.year }}
- name: Setup R
uses: r-lib/actions/setup-r@v2
- name: Install R dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: local::.
- name: Modify shapefiles
env:
STATE_SHP: ${{ env.state_shp }}
COUNTY_SHP: ${{ env.county_shp }}
YEAR: ${{ env.shp_year }}
run: |
input_dir <- file.path("data-raw", "shapefiles", Sys.getenv("YEAR"))
output_dir <- file.path("inst", "extdata", Sys.getenv("YEAR"))
usmapdata:::create_us_map(
"states",
file.path(input_dir, Sys.getenv("STATE_SHP")),
output_dir,
"us_states.gpkg"
)
usmapdata:::create_us_map(
"counties",
file.path(input_dir, Sys.getenv("COUNTY_SHP")),
output_dir,
"us_counties.gpkg"
)
shell: Rscript {0}
- name: Import GPG signing key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Determine pull request parameters
id: pr-params
env:
YEAR: ${{ env.shp_year }}
run: |
echo "branch_name=data-update/$YEAR" >> "$GITHUB_OUTPUT"
echo "pr_title=Add $YEAR map data" >> "$GITHUB_OUTPUT"
- name: Render pull request body
id: pr-body
uses: chuhlomin/render-template@v1
with:
template: data-raw/scripts/update-data-pr-body.md
vars: |
branch_name: ${{ steps.pr-params.outputs.branch_name }}
- name: Open pull request
id: open-pr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.BOT_PAT }}
author: ${{ secrets.BOT_USER }}
committer: ${{ secrets.BOT_USER }}
commit-message: "[automated] Update map data based on latest shapefiles"
branch: ${{ steps.pr-params.outputs.branch_name }}
title: ${{ steps.pr-params.outputs.pr_title }}
body: ${{ steps.pr-body.outputs.result }}
reviewers: pdil
assignees: pdil
labels: data update
delete-branch: true
- name: Send success notification
run: |
python data-raw/scripts/pushover.py "✅ usmapdata has updated its data files, a PR review is needed: <a href=\"${{ steps.open-pr.outputs.pull-request-url }}\">PR #${{ steps.open-pr.outputs.pull-request-number }}</a>"
- name: Send data not found notification
if: ${{ failure() && steps.dl-shp.outputs.exit_code == '404' }}
run: |
python data-raw/scripts/pushover.py "⚠️ usmapdata failed to find map data files for ${{ env.shp_year }}." "LOW"
- name: Send failure notification
if: ${{ failure() && steps.dl-shp.outputs.exit_code != '404' }}
run: |
python data-raw/scripts/pushover.py "❌ usmapdata failed to update map data files. (error: ${{ steps.dl-shp.outputs.exit_code }})" "LOW"