commit ea9148395c4b28300631d9acac5b83ade923a232 Author: fghwett <1058178245@qq.com> Date: Wed Dec 18 11:23:01 2024 +0800 first version diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..4894e9c --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,21 @@ +name: '代码更新通知' +on: + push: + +jobs: + update-server: + runs-on: home-lab + steps: + - name: 输出当前目录环境 + run: pwd && ls -ahl + - name: 发送通知 + id: use-go-action + uses: https://git.aweoo.com/learning/simple-go-action@latest + with: + username: foo + - name: Print Output + run: echo 'output time is ${{ steps.use-go-action.outputs.time }}' + - name: 错误处理 + if: ${{ failure() }} + run: | + echo '出错了 你个笨蛋' \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c93f1a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +_tmp/ +out/ +dist/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..b71b02b --- /dev/null +++ b/action.yaml @@ -0,0 +1,14 @@ +name: 'Simple Go Action' +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: + using: 'go' + main: 'main.go' + pre: 'pre/main.go' + post: 'post/main.go' \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..31dc5f5 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.aweoo.com/action/gotify + +go 1.23.3 + +require github.com/sethvargo/go-githubactions v1.3.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3418b69 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/sethvargo/go-githubactions v1.3.0 h1:Kg633LIUV2IrJsqy2MfveiED/Ouo+H2P0itWS0eLh8A= +github.com/sethvargo/go-githubactions v1.3.0/go.mod h1:7/4WeHgYfSz9U5vwuToCK9KPnELVHAhGtRwLREOQV80= diff --git a/main.go b/main.go new file mode 100644 index 0000000..e8d6c9c --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "encoding/json" + "fmt" + "github.com/sethvargo/go-githubactions" + "time" +) + +func main() { + + ctx, err := githubactions.Context() + if err != nil { + panic(err) + } + + body, err := json.Marshal(ctx) + if err != nil { + panic(err) + } + fmt.Printf("context: %s\n", string(body)) + + username := githubactions.GetInput("username") + fmt.Printf("username is %s\n", username) + + githubactions.SetOutput("time", time.Now().Format("2006-01-02 15:04:05")) +} diff --git a/post/main.go b/post/main.go new file mode 100644 index 0000000..c15cdb4 --- /dev/null +++ b/post/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Post of Simple Go Action") +} diff --git a/pre/main.go b/pre/main.go new file mode 100644 index 0000000..b8d5edd --- /dev/null +++ b/pre/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Pre of Simple Go Action") +}