-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Hello!,
Thanks for the awesome package. I'm currently using it to read/write GitHub Actions (GHA) workflow files in my new R package / GH Action called rworkflows.
I have a scenario where I have a GHA workflow yaml that has the key "on". Thanks to the handler arg I managed to read in the yaml file.
However, I couldn't seem to figure out how to prevent the "on" key being written as 'on': (in single quotes) instead of on: when writing back to disk with write_yaml. This is an issue for GHA as their parser doesn't recognize keys with quotes.
After some playing around, I figured out that the solution was substituting the quoted character and then using file(..., raw=TRUE), but this feature isn't currently exposed to users via write_yaml (as far as I can tell).
Reprex
path <- tempfile(fileext = ".yml")
yml <- yaml::read_yaml("https://raw.githubusercontent.com/neurogenomics/rworkflows/master/inst/yaml/rworkflows_template.yml")
Issue
yaml::write_yaml(yml, path)
yaml file looks like:
name: rworkflows
'on':
push:
- master
- main
pull_request:
- master
- mainSolution
result <- gsub(shQuote("on"),"on",yaml::as.yaml(yml))
path <- file(path, "w", encoding = "UTF-8", raw=TRUE)
open(path, "w")
on.exit(close(path))
cat(result, file = path, sep = "")
name: rworkflows
on:
push:
- master
- main
pull_request:
- master
- mainIf it's helpful, I'd be happy to implement the raw arg in write_yaml and make a Pull Request. Does that sound ok to you (maintainer[s])?
Thanks!,
Brian
Session info
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] yaml_2.3.6
loaded via a namespace (and not attached):
[1] compiler_4.2.1 tools_4.2.1
</details>