Skip to content

Commit

Permalink
Docs for Gitea Actions (#24405)
Browse files Browse the repository at this point in the history
A new documentation section for Gitea Actions.

Some content comes from:

- [Hacking on Gitea
Actions](https://blog.gitea.io/2023/03/hacking-on-gitea-actions/)
- The README of [act_runner](https://gitea.com/gitea/act_runner)
- @ChristopherHX's excellent overview of the differences between Gitea
Actions and GitHub Actions in [this
comment](#13539 (comment)).

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
  • Loading branch information
3 people authored May 5, 2023
1 parent b8c19e7 commit 8f314c6
Show file tree
Hide file tree
Showing 14 changed files with 888 additions and 1 deletion.
13 changes: 13 additions & 0 deletions docs/content/doc/actions.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
date: "2023-04-27T14:00:00+08:00"
title: "Actions"
slug: "actions"
weight: 36
toc: false
draft: false
menu:
sidebar:
name: "Usage - Actions"
weight: 31
identifier: "actions"
---
206 changes: 206 additions & 0 deletions docs/content/doc/actions/act-runner.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
---
date: "2023-04-27T15:00:00+08:00"
title: "Act Runner"
slug: "usage/actions/act-runner"
weight: 20
draft: false
toc: false
menu:
sidebar:
parent: "actions"
name: "Act Runner"
weight: 20
identifier: "actions-runner"
---

# Act Runner

This page will introduce the [act runner](https://gitea.com/gitea/act_runner) in detail, which is the runner of Gitea Actions.

**Table of Contents**

{{< toc >}}

## Requirements

It is recommended to run jobs in a docker container, so you need to install docker first.
And make sure that the docker daemon is running.

Other OCI container engines which are compatible with Docker's API should also work, but are untested.

However, if you are sure that you want to run jobs directly on the host only, then docker is not required.

## Installation

There are multiple ways to install the act runner.

### Download the binary

You can download the binary from the [release page](https://gitea.com/gitea/act_runner/releases).
However, if you want to use the latest nightly build, you can download it from the [download page](https://dl.gitea.com/act_runner/).

When you download the binary, please make sure that you have downloaded the correct one for your platform.
You can check it by running the following command:

```bash
chmod +x act_runner
./act_runner --version
```

If you see the version information, it means that you have downloaded the correct binary.

### Use the docker image

You can use the docker image from the [docker hub](https://hub.docker.com/r/gitea/act_runner/tags).
Just like the binary, you can use the latest nightly build by using the `nightly` tag, while the `latest` tag is the latest stable release.

```bash
docker pull gitea/act_runner:latest # for the latest stable release
docker pull gitea/act_runner:nightly # for the latest nightly build
```

## Configuration

Configuration is done via a configuration file. It is optional, and the default configuration will be used when no configuration file is specified.

You can generate a configuration file by running the following command:

```bash
./act_runner generate-config
```

The default configuration is safe to use without any modification, so you can just use it directly.

```bash
./act_runner generate-config > config.yaml
./act_runner --config config.yaml [command]
```

When you are using the docker image, you can specify the configuration file by using the `CONFIG_FILE` environment variable. Make sure that the file is mounted into the container as a volume:

```bash
docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```

You may notice the commands above are both incomplete, because it is not the time to run the act runner yet.
Before running the act runner, we need to register it to your Gitea instance first.

## Registration

Registration is required before running the act runner, because the runner needs to know where to get jobs from.
And it is also important to Gitea instance to identify the runner.

### Runner levels

You can register a runner in different levels, it can be:

- Instance level: The runner will run jobs for all repositories in the instance.
- Organization level: The runner will run jobs for all repositories in the organization.
- Repository level: The runner will run jobs for the repository it belongs to.

Note that the repository may still use instance-level or organization-level runners even if it has its own repository-level runners. A future release may provide an option to allow more control over this.

### Obtain a registration token

The level of the runner determines where to obtain the registration token.

- Instance level: The admin settings page, like `<your_gitea.com>/admin/runners`.
- Organization level: The organization settings page, like `<your_gitea.com>/<org>/settings/runners`.
- Repository level: The repository settings page, like `<your_gitea.com>/<owner>/<repo>/settings/runners`.

If you cannot see the settings page, please make sure that you have the right permissions and that Actions have been enabled.

The format of the registration token is a random string `D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx`.

### Register the runner

The act runner can be registered by running the following command:

```bash
./act_runner register
```

Alternatively, you can use the `--config` option to specify the configuration file mentioned in the previous section.

```bash
./act_runner --config config.yaml register
```

You will be asked to input the registration information step by step. Includes:

- The Gitea instance URL, like `https://gitea.com/` or `http://192.168.8.8:3000/`.
- The registration token.
- The runner name, which is optional. If you leave it blank, the hostname will be used.
- The runner labels, which is optional. If you leave it blank, the default labels will be used.

You may be confused about the runner labels, which will be explained later.

If you want to register the runner in a non-interactive way, you can use arguments to do it.

```bash
./act_runner register --no-interactive --instance <intance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```

When you have registered the runner, you can find a new file named `.runner` in the current directory.
This file stores the registration information.
Please do not edit it manually.
If this file is missing or corrupted, you can simply remove it and register again.

If you want to store the registration information in another place, you can specify it in the configuration file,
and don't forget to specify the `--config` option.

### Register the runner with docker

If you are using the docker image, behaviour will be slightly different. Registration and running are combined into one step in this case, so you need to specify the registration information when running the act runner.

```bash
docker run \
-v $(pwd)/config.yaml:/config.yaml \
-v $(pwd)/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d gitea/act_runner:nightly
```

You may notice that we have mounted the `/var/run/docker.sock` into the container.
It is because the act runner will run jobs in docker containers, so it needs to communicate with the docker daemon.
As mentioned, you can remove it if you want to run jobs in the host directly.
To be clear, the "host" actually means the container which is running the act runner now, instead of the host machine.

### Labels

The labels of a runner are used to determine which jobs the runner can run, and how to run them.

The default labels are `ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`.
It is a comma-separated list, and each item is a label.

Let's take `ubuntu-22.04:docker://node:16-bullseye` as an example.
It means that the runner can run jobs with `runs-on: ubuntu-22.04`, and the job will be run in a docker container with the image `node:16-bullseye`.

If the default image is insufficient for your needs, and you have enough disk space to use a better and bigger one, you can change it to `ubuntu-22.04:docker://<the image you like>`.
You can find more useful images on [act images](https://github.com/nektos/act/blob/master/IMAGES.md).

If you want to run jobs in the host directly, you can change it to `ubuntu-22.04:host` or just `ubuntu-22.04`, the `:host` is optional.
However, we suggest you to use a special name like `linux_amd64:host` or `windows:host` to avoid misusing it.

One more thing is that it is recommended to register the runner if you want to change the labels.
It may be annoying to do this, so we may provide a better way to do it in the future.

## Running

After you have registered the runner, you can run it by running the following command:

```bash
./act_runner daemon
# or
./act_runner daemon --config config.yaml
```

The runner will fetch jobs from the Gitea instance and run them automatically.

Since act runner is still in development, it is recommended to check the latest version and upgrade it regularly.
171 changes: 171 additions & 0 deletions docs/content/doc/actions/comparison.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
date: "2023-04-27T15:00:00+08:00"
title: "Compared to GitHub Actions"
slug: "usage/actions/comparison"
weight: 30
draft: false
toc: false
menu:
sidebar:
parent: "actions"
name: "Comparison"
weight: 30
identifier: "actions-comparison"
---

# Compared to GitHub Actions

Even though Gitea Actions is designed to be compatible with GitHub Actions, there are some differences between them.

**Table of Contents**

{{< toc >}}

## Additional features

### Absolute action URLs

Gitea Actions supports defining actions via absolute URL, which means that you can use actions from any git repository.
Like `uses: https://github.com/actions/checkout@v3` or `uses: http://your_gitea.com/owner/repo@branch`.

### Actions written in Go

Gitea Actions supports writing actions in Go.
See [Creating Go Actions](https://blog.gitea.io/2023/04/creating-go-actions/).

## Unsupported workflows syntax

### `concurrency`

It's used to run a single job at a time.
See [Using concurrency](https://docs.github.com/en/actions/using-jobs/using-concurrency).

It's ignored by Gitea Actions now.

### `run-name`

The name for workflow runs generated from the workflow.
See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#run-name).

It's ignored by Gitea Actions now.

### `permissions` and `jobs.<job_id>.permissions`

See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions).

It's ignored by Gitea Actions now.

### `jobs.<job_id>.timeout-minutes`

See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes).

It's ignored by Gitea Actions now.

### `jobs.<job_id>.continue-on-error`

See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error).

It's ignored by Gitea Actions now.

### `jobs.<job_id>.environment`

See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idenvironment).

It's ignored by Gitea Actions now.

### Complex `runs-on`

See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on).

Gitea Actions only supports `runs-on: xyz` or `runs-on: [xyz]` now.

### `workflow_dispatch`

See [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatch).

It's ignored by Gitea Actions now.

### `hashFiles` expression

See [Expressions](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles)

Gitea Actions doesn't support it now, if you use it, the result will always be empty string.

As a workaround, you can use [go-hashfiles](https://gitea.com/actions/go-hashfiles) instead.

## Missing features

### Variables

See [Variables](https://docs.github.com/en/actions/learn-github-actions/variables).

It's under development.

### Problem Matchers

Problem Matchers are a way to scan the output of actions for a specified regex pattern and surface that information prominently in the UI.
See [Problem matchers](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md).

It's ignored by Gitea Actions now.

### Create an error annotation

See [Creating an annotation for an error](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-creating-an-annotation-for-an-error)

It's ignored by Gitea Actions now.

## Missing UI features

### Pre and Post steps

Pre and Post steps don't have their own section in the job log user interface.

## Different behavior

### Downloading actions

Gitea Actions doesn't download actions from GitHub by default.
"By default" means that you don't specify the host in the `uses` field, like `uses: actions/checkout@v3`.
As a contrast, `uses: https://github.com/actions/checkout@v3` has specified host.

The missing host will be filled with `https://gitea.com` if you don't configure it.
That means `uses: actions/checkout@v3` will download the action from [gitea.com/actions/checkout](https://gitea.com/actions/checkout), instead of [github.com/actions/checkout](https://github.com/actions/checkout).

As mentioned, it's configurable.
If you want your runners to download actions from GitHub or your own Gitea instance by default, you can configure it by setting `[actions].DEFAULT_ACTIONS_URL`. See [Configuration Cheat Sheet](({{ < relref "doc/administration/config-cheat-sheet.en-us.md#actions-actions" > }})).

### Context availability

Context availability is not checked, so you can use the env context on more places.
See [Context availability](https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability).

## Known issues

### `docker/build-push-action@v4`

See [act_runner#119](https://gitea.com/gitea/act_runner/issues/119#issuecomment-738294).

`ACTIONS_RUNTIME_TOKEN` is a random string in Gitea Actions, not a JWT.
But the `docker/build-push-action@v4` tries to parse the token as JWT and doesn't handle the error, so the job fails.

There are two workarounds:

Set the `ACTIONS_RUNTIME_TOKEN` to empty manually, like:

``` yml
- name: Build and push
uses: docker/build-push-action@v4
env:
ACTIONS_RUNTIME_TOKEN: ''
with:
...
```

The bug has been fixed in a newer [commit](https://gitea.com/docker/build-push-action/commit/d8823bfaed2a82c6f5d4799a2f8e86173c461aba?style=split&whitespace=show-all#diff-1af9a5bdf96ddff3a2f3427ed520b7005e9564ad), but it has not been released. So you could use the latest version by specifying the branch name, like:

``` yml
- name: Build and push
uses: docker/build-push-action@master
with:
...
```
Loading

0 comments on commit 8f314c6

Please sign in to comment.