Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape {{ and }} in templates #16

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions gootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ func generate(name, group string, templateFS fs.FS, templateDir string) {
}

applyTemplate := func(templ string) string {
// Why: some files, like Github CI files, have notation identical
// To Go templates. So for now we just try to apply the template and if it
// fails we assume it should be used as is (not the safest option, but no more time to deal
// with this right now).
t, err := template.New("templ").Parse(templ)
if err != nil {
return templ
}
assert(err)
result := bytes.Buffer{}
assert(t.Execute(&result, info))
return result.String()
Expand Down
6 changes: 3 additions & 3 deletions templates/basic/.github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ jobs:
uses: "google-github-actions/auth@v2"
with:
token_format: access_token
workload_identity_provider: ${{ vars.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GOOGLE_SERVICE_ACCOUNT }}
workload_identity_provider: ${{"{{"}} vars.GOOGLE_WORKLOAD_IDENTITY_PROVIDER {{"}}"}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is how you're meant to deal with literal {{ and }} in templates. At least I don't see any other solution in the documenation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think this is it indeed... since we dont need to escape in a lot of places maybe it is not that bad x_x

service_account: ${{"{{"}} vars.GOOGLE_SERVICE_ACCOUNT {{"}}"}}
access_token_lifetime: 300s

- name: Login to Artifact Registry
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev/birdie-org/birdie
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
password: ${{"{{"}} steps.auth.outputs.access_token {{"}}"}}

- name: Publish image
run: |
Expand Down
6 changes: 3 additions & 3 deletions templates/basic/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:
uses: "google-github-actions/auth@v2"
with:
token_format: access_token
workload_identity_provider: ${{ vars.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GOOGLE_SERVICE_ACCOUNT }}
workload_identity_provider: ${{"{{"}} vars.GOOGLE_WORKLOAD_IDENTITY_PROVIDER {{"}}"}}
service_account: ${{"{{"}} vars.GOOGLE_SERVICE_ACCOUNT {{"}}"}}
access_token_lifetime: 300s

- name: Login to Artifact Registry
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev/birdie-org/birdie
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
password: ${{"{{"}} steps.auth.outputs.access_token {{"}}"}}

- name: Release
run: make release
Loading