nealrichardson commented on code in PR #13266:
URL: https://github.com/apache/arrow/pull/13266#discussion_r888934394


##########
.github/workflows/r_nightly.yml:
##########
@@ -65,54 +68,58 @@ jobs:
           fi
           echo $PREFIX
 
-          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries --skip-pattern-validation $PREFIX
+          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries $PREFIX

Review Comment:
   How is `$PREFIX` ever not empty? 



##########
.github/workflows/r_nightly.yml:
##########
@@ -65,54 +68,58 @@ jobs:
           fi
           echo $PREFIX
 
-          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries --skip-pattern-validation $PREFIX
+          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries $PREFIX
+
+          if [ -n "$(ls -A binaries/*/*/)" ]; then
+            echo "Found files!"
+            echo "GOT_FILES=true" >> $GITHUB_ENV
+          else
+            echo "No files found. Stopping upload."
+            echo "GOT_FILES=false" >> $GITHUB_ENV
+          fi
       - name: Build Repository
+        if: env.GOT_FILES == 'true'
         shell: Rscript {0}

Review Comment:
   Would it help with readability or maintainability to pull this script out to 
a standalone .R file, rather than have it inlined in the yaml?



##########
.github/workflows/r_nightly.yml:
##########
@@ -25,7 +28,7 @@ on:
         required: false
         default: ''
   schedule:

Review Comment:
   Should we also trigger this workflow on changes to the workflow file itself, 
like we do for other workflows (e.g. 
https://github.com/apache/arrow/blob/master/.github/workflows/r.yml#L23)? There 
are tradeoffs but it would make it easier to test changes to the nightly 
uploading code, which is non-trivial. 



##########
.github/workflows/r_nightly.yml:
##########
@@ -65,54 +68,58 @@ jobs:
           fi
           echo $PREFIX
 
-          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries --skip-pattern-validation $PREFIX
+          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries $PREFIX
+
+          if [ -n "$(ls -A binaries/*/*/)" ]; then
+            echo "Found files!"
+            echo "GOT_FILES=true" >> $GITHUB_ENV
+          else
+            echo "No files found. Stopping upload."
+            echo "GOT_FILES=false" >> $GITHUB_ENV
+          fi
       - name: Build Repository
+        if: env.GOT_FILES == 'true'
         shell: Rscript {0}
         run: |
+          repo_root <- "repo"
           art_path <- list.files("binaries",
-              recursive = TRUE,
-              include.dirs = TRUE,
-              pattern = "r-nightly-packages$",
-              full.names = TRUE
+            recursive = TRUE,
+            include.dirs = TRUE,
+            pattern = "r-nightly-packages$",
+            full.names = TRUE
           )
 
-          pkgs <- list.files(art_path, pattern = "r-pkg_*")
-          src_i <- grep("r-pkg_src", pkgs)
-          src_pkg <- pkgs[src_i]
-          pkgs <- pkgs[-src_i]
-          libs <- list.files(art_path, pattern = "r-libarrow*")
+          current_path <- list.files(art_path, full.names = TRUE, recursive = 
TRUE)
+          files <- sub("r-(pkg|lib)", repo_root, current_path)
+          new_paths <- gsub("__", "/", files)
+          new_paths <- sub(art_path, ".", new_paths)
+          dirs <- dirname(new_paths)
+          dir_result <- sapply(dirs, dir.create, recursive = TRUE)
 
-          new_names <- sub("r-pkg_", "", pkgs, fixed = T)
-          matches <- regmatches(new_names, 
regexec("(([a-z]+)-[\\.a-zA-Z0-9]+)_(\\d\\.\\d)-(arrow.+)$", new_names))
-
-          dir.create("repo/src/contrib", recursive = TRUE)
-          file.copy(paste0(art_path, "/", src_pkg), 
paste0("repo/src/contrib/", sub("r-pkg_src-", "", src_pkg)))
-          tools::write_PACKAGES("repo/src/contrib", type = "source", verbose = 
TRUE)
+          if (!all(dir_result)) {
+            stop("There was an issue while creating the folders!")
+          }
 
-          for (match in matches) {
-              path <- paste0("repo/bin/", match[[3]], "/contrib/", match[[4]])
-              path <- sub("macos", "macosx", path)
-              dir.create(path, recursive = TRUE)
-              file <- list.files(art_path, pattern = paste0(match[[1]], "*"), 
full.names = TRUE)
+          copy_result <- file.copy(current_path, new_paths)
 
-              file.copy(file, paste0(path, "/", match[[5]]))
-              tools::write_PACKAGES(path, type = paste0(substring(match[[3]], 
1, 3), ".binary"), verbose = TRUE)
+          if (!all(copy_result)) {
+            stop("There was an issue while copying the files!")
           }
 
-          lib_names <- sub("r-libarrow-", "", libs)
-          lib_match <- regmatches(lib_names, regexec("([[:alpha:]]+)-(.+)", 
lib_names))
+          tools::write_PACKAGES(file.path(repo_root, "src/contrib"), type = 
"source", verbose = TRUE)
 
-          dir.create("repo/libarrow/bin/windows", recursive = TRUE)
-          dir.create("repo/libarrow/bin/centos-7", recursive = TRUE)
-          dir.create("repo/libarrow/bin/ubuntu-18.04", recursive = TRUE)
+          repo_dirs <- list.dirs("repo")

Review Comment:
   ```suggestion
             repo_dirs <- list.dirs(repo_root)
   
   ```



##########
dev/tasks/r/github.packages.yml:
##########
@@ -297,7 +312,7 @@ jobs:
         shell: Rscript {0}
         run: |
           file_paths <- list.files("artifacts", include.dirs = FALSE, 
recursive = TRUE)
-          new_names <- paste0("binaries/", sub("/","-",file_paths))
+          new_names <- paste0("binaries/", sub("/","__",file_paths))

Review Comment:
   And likewise with L317?
   
   ```suggestion
             new_names <- file.path("binaries", sub("/", "__", file_paths))
   
   ```



##########
.github/workflows/r_nightly.yml:
##########
@@ -65,54 +68,58 @@ jobs:
           fi
           echo $PREFIX
 
-          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries --skip-pattern-validation $PREFIX
+          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries $PREFIX
+
+          if [ -n "$(ls -A binaries/*/*/)" ]; then
+            echo "Found files!"
+            echo "GOT_FILES=true" >> $GITHUB_ENV
+          else
+            echo "No files found. Stopping upload."
+            echo "GOT_FILES=false" >> $GITHUB_ENV
+          fi
       - name: Build Repository
+        if: env.GOT_FILES == 'true'
         shell: Rscript {0}
         run: |
+          repo_root <- "repo"

Review Comment:
   Can you please liberally add code comments in this script to explain what 
you're doing and why? Particularly useful might be to describe/give examples of 
the inputs and outputs; otherwise it's not clear why all of the regex-ing.



##########
.github/workflows/r_nightly.yml:
##########
@@ -65,54 +68,58 @@ jobs:
           fi
           echo $PREFIX
 
-          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries --skip-pattern-validation $PREFIX
+          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries $PREFIX
+
+          if [ -n "$(ls -A binaries/*/*/)" ]; then
+            echo "Found files!"
+            echo "GOT_FILES=true" >> $GITHUB_ENV
+          else
+            echo "No files found. Stopping upload."
+            echo "GOT_FILES=false" >> $GITHUB_ENV
+          fi
       - name: Build Repository
+        if: env.GOT_FILES == 'true'
         shell: Rscript {0}
         run: |
+          repo_root <- "repo"
           art_path <- list.files("binaries",
-              recursive = TRUE,
-              include.dirs = TRUE,
-              pattern = "r-nightly-packages$",
-              full.names = TRUE
+            recursive = TRUE,
+            include.dirs = TRUE,
+            pattern = "r-nightly-packages$",
+            full.names = TRUE
           )
 
-          pkgs <- list.files(art_path, pattern = "r-pkg_*")
-          src_i <- grep("r-pkg_src", pkgs)
-          src_pkg <- pkgs[src_i]
-          pkgs <- pkgs[-src_i]
-          libs <- list.files(art_path, pattern = "r-libarrow*")
+          current_path <- list.files(art_path, full.names = TRUE, recursive = 
TRUE)
+          files <- sub("r-(pkg|lib)", repo_root, current_path)
+          new_paths <- gsub("__", "/", files)
+          new_paths <- sub(art_path, ".", new_paths)
+          dirs <- dirname(new_paths)
+          dir_result <- sapply(dirs, dir.create, recursive = TRUE)
 
-          new_names <- sub("r-pkg_", "", pkgs, fixed = T)
-          matches <- regmatches(new_names, 
regexec("(([a-z]+)-[\\.a-zA-Z0-9]+)_(\\d\\.\\d)-(arrow.+)$", new_names))
-
-          dir.create("repo/src/contrib", recursive = TRUE)
-          file.copy(paste0(art_path, "/", src_pkg), 
paste0("repo/src/contrib/", sub("r-pkg_src-", "", src_pkg)))
-          tools::write_PACKAGES("repo/src/contrib", type = "source", verbose = 
TRUE)
+          if (!all(dir_result)) {
+            stop("There was an issue while creating the folders!")
+          }
 
-          for (match in matches) {
-              path <- paste0("repo/bin/", match[[3]], "/contrib/", match[[4]])
-              path <- sub("macos", "macosx", path)
-              dir.create(path, recursive = TRUE)
-              file <- list.files(art_path, pattern = paste0(match[[1]], "*"), 
full.names = TRUE)
+          copy_result <- file.copy(current_path, new_paths)
 
-              file.copy(file, paste0(path, "/", match[[5]]))
-              tools::write_PACKAGES(path, type = paste0(substring(match[[3]], 
1, 3), ".binary"), verbose = TRUE)
+          if (!all(copy_result)) {
+            stop("There was an issue while copying the files!")
           }
 
-          lib_names <- sub("r-libarrow-", "", libs)
-          lib_match <- regmatches(lib_names, regexec("([[:alpha:]]+)-(.+)", 
lib_names))
+          tools::write_PACKAGES(file.path(repo_root, "src/contrib"), type = 
"source", verbose = TRUE)
 
-          dir.create("repo/libarrow/bin/windows", recursive = TRUE)
-          dir.create("repo/libarrow/bin/centos-7", recursive = TRUE)
-          dir.create("repo/libarrow/bin/ubuntu-18.04", recursive = TRUE)
+          repo_dirs <- list.dirs("repo")
+          pkg_dirs <- repo_dirs[grepl(".+contrib\\/\\d.+", repo_dirs)]

Review Comment:
   ```suggestion
             pkg_dirs <- grep(".+contrib\\/\\d.+", repo_dirs, value = TRUE)
   
   ```



##########
.github/workflows/r_nightly.yml:
##########
@@ -65,54 +68,58 @@ jobs:
           fi
           echo $PREFIX
 
-          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries --skip-pattern-validation $PREFIX
+          archery crossbow download-artifacts -f r-nightly-packages -t 
binaries $PREFIX
+
+          if [ -n "$(ls -A binaries/*/*/)" ]; then
+            echo "Found files!"
+            echo "GOT_FILES=true" >> $GITHUB_ENV
+          else
+            echo "No files found. Stopping upload."

Review Comment:
   Why not just `exit 1` and fail the workflow if there are no artifacts to 
upload? Seems like there is a risk that packages will silently fail to upload. 
(It's a risk anyway because no one seems to be alerted when cron workflows 
fail.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to