simple-go-action/main.go

40 lines
722 B
Go
Raw Normal View History

2023-04-17 13:52:29 +08:00
package main
import (
"fmt"
2024-08-12 16:54:18 +08:00
"os"
2023-04-17 13:52:29 +08:00
"time"
)
func main() {
2024-08-12 16:54:18 +08:00
username := readInputs()
2023-04-17 13:52:29 +08:00
fmt.Printf("username is %s\n", username)
2024-08-12 16:54:18 +08:00
err := writeOutputs("time", time.Now().Format("2006-01-02 15:04:05"))
if err != nil {
panic(err)
}
2023-04-17 13:52:29 +08:00
}
2024-08-12 16:54:18 +08:00
func readInputs() string {
username := os.Getenv("INPUT_USERNAME")
return username
}
func writeOutputs(k, v string) (err error) {
msg := fmt.Sprintf("%s=%s", k, v)
outputFilepath := os.Getenv("GITHUB_OUTPUT")
f, err := os.OpenFile(outputFilepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return
}
defer func() {
if cErr := f.Close(); cErr != nil && err == nil {
err = cErr
}
}()
if _, err = f.Write([]byte(msg)); err != nil {
return
}
return
}