cargo-generate / cargo-generate

cargo, make me a project

Home Page:https://cargo-generate.github.io/cargo-generate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cargo-generate is not able to generate GH Actions files

SergioGasquez opened this issue · comments

Describe the bug
I've tried to generate some GH Action CI files with cargo-generate and it doesn't work since both things use the same syntax for variables ({{ <variable_name> }}).

To Reproduce
Steps to reproduce the behavior:

  1. cargo generate SergioGasquez/esp-template -b feat/ci --name test -d mcu=esp32 -d advanced=true -d alloc=false -d wokwi=false -d devcontainer=false -d ci=true
  2. See .github/workflows/rust_ci.yml file.

Expected behavior
File is generated properly, although I am not sure how we can solve this.

For ci pipelines you can do the following 2 things:

  • Exclude them from being processed
  • Wrap the whole content of the file with the raw tag

Thanks for the quick response! Excluding is not a solution since I need some parts of the file to be processed, but the raw tag is a perfect solution!

commented

I ran into a similar problem; placeholders weren't being substituted. After an hour of fiddling, I figured that liquid is probably just erroring out silently behind the scenes due to a false positive of a CI variable.

In other words, make sure to wrap {{ }} in your CI workloads with raw tag, even if not placeholder!

To give an example:

❌ Don't do this

jobs:
  test-native:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: 
          - ubuntu-latest
{%- if xplat %}
          - macos-latest
          - windows-latest
{%- endif %}

✅ Do this

jobs:
  test-native:
{% raw -%}
    runs-on: ${{ matrix.os }}
{%- endraw %}
    strategy:
      matrix:
        os: 
          - ubuntu-latest
{%- if xplat %}
          - macos-latest
          - windows-latest
{%- endif %}

Hope this helps someone 👍