Use input and output
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
name: "Simple Go Action"
|
name: "Simple Go Action"
|
||||||
description: "A simple Gitea action written in go"
|
description: "A simple Gitea action written in go"
|
||||||
|
inputs:
|
||||||
|
username:
|
||||||
|
description: "The username to print"
|
||||||
|
required: true
|
||||||
|
outputs:
|
||||||
|
time:
|
||||||
|
description: "The time when the action was called"
|
||||||
runs:
|
runs:
|
||||||
using: "go"
|
using: "go"
|
||||||
main: "main.go"
|
main: "main.go"
|
||||||
|
|||||||
35
main.go
35
main.go
@@ -1,13 +1,40 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
slog.Info("Printing Environment")
|
username := readInputs()
|
||||||
for _, key_val := range os.Environ() {
|
fmt.Printf("username is %s\n", username)
|
||||||
slog.Info(key_val)
|
|
||||||
|
err := writeOutputs("time", time.Now().Format("2006-01-02 15:04:05"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user