download_registers_of_interests #941
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
on: | |
workflow_dispatch: | |
schedule: | |
- cron: 40 16 * * 1-5 | |
name: download_registers_of_interests | |
jobs: | |
download_registers_of_interests: | |
runs-on: macOS-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: r-lib/actions/setup-r@v2 | |
- uses: r-lib/actions/setup-pandoc@v2 | |
- name: Query dependencies | |
run: | | |
install.packages('remotes') | |
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | |
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | |
shell: Rscript {0} | |
- name: Restore R package cache | |
uses: actions/cache@v2 | |
with: | |
path: ${{ env.R_LIBS_USER }} | |
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | |
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- | |
- name: Install dependencies | |
run: | | |
install.packages(c("devtools", "rmarkdown")) | |
devtools::install_deps(dependencies = TRUE) | |
shell: Rscript {0} | |
- name: Checkout registers_of_interests branch | |
uses: actions/checkout@v2 | |
with: | |
ref: registers_of_interests | |
path: registers_of_interests | |
- name: Fetch and write registers of interests | |
run: | | |
devtools::load_all() | |
members <- get_senedd_members(extra_info=TRUE) | |
members %>% write_csv("registers_of_interests/members.csv") | |
interests <- get_interests_for_members(members) | |
interests %>% | |
left_join(members %>% select(SeneddID, Name, Party)) %>% | |
select(SeneddID, Name, Party, everything()) %>% | |
write_csv("registers_of_interests/interests.csv") | |
interests <- interests %>% | |
filter(str_trim(EntrySubject) != 'None') | |
senedd_ids <- interests %>% pull(SeneddID) %>% unique() | |
for(sid in senedd_ids){ | |
sid_path <- paste0("registers_of_interests/registers_by_senedd_id/", sid, ".csv") | |
interests %>% | |
filter(SeneddID == sid) %>% | |
write_csv(sid_path) | |
} | |
members %>% | |
do_gooder_table_from_senedd_members() %>% | |
write_csv("registers_of_interests/members_for_do_gooder.csv") | |
convert_do_gooder_csv_file_encoding("registers_of_interests/members_for_do_gooder.csv") | |
rmarkdown::render("registers_of_interests/README.Rmd") | |
shell: Rscript {0} | |
- name: Commit updated registers | |
run: | | |
cd registers_of_interests | |
git config user.name "Github Actions Bot" | |
git config user.email "<>" | |
git add . | |
git commit -m "Auto-updated" | |
git push origin registers_of_interests | |
cd .. |