LoginSignup
8
7

More than 1 year has passed since last update.

Gitea Actionsが来てるやんけ

Last updated at Posted at 2023-04-07

What is Gitea Actions

gitea版のGihub Actionsみたいなもんです。
CI, CDするやつです。

オンプレで社内gitつくろうとすると、gitlabかgiteaか、みたいな選択になると思います。
githubにソースコード置きたくない会社ってあるよね。

gitlabはすでにgitlab runnerがあって良いんですが、ちょっと重いんですよね〜。
設定を変えて再起動する度に結構待たされる。コーヒー飲む時間には良いけどサボってるように見えてしまう。

そういうわけで、僕はgiteaを使っていましたが、どうもCI, CDの連携が難しい。
droneとかいろいろ考えたけれど、結局、自作のwebhookデプロイになってました……。

公式Blog

詳しい内容はここを読むべし
https://blog.gitea.io/2023/03/hacking-on-gitea-actions/

どうすりゃ使えるんや

バージョンを1.19にする

docker-compose.yml
version: "3"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.19
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "222:22"

まあこんな感じですな。
適宜giteaの調整してください。
(個人的にはこれで立てたあとにconfのほうからいじるほうが好き)

configを変える

app.ini
[actions]
ENABLED=true

これを足してあげる!

runnerをビルドする

Currently, the only way to install act runner is by compiling it yourself, or by using one of the pre-built binaries.
現在のところ、act runnerをインストールする方法は、あなた自身でコンパイルを行うか、pre-built binariesを使用することによってのみ可能です。

ここからpre-built binariesをwgetとかしてくるのが簡単そうです。

僕はとりあえず自分でコンパイルしてみました。
コンパイル手順

  1. https://gitea.com/gitea/act_runner これをクローンする
  2. make build ※makeとgolangが要ります

runnerに渡すtokenを取得する

https://your_gitea_url/admin/runners
ここにアクセスしてtoken生成。
公式から画像取ってきたので参考に。
image.png

runnerにregisterする

./act_runner register

INFO Registering runner, arch=amd64, os=linux, version=0.1.0+2-g9c6499e.
WARN Runner in user-mode.
INFO Enter the Gitea instance URL (for example, https://gitea.com/):
→自分のgiteaのURL渡す。
https://your_gitea_url/

INFO Enter the runner token:
→さっき取得したtoken渡す

INFO Enter the runner name (if set empty, use hostname: xxx):
→名前つけられる。空だとhostnameになる

INFO Enter the runner labels, leave blank to use the default labels (comma-separated, for example, ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster,linux_arm:host):
actions起こすときのlabelをつけられる

こんな感じでregisterします。

注:https://git.example.co.jp/gitea/
みたいなサブディレクトリにした場合、runnerの登録は成功したが実際のactionsで失敗した。
しっかりサブドメインにするかportでやったほうが良いかも。

runnerのdaemonを起動する

./act_runner daemon

これでrunner起動完了です!

自分のレポジトリでactionsを有効化する

スクリーンショット 2023-04-07 22.05.49.png

歯車からいけます

actionsのyamlをディレクトリに作成する

該当リポジトリに.gitea/workflows/を作成します。

mkdir -p ./.gitea/workflows/
vi ./.gitea/workflows/demo.yaml
demo.yaml
name: Gitea Actions Demo
run-name: ${{ gitea.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 ${{ gitea.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 ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v3
      - run: echo "💡 The ${{ gitea.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 ${{ gitea.workspace }}          
      - run: echo "🍏 This job's status is ${{ gitea.status }}."

全部公式の例です。というか公式見ればいいけど最低限だけ抜き出したのがこの記事だ。
あとはpushしてみたら動くはずです。

注: actions/checkout@v3はgithubのものではなく、 デフォルトではgiteaのものが使われます。
https://gitea.com/actions/checkout
↑基本はこれが使われる

ただ、たとえばdenoでlintとかformatしたいときは、githubにあるdenoのactionsを使いたいわけです。
そういうときはこうします。

test.yaml
name: Deno CI
on: [push, pull_request]

jobs:
  test:
    name: Test app
    runs-on: ubuntu-latest

    steps:
      - name: Checkout gitea.repository
        uses: actions/checkout@v3

      - name: Setup Deno
        uses: https://github.com/denoland/setup-deno@v1
        with:
          deno-version: v1.x

      - name: Check format
        run: deno fmt --check

      - name: Check lint
        run: deno lint

      - name: Run tests
        run: deno test

usesのところにhttpsからちゃんとフルパスを渡してあげたらそれが使えます。

実際に動かしてみたらちゃんと動きました。
deno initして、.gitea/workflows/test.yamlに上記入れたら
ちゃんとdenoのCIが動くはずです。

設定で基本的にgithubのほうを見るように、とかもできるっぽいです。
[actions].DEFAULT_ACTIONS_URLらしい。

giteaのact runnerはhttps://github.com/nektos/actを元にしてるよ、とかいろいろ書いてますが
とりあえず上記やればgitea actionsを楽しめるはず。

基本的にはgithub actionsと同じことができそう。
通勤中に記事を見つけて、ざっと読んで会社でざっと作ってみて動きました。
いままでdroneとか使ってあーだこーだしてたときと比べたら超簡単で良し。
ほとんどはまるところなくいけました。
gitlabよりも軽くて使いやすそうで良し。

またいろいろ試してみますわな。

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7