Skip to content

Update map data

Update map data #12

name: update-map-data
run-name: Update map data
on:
schedule:
# runs at noon UTC on the 1st of each month
- cron: '0 12 1 * *'
workflow_dispatch:
jobs:
check:
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
- 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: data-raw/shapefiles/${{ env.state_shp }}
COUNTY_SHP: data-raw/shapefiles/${{ env.county_shp }}
run: |
usmapdata:::create_us_map(
"states",
Sys.getenv("STATE_SHP"),
"inst/extdata/us_states.gpkg"
)
usmapdata:::create_us_map(
"counties",
Sys.getenv("COUNTY_SHP"),
"inst/extdata/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
run: |
echo "branch_name=data-update/$(date +'%B-%Y')" >> "$GITHUB_OUTPUT"
echo "pr_title=$(date +'%B %Y') map data update" >> "$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 failure notification
if: ${{ failure() }}
run: |
python data-raw/scripts/pushover.py "⚠️ usmapdata failed to update map data files. (error: ${{ steps.dl-shp.outputs.python_exit_code }})" "LOW"