vcs-check.R 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env Rscript
  2. library(magrittr)
  3. library(dplyr)
  4. library(stringr)
  5. library(processx)
  6. library(readr)
  7. get_lines <- . %>%
  8. str_replace("\n+$", "") %>%
  9. str_split_fixed(pattern="\n", n=Inf) %>%
  10. as.vector
  11. git_tracked_files <-
  12. run("git", c("ls-tree", "-r", "HEAD", "--name-only")) %$%
  13. stdout %>% get_lines
  14. snakemake_untracked_files <-
  15. run("snakemake", "--list-untracked") %$%
  16. stderr %>% get_lines
  17. all_files <- list.files(".", full.names=TRUE, recursive=TRUE) %>%
  18. str_replace("^./", "")
  19. snakemake_summary <-
  20. run("snakemake", "--summary") %$%
  21. stdout %>% read_tsv
  22. snakemake_generated_files <- snakemake_summary$output_file
  23. ## All files used as inputs to the snakemake workflow
  24. input_files <- setdiff(all_files, c(snakemake_untracked_files, snakemake_generated_files))
  25. untracked_input_files <- setdiff(input_files, git_tracked_files) %>% sort
  26. if (length(untracked_input_files) > 0) {
  27. message("The following files are used as input but not tracked in git:\n",
  28. str_c(untracked_input_files, collapse="\n"))
  29. quit(status=1)
  30. } else {
  31. message("All input files used in the workflow are tracked in git.")
  32. }