edit some of the text

This commit is contained in:
techknowlogick 2023-04-07 20:38:29 -04:00 committed by Zettat123
parent 36c5613ccb
commit e223b34119

View file

@ -6,19 +6,13 @@ tags: ["actions"]
draft: false
---
Gitea's CI system Gitea Actions has been released in 1.19.0.
Gitea Actions is similar to and GitHub Actions, but there are still some differences.
Gitea's CI system, Gitea Actions, was recently released in version 1.19.0. Gitea Actions is an internal CI/CD system, offering near compatibility with GitHub Actions. One key difference is that Gitea supports both Go and JavaScript actions, while GitHub only supports JavaScript actions natively (though you can use any programming language for Docker container actions).
One of them is that Gitea supports both Go and JavaScript actions while GitHub only supports JavaScript actions
(here we are talking about native actions and you can use any programming languages for Docker container actions).
In this guide, you'll learn how to create a Go action in Gitea.
Before reading this guide, you should have a basic understanding of Gitea Actions.
We recommend you to read [Hacking on Gitea Actions](https://blog.gitea.io/2023/03/hacking-on-gitea-actions/) if you are not familiar with it.
In this guide, we'll show you how to create a Go action in Gitea. Before diving in, you should have a basic understanding of Gitea Actions. If you're not familiar with it, we recommend reading [Hacking on Gitea Actions](https://blog.gitea.io/2023/03/hacking-on-gitea-actions/).
## A Simple Go Action
Let's start with a simple Go action. You need to create a repository called `simple-go-action` on your Gitea instance and clone it.
First, let's create a simple Go action. You'll need to create a repository called `simple-go-action` on your Gitea instance and clone it:
```sh
git clone <repo-url>
@ -27,8 +21,7 @@ cd simple-go-action
go mod init simple-go-action
```
The metadata file is important for actions and it's filename must be either `action.yml` or `action.yaml`.
The `action.yml` file is like the following code. For more information about matadata syntax, see [Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
The metadata file is essential for actions, and its filename must be either `action.yml` or `action.yaml`. Here's an example action.yml file:
```yml
name: 'Simple Go Action'
@ -38,10 +31,11 @@ runs:
main: 'main.go'
```
You might notice that we use `using: 'go'` in the metadata. This means that we specified Go as the runtime of this action.
Since GitHub doesn't support Go actions, you won't see such usage in GitHub's documents.
To read more about the about matadata syntax, you can see the [Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
Then add the `main.go` file. The logic is very simple and it only prints a `Hello world` string.
You may notice that we use `using: 'go'` in the metadata, specifying Go as the runtime for this action. Since GitHub doesn't support Go actions natively, you won't find this in GitHub's documentation.
Next, add the `main.go` file with a simple logic to print a "Hello world" string:
```go
package main
@ -53,9 +47,7 @@ func main() {
}
```
Now the action is ready to be tested. You can commit and push the code to Gitea.
To test the action, you need to create another repository `test-simple-go-action` and create a workflow file using the following code.
Please change the `<action-url>` to the url of your own action.
Now the action is ready to be tested. Commit and push the code to Gitea. To test the action, create another repository called `test-simple-go-action` and add a workflow file using the following code (replace `<action-url>` with the URL of your action):
```yml
name: 'Test Go Action'
@ -73,18 +65,15 @@ jobs:
uses: <action-url>
```
Since the action is written in Go and the `runs-on` environment may not have Go installed, a Go runtime must be setup before using the action.
The `setup-go` action works well in this case, but in some cases it doesn't work, we will discuss later.
After pushing the workflow file, you can see the result in Actions tab.
Since the action is written in Go and the `runs-on` environment may not have Go installed, you'll need to set up a Go runtime before using the action. The `setup-go` action works well in this case, but we'll discuss cases where it doesn't later. After pushing the workflow file, you can see the result in the Actions tab.
![use-go-action-main](/demos/creating-go-actions/use-go-action-main.png)
## Inputs and Outputs
You can specify the data that the action will use by `inputs` parameters, and the data that the action can provide to other actions by `outputs` parameters.
For more information, see GitHub's documents about [`inputs`](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs) and [`outputs`](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions).
You can specify the data that the action will use through inputs parameters and the data that the action can provide to other actions through outputs parameters. For more information, see GitHub's documentation on [`inputs`](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs) and [`outputs`](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions)
To use `inputs` and `outputs`, you need to update the `action.yml` file.
To use `inputs` and `outputs`, you'll need to update the `action.yml` file:
```yml
name: 'Simple Go Action'
@ -101,7 +90,7 @@ runs:
main: 'main.go'
```
And the `main.go` file also need to be updated.
You'll also need to update the `main.go` file:
```go
package main
@ -146,7 +135,7 @@ func writeOutputs(k, v string) (err error) {
}
```
In the workflow that uses the action, you need to add the code related to `inputs` and `outputs`.
In the workflow that uses the action, you need to add the code related to `inputs` and `outputs`:
```yml
name: 'Test Go Action'