Skip to content

Commit dba4e77

Browse files
1 parent 5f78ee7 commit dba4e77

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

main.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/base64"
77
"encoding/pem"
88
"fmt"
9+
"io"
910
"os"
1011
)
1112

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

45-
setOutput("token", token)
46+
githubOutputFile, err := openGitHubOutput(os.Getenv("GITHUB_OUTPUT"))
47+
if err != nil {
48+
setFailed("Failed to set the output 'token'", fmt.Sprintf("Unable to open GITHUB_OUTPUT. err: %s", err))
49+
return
50+
}
51+
defer githubOutputFile.Close()
52+
53+
if err := setOutput(githubOutputFile, "token", token); err != nil {
54+
setFailed("Failed to set the output 'token'", fmt.Sprintf("Unable to write the token to GITHUB_OUTPUT. err: %s", err))
55+
}
4656
}
4757

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

62-
func setOutput(name, value string) {
63-
// print output to stdout
64-
fmt.Printf("::set-output name=%s::%s", name, value)
72+
func openGitHubOutput(p string) (io.WriteCloser, error) {
73+
return os.OpenFile(p, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
74+
}
75+
76+
func setOutput(file io.Writer, name, value string) error {
77+
if _, err := file.Write([]byte(fmt.Sprintf("%s=%s\n", name, value))); err != nil {
78+
return err
79+
}
80+
return nil
6581
}
6682

6783
func setFailed(title, msg string) {

0 commit comments

Comments
 (0)