-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Summary
As a package developer, in order to install working GitHub Actions workflows, I would like
use_github_copilot()to write workflow files without corrupting${{ }}expressions.
Details
The templates in inst/templates/workflows/ contain GitHub Actions expressions such as ${{ secrets.GITHUB_TOKEN }} and ${{ inputs.r-version }}. Because .use_template() delegates to usethis::use_template(), which renders templates via the whisker engine, the {{ }} delimiters are interpreted as template variables. Since these workflows have no package-specific data, whisker silently strips the variable content, producing broken YAML (e.g., $ instead of ${{ secrets.GITHUB_TOKEN }}).
The fix has two parts:
- Add a
.use_template_as_is()internal helper that reads the raw template bytes frominst/templates/and writes them verbatim usingusethis::write_over(), then callsusethis::edit_file()whenopen = TRUE. This is the same observable behavior asusethis::use_template(), but skips therender_template()/ whisker step entirely. Check the code ofusethis::use_templatefor the general idea of what's needed, but we should also handleoverwritein our helper. - Update
use_github_copilot()to call.use_template_as_is()instead of.use_template()for both workflow files.
Escaping {{ / }} in the templates is an alternative but requires ongoing maintenance every time a template is edited, and the escape syntax is not obvious to future contributors.
Behavior
Current (broken):
use_github_copilot()produces acopilot-setup-steps.ymlandinstall/action.ymlin which${{ ... }}expressions are partially or fully stripped, rendering the workflows invalid.
Expected:
- Both installed files are byte-for-byte identical to their templates (no whisker interpolation).
use_github_copilot()tests verify that the installed files contain${{literally (e.g.,${{ secrets.GITHUB_TOKEN }}incopilot-setup-steps.yml,${{ inputs.r-version }}ininstall/action.yml).
Behavior of .use_template_as_is(template, save_as, open = FALSE):
- Reads the template from
system.file("templates", template, package = "pkgskills"). - Processes
overwritearg as in (or with).path_proj_save_asand ultimately.check_path_writable(). We may want to refactor.use_template()to likewise move the.path_proj_save_as()step "inside" the helper, if that makes sense and doesn't break tests. - Writes the content verbatim to
usethis::proj_path(save_as)viausethis::write_over(). - Calls
usethis::edit_file(usethis::proj_path(save_as))whenopen = TRUE.