-
Notifications
You must be signed in to change notification settings - Fork 0
187 lines (158 loc) · 6 KB
/
build-map-data.yaml
File metadata and controls
187 lines (158 loc) · 6 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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:
download:
runs-on: ubuntu-latest
outputs:
exit_code: ${{ steps.dl-shp.outputs.exit_code }}
shp_year: ${{ steps.info.outputs.shp_year }}
state_shp: ${{ steps.info.outputs.state_shp }}
county_shp: ${{ steps.info.outputs.county_shp }}
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: Save shapefile info
id: info
run: |
echo "shp_year=${{ env.shp_year }}" >> "$GITHUB_OUTPUT"
echo "state_shp=${{ env.state_shp }}" >> "$GITHUB_OUTPUT"
echo "county_shp=${{ env.county_shp }}" >> "$GITHUB_OUTPUT"
- name: Upload shapefiles
if: steps.dl-shp.outputs.exit_code == '0'
uses: actions/upload-artifact@v4
with:
name: shapefiles
path: data-raw/shapefiles/${{ env.shp_year }}
process:
runs-on: ubuntu-latest
needs: download
if: needs.download.outputs.exit_code == '0'
outputs:
pr_url: ${{ steps.info.outputs.pr_url }}
pr_number: ${{ steps.info.outputs.pr_number }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download shapefiles
uses: actions/download-artifact@v4
with:
name: shapefiles
path: data-raw/shapefiles/${{ needs.download.outputs.shp_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: ${{ needs.download.outputs.state_shp }}
COUNTY_SHP: ${{ needs.download.outputs.county_shp }}
YEAR: ${{ needs.download.outputs.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: ${{ needs.download.outputs.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] Add ${{ needs.download.outputs.shp_year }} map data based on available 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: Save PR info
id: info
run: |
echo "pr_url=${{ steps.open-pr.outputs.pull-request-url }}" >> "$GITHUB_OUTPUT"
echo "pr_number=${{ steps.open-pr.outputs.pull-request-number }}" >> "$GITHUB_OUTPUT"
notify:
runs-on: ubuntu-latest
needs: [download, process]
if: always()
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: Send success notification
if: needs.download.outputs.exit_code == '0' && needs.process.result == 'success'
run: |
python data-raw/scripts/pushover.py "✅ usmapdata has updated its data files, a PR review is needed: <a href=\"${{ needs.process.outputs.pr_url }}\">PR #${{ needs.process.outputs.pr_number }}</a>"
- name: Send data not found notification
if: needs.download.outputs.exit_code == '404'
run: |
python data-raw/scripts/pushover.py "⚠️ usmapdata failed to find map data files for ${{ needs.download.outputs.shp_year }}." "LOW"
- name: Send failure notification
if: needs.download.outputs.exit_code != '0' && needs.download.outputs.exit_code != '404'
run: |
python data-raw/scripts/pushover.py "❌ usmapdata failed to update map data files. (error: ${{ needs.download.outputs.exit_code }})" "LOW"