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


##########
dev/tasks/r/github.packages.yml:
##########
@@ -279,8 +286,8 @@ jobs:
           {{ macros.github_test_r_src_pkg()|indent(8) }}
 
   upload-binaries:
-    needs: r-packages
-    if: true && !cancelled()
+    # Only upload binaries if all tests pass.

Review Comment:
   Ah, I see. So a tricky thing to watch out for is the binary package path, 
which `contrib.url()` will return 
(https://github.com/ursa-labs/arrow-r-nightly/blob/master/build-binary-and-upload.R#L30).
 This is different on different R versions and platforms, and unfortunately, 
CRAN has changed this repo layout periodically--not super frequent, of course, 
but it seems like with many major releases (annual) there is a change. 
   
   For example, on my machine:
   
   ```
   > contrib.url("", type="binary")
   [1] "/bin/macosx/big-sur-arm64/contrib/4.2"
   ```
   
   I see the binaries get uploaded as artifacts like this:
   
   ```
         - name: Upload binary artifact
           uses: actions/upload-artifact@v3
           with:
             name: r-pkg-{{ '${{ matrix.platform }}-${{ matrix.r_version.r }}' 
}}
             path: arrow_*
   ```
   
   I might not be following things correctly, but I don't see how you could end 
up with that path based on how you're constructing them now. I know we aren't 
building M1 binaries today, but that's kinda my point: it would be ideal if we 
didn't have to change the glue code every time we add a new package or when R 
changes things.
   
   The easiest way to make sure you get the right path is to call contrib.url() 
from the platform/version you're building on. Maybe instead we create the 
artifact name based on what contrib.url does, just replacing the path 
separators with something else, like 
   
   ```
   > gsub("/", "__", contrib.url("", type="binary"))
   [1] "__bin__macosx__big-sur-arm64__contrib__4.2"
   ```
   
   We can get that into an env var, and then maybe pass it as an `output` so 
that it can be available in the upload step?
   
   ```
    % filename=$(Rscript -e 'cat(gsub("/", "__", contrib.url("", 
type="binary")))')
    % echo $filename                                                            
   
   __bin__macosx__big-sur-arm64__contrib__4.2
   ```
   
   Then in r_nightly.yml we gsub back, recursively create the dirs, and that's 
it. It's a little tortured, but seems less so than trying to reimplement 
contrib.url?



##########
.github/workflows/r_nightly.yml:
##########
@@ -76,43 +88,42 @@ jobs:
               full.names = TRUE
           )
 
-          pkgs <- list.files(art_path, pattern = "r-pkg_*")
-          src_i <- grep("r-pkg_src", pkgs)
+          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*")
 
-          new_names <- sub("r-pkg_", "", pkgs, fixed = T)
-          matches <- regmatches(new_names, 
regexec("(([a-z]+)-[\\.a-zA-Z0-9]+)_(\\d\\.\\d)-(arrow.+)$", new_names))
+          matches <- regmatches(pkgs, 
regexec("r-pkg-(([a-z]+)-[\\.a-zA-Z0-9]+)-(\\d\\.\\d)-(arrow.+)$", pkgs))
+
 
           dir.create("repo/src/contrib", recursive = TRUE)
-          file.copy(paste0(art_path, "/", src_pkg), 
paste0("repo/src/contrib/", sub("r-pkg_src-", "", src_pkg)))
+          file.copy(file.path(art_path, src_pkg), 
file.path("repo/src/contrib", sub("r-pkg-src-", "", src_pkg)))
           tools::write_PACKAGES("repo/src/contrib", type = "source", verbose = 
TRUE)
 
           for (match in matches) {
-              path <- paste0("repo/bin/", match[[3]], "/contrib/", match[[4]])
+              path <- file.path("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)
+              file <- file.path(art_path, match[[1]])
 
-              file.copy(file, paste0(path, "/", match[[5]]))
+              file.copy(file, file.path(path, match[[5]]))
               tools::write_PACKAGES(path, type = paste0(substring(match[[3]], 
1, 3), ".binary"), verbose = TRUE)
           }
 
-          lib_names <- sub("r-libarrow-", "", libs)
-          lib_match <- regmatches(lib_names, regexec("([[:alpha:]]+)-(.+)", 
lib_names))
-
-          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)
+          lib_match <- regmatches(libs, 
regexec("r-libarrow-(windows|[[:alpha:]]+-\\d.*)-(arrow-.+)", libs))
 
           for (match in lib_match) {
-              path <- list.files("repo//libarrow//bin", pattern = match[[2]], 
full.names = TRUE)
-              file <- paste0(art_path, "/r-libarrow-", match[[1]])
-              file.copy(file, paste0(path, "//", match[[3]]))
+              path <- file.path("repo/libarrow/bin", match[[2]])
+              file <- file.path(art_path, match[[1]])
+              dir.create(path, recursive = TRUE, showWarnings = FALSE)
+              file.copy(file, file.path(path, match[[3]]))
           }
-      - run: ls -R repo
+      - name: Show repo contents
+        if: env.GOT_FILES == 'true'
+        run: ls -R repo
       - name: Upload Files
+        if: env.GOT_FILES == 'true'
         uses: burnett01/[email protected]
         with:
           switches: -avzr

Review Comment:
   The workflow is erroring: 
https://github.com/apache/arrow/runs/6690966333?check_suite_focus=true#step:11:19
   
   You may need more switches to make it create the intermediate subdirectories?



-- 
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