From ca292520017d0f8749e60fb26ec8480ff61a75ed Mon Sep 17 00:00:00 2001 From: dm Date: Mon, 12 Aug 2024 16:54:18 +0800 Subject: [PATCH] test --- .gitea/workflows/build.yaml | 18 ++++++++++++++++++ action.yml | 31 ++++++++++++------------------- main.go | 34 +++++++++++++++++++++++++++++----- 3 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 .gitea/workflows/build.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..41f9aea --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,18 @@ +name: Gitea Actions Demo +run-name: ${{ github.actor }} is testing out Gitea Actions +on: [push] +jobs: + Explore-Gitea-Actions: + runs-on: ubuntu-latest + steps: + - run: echo " The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo " This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo " The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v3 + - run: echo " The ${{ github.repository }} repository has been cloned to the runner." + - run: echo " ️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo " This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/action.yml b/action.yml index 5b9f171..5d55876 100644 --- a/action.yml +++ b/action.yml @@ -1,19 +1,12 @@ -name: 'Test Go Action' -on: [push] -jobs: - use-go-action: - runs-on: ubuntu-latest - steps: - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: '1.20' - - - name: Use Go Action - id: use-go-action - uses: - with: - username: foo - - - name: Print Output - run: echo 'output time is ${{ steps.use-go-action.outputs.time }}' \ No newline at end of file +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' \ No newline at end of file diff --git a/main.go b/main.go index 88206cf..687f185 100644 --- a/main.go +++ b/main.go @@ -2,15 +2,39 @@ package main import ( "fmt" + "os" "time" - - gha "github.com/sethvargo/go-githubactions" ) func main() { - - username := gha.GetInput("username") + username := readInputs() fmt.Printf("username is %s\n", username) - gha.SetOutput("time", time.Now().Format("2006-01-02 15:04:05")) + 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 +} \ No newline at end of file