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

feat: add shellescape function #58

Merged
merged 1 commit into from
Nov 1, 2023
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: 3 additions & 5 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ jobs:

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
- name: Install Cosign
uses: sigstore/[email protected]
with:
cosign-release: 'v1.13.1'

cosign-release: 'v2.1.1'

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
Expand Down
3 changes: 2 additions & 1 deletion internal/ci/conductor_hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func CreateEvalContext(cfg ConductorConfig, process Process) *hcl.EvalContext {
"yamlencode": yaml.YAMLEncodeFunc,
"zipmap": stdlib.ZipmapFunc,

"stripansi": ui.StripAnsiFunc,
"stripansi": ui.StripAnsiFunc,
"shellescape": ui.ShellEscapeFunc,

"ansifmt": ui.AnsiFunc,
"env": function.New(&function.Spec{
Expand Down
15 changes: 15 additions & 0 deletions internal/ui/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"fmt"
"github.com/acarl005/stripansi"
"github.com/alessio/shellescape"
"github.com/fatih/color"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"
Expand Down Expand Up @@ -76,6 +77,20 @@
},
})

var ShellEscapeFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Name: "message",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
message := args[0].AsString()
return cty.StringVal(shellescape.Quote(message)), nil
},

Check warning on line 91 in internal/ui/colors.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/colors.go#L88-L91

Added lines #L88 - L91 were not covered by tests
})

func Color(color string, message string) string {
switch color {
case "green":
Expand Down
Loading