Skip to content

Commit

Permalink
Run arbitrary commands with the action
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Nov 17, 2023
1 parent 242ea5c commit e60d037
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: docker/login-action@v2
with:
Expand Down
25 changes: 7 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
name: "Jalapeno"
description: "Run Jalapeno check on the workspace"
description: "Run arbitrary Jalapeno commands"
inputs:
insecure:
description: "Allow connections to SSL registry without certs"
default: "false"
required: false
plain-http:
description: "Allow insecure connections to registry without SSL check"
default: "false"
required: false
ca-file:
description: "Server certificate authority file for the remote registry"
required: false
cmd:
description: "The command which should be run"
required: true
outputs:
result:
description: "stdout after running the command"
exitcode:
description: "Exit code of the operation"
runs:
using: "docker"
image: "docker://ghcr.io/futurice/jalapeno:v0-githubaction"
args:
- check
- --dir=${{ github.workspace }}
- --detailed-exitcode
- --insecure=${{ inputs.insecure }}
- --plain-http=${{ inputs.plain-http }}
- --ca-file=${{ inputs.ca-file }}
- ${{ inputs.cmd }}
7 changes: 7 additions & 0 deletions cmd/action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"os"

"github.com/futurice/jalapeno/internal/cli"
"github.com/gofrs/uuid"
)

const (
OutputResult = "result"
OutputExitCode = "exitcode"
)

Expand All @@ -22,8 +24,13 @@ func main() {
output, err := os.OpenFile(os.Getenv("GITHUB_OUTPUT"), os.O_APPEND|os.O_WRONLY, 0644)
checkErr(err)

delimiter := uuid.Must(uuid.NewV4()).String()
fmt.Fprintf(output, "%s << %s\n", OutputResult, delimiter)

cmd := cli.NewRootCmd("")
cmd.SetOut(output)
err = cmd.ExecuteContext(context.Background())
fmt.Fprintf(output, "%s\n", delimiter)

exitCode, isExitCodeSet := cmd.Context().Value(cli.ExitCodeContextKey{}).(int)
if !isExitCodeSet {
Expand Down

0 comments on commit e60d037

Please sign in to comment.