Skip to content

Commit

Permalink
fix: use GITHUB_OUTPUT instead of deprecated set-output command (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke authored Dec 14, 2022
1 parent 5f78ee7 commit dba4e77
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"io"
"os"
)

Expand Down Expand Up @@ -42,7 +43,16 @@ func main() {
setFailed("Failed to get installation key", fmt.Sprintf("Unable to get intallation token. err: %s", err))
}

setOutput("token", token)
githubOutputFile, err := openGitHubOutput(os.Getenv("GITHUB_OUTPUT"))
if err != nil {
setFailed("Failed to set the output 'token'", fmt.Sprintf("Unable to open GITHUB_OUTPUT. err: %s", err))
return
}
defer githubOutputFile.Close()

if err := setOutput(githubOutputFile, "token", token); err != nil {
setFailed("Failed to set the output 'token'", fmt.Sprintf("Unable to write the token to GITHUB_OUTPUT. err: %s", err))
}
}

func loadPEMFromBytes(key []byte) (*rsa.PrivateKey, error) {
Expand All @@ -59,9 +69,15 @@ func loadPEMFromBytes(key []byte) (*rsa.PrivateKey, error) {
return parsedKey, nil
}

func setOutput(name, value string) {
// print output to stdout
fmt.Printf("::set-output name=%s::%s", name, value)
func openGitHubOutput(p string) (io.WriteCloser, error) {
return os.OpenFile(p, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
}

func setOutput(file io.Writer, name, value string) error {
if _, err := file.Write([]byte(fmt.Sprintf("%s=%s\n", name, value))); err != nil {
return err
}
return nil
}

func setFailed(title, msg string) {
Expand Down

0 comments on commit dba4e77

Please sign in to comment.