Skip to content

Commit

Permalink
GitHub output adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
josephburnett committed Feb 15, 2025
1 parent 9108c30 commit f048eda
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ COPY . .
RUN set -eux; \
export GOROOT="$(go env GOROOT)"; \
make build
make build-action
FROM scratch
COPY --from=build /go/src/github.com/josephburnett/jd/release/jd /jd
COPY --from=build /go/src/github.com/josephburnett/jd/release/jd-acion /jd-action
ENTRYPOINT ["/jd"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ build-web :
serve : pack-web
go run -tags include_web main.go -port 8080

.PHONY : build-action
build-action :
CGO_ENABLED=0 go build ./github-action -o jd-action main.go

.PHONY : release-build
release-build : check-env check-version check-dirty build-all build-docker
@echo
Expand Down
31 changes: 31 additions & 0 deletions github-action/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"math/rand"
"os"
"os/exec"
"strconv"
)

func main() {
outputFile := os.Getenv("GITHUB_OUTPUT")
if outputFile == "" {
fmt.Printf("GITHUB_OUTPUT not set. Are you running in GitHub CI?")
os.Exit(2)
}
file, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
defer file.Close()
cmd := exec.Command("jd", os.Args[2:]...)
data, _ := cmd.CombinedOutput()
exitCode := cmd.ProcessState.ExitCode()
delimiter := strconv.Itoa(rand.Int())
file.WriteString("output<<" + delimiter + "\n")
file.WriteString(string(data))
file.WriteString("delimiter\n")
os.Exit(exitCode)
}

0 comments on commit f048eda

Please sign in to comment.