Skip to content

Commit

Permalink
publish url checker (#469)
Browse files Browse the repository at this point in the history
* 449 check client urls (#460)

* add github action and script to check front end urls on front end production

* fix name

* use stringr functions

Co-authored-by: Joshua Shapiro <[email protected]>

* move strsplit outside of loop

Co-authored-by: Joshua Shapiro <[email protected]>

* use any + stringr:str_detect

Co-authored-by: Joshua Shapiro <[email protected]>

* append -> c

* fix url source

* test the action on this push

* remove testing hook

* add one more test that should fail

* test on push

* making sure it used the correct list

* unique the expected files

* add missing semicolon

* fix how path ids are merged into the missing list

* R style points

* remove testing event hook

Co-authored-by: Joshua Shapiro <[email protected]>

* 449 check client urls (#468)

* add github action and script to check front end urls on front end production

* fix name

* use stringr functions

Co-authored-by: Joshua Shapiro <[email protected]>

* move strsplit outside of loop

Co-authored-by: Joshua Shapiro <[email protected]>

* use any + stringr:str_detect

Co-authored-by: Joshua Shapiro <[email protected]>

* append -> c

* fix url source

* test the action on this push

* remove testing hook

* add one more test that should fail

* test on push

* making sure it used the correct list

* unique the expected files

* add missing semicolon

* fix how path ids are merged into the missing list

* R style points

* remove testing event hook

* use the production links list

Co-authored-by: Joshua Shapiro <[email protected]>

Co-authored-by: Joshua Shapiro <[email protected]>
  • Loading branch information
davidsmejia and jashapiro authored Jul 16, 2021
1 parent 62b9c66 commit 8124384
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/check-frontend-urls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check Refinebio Frontend Urls

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "check-frontend-urls"
check-frontend-urls:
runs-on: ubuntu-latest
container:
image: rocker/tidyverse:4.0.2

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: Rscript -e "install.packages(c('optparse', 'jsonlite'))"

- name: Run Script to check URLs
id: get_missing_urls
run: |
links=https://raw.githubusercontent.com/AlexsLemonade/refinebio-frontend/master/src/common/examples-links.json
results=$(Rscript "scripts/check-frontend-urls.R" --links $links)
echo "::set-output name=missing_urls::$results"
# Fail if any number besides 0 is returned
- name: Check if any URLs were missing
if: ${{ steps.get_missing_urls.outputs.missing_urls != 'OK' }}
run: |
echo "Please verify that the following file(s) exist:"
echo ${{ steps.get_missing_urls.outputs.missing_urls }}
exit 1
66 changes: 66 additions & 0 deletions scripts/check-frontend-urls.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env Rscript
#
# Check Refinebio-Frontend urls and return anything missing that was expected or NULL

library(optparse)
library(jsonlite)

option_list <- list(
make_option(
opt_str = c("-l", "--links"), type = "character",
default = NULL,
help = "JSON array that will be interpreted as the expected urls.",
metavar = ".json"
)
)

# Parse options
opt <- parse_args(OptionParser(option_list = option_list))

expected_urls <- fromJSON(txt=opt$links)

# urls -> relatative file paths
expected_files <- stringr::word(expected_urls, 2, sep = '/refinebio-examples/')
expected_id_paths <- stringr::str_subset(expected_files, '#')
# remove anchors
expected_files <- unique(stringr::word(expected_files, 1, sep = '#'))

# get a list of all html files in the project
existing_files <- list.files(pattern = 'html$', recursive = TRUE)

# get anything thats not in the project
missing_files <- expected_files[!expected_files %in% existing_files]

# check for missing ids after we know the file isnt missing
# if a file and id is missing it will first complain that the file is missing
if (any(missing_files)) {
expected_id_paths <- expected_id_paths[!grepl(paste(missing_files, collapse="|"), expected_id_paths)]
}
# find missing ids
missing_ids = c()

expected_id_parts_list <- strsplit(expected_id_paths, "#")
for (expected_id_parts in expected_id_parts_list) {
expected_file <- expected_id_parts[1]
expected_id <- expected_id_parts[2]
expected_id_lines <- readr::read_lines(expected_file)

# check if the id="{expected_id}" exists
found <- any(stringr::str_detect(expected_id_lines, paste0('id="', expected_id, '"')))

# add it to missing if not found
if (!found) {
missing_ids <- c(missing_ids, paste0(expected_id_parts, collapse = "#"))
}
}


# group the missing things
missing <- c(missing_files, missing_ids)

# exit with the list or "OK" if nothing missing
if(length(missing) == 0) {
cat('OK')
} else {
cat(paste(missing, collapse = "\n"))
}

0 comments on commit 8124384

Please sign in to comment.