1
0
wiki/Personal/Blog/2023/浅尝-Gitea-的-Actions.html

206 lines
476 KiB
HTML
Raw Normal View History

2024-09-03 21:23:28 +08:00
<!DOCTYPE html>
<html><head><title>浅尝 Gitea 的 Actions</title><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta property="og:title" content="浅尝 Gitea 的 Actions"/><meta property="og:description" content="浅尝 Gitea 的 Actions."/><meta property="og:image" content="https://wiki.7wate.com/static/og-image.png"/><meta property="og:width" content="1200"/><meta property="og:height" content="675"/><link rel="icon" href="../../../static/icon.png"/><meta name="description" content="浅尝 Gitea 的 Actions."/><meta name="generator" content="Quartz"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com"/><script async src="https://umami.7wate.com/script.js" data-website-id="c061efdc-95dd-4d21-9d04-a1ffda0a85b9"></script><script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?94d8ccb156eb7c65abf317e6e01cdba9";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script><script async src="https://www.googletagmanager.com/gtag/js?id=G-MHMEL0F832"></script><script>
(function() {
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-MHMEL0F832');
})();
</script><link href="../../../index.css" rel="stylesheet" type="text/css" spa-preserve/><link href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css" rel="stylesheet" type="text/css" spa-preserve/><link href="https://fonts.googleapis.com/css2?family=IBM Plex Mono&amp;family=Schibsted Grotesk:wght@400;700&amp;family=Source Sans Pro:ital,wght@0,400;0,600;1,400;1,600&amp;display=swap" rel="stylesheet" type="text/css" spa-preserve/><script src="../../../prescript.js" type="application/javascript" spa-preserve></script><script type="application/javascript" spa-preserve>const fetchData = fetch(`../../../static/contentIndex.json`).then(data => data.json())</script></head><body data-slug="Personal/Blog/2023/浅尝-Gitea-的-Actions"><div id="quartz-root" class="page"><div id="quartz-body"><div class="left sidebar"><h1 class="page-title "><a href="../../..">📚 X·Eden</a></h1><div class="spacer mobile-only"></div><div class="search "><div id="search-icon"><p>Search</p><div></div><svg tabIndex="0" aria-labelledby="title desc" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7"><title id="title">Search</title><desc id="desc">Search</desc><g class="search-path" fill="none"><path stroke-linecap="square" d="M18.5 18.3l-5.4-5.4"></path><circle cx="8" cy="8" r="7"></circle></g></svg></div><div id="search-container"><div id="search-space"><input autocomplete="off" id="search-bar" name="search" type="text" aria-label="Search for something" placeholder="Search for something"/><div id="results-container"></div></div></div></div><div class="darkmode "><input class="toggle" id="darkmode-toggle" type="checkbox" tabIndex="-1"/><label id="toggle-label-light" for="darkmode-toggle" tabIndex="-1"><svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1" id="dayIcon" x="0px" y="0px" viewBox="0 0 35 35" style="enable-background:new 0 0 35 35;" xmlSpace="preserve"><title>Light mode</title><path d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z"></path></svg></label><label id="toggle-label-dark" for="darkmode-toggle" tabIndex="-1"><svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1" id="nightIcon" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background='new 0 0 100 100'" xmlSpace="preserve"><title>Dark mode</title><path d="M96.76,66.458c-0.853-0.852-2.15-1.064-3.23-0.534c-6.063,2.991-12.858,4.571-19.655,4.571 C62.022,70.495,50.88,65.88,42.5,57.5C29.043,44.043,25.658,23.536,34.076,6.47c0.532-1.08,0.318-2.379-0.534-3.23 c-0.851-0.852-2.15-1.064-3.23-0.534c-4.918,2.427-9.375,5.619-13.246,9.491c-9.447,9.447-14.65,22.008-14.65,35.369 c0,13.36,5.2
<p>Gitea 是一个轻量级的 DevOps 平台软件。从开发计划到产品成型的整个软件生命周期,它都能够高效而轻松地帮助团队和开发者,实现包括 Git 托管、代码审查、团队协作、软件包注册和 CI/CD 等功能。它与 GitHub、Bitbucket 和 GitLab 等 <a href="https://docs.gitea.com/zh-cn/installation/comparison" class="external">比较</a> 类似。</p>
<p>Gitea 的主要目标是创建一个<strong>极易安装,运行非常快速,安装和使用体验良好的自建 Git 服务</strong>。通常我把 Gitea 称为 GitHub 的青春版,但一直以来它缺少 CI/CD 功能,因此一直只被用作代码托管的中转站。</p>
<p>Gitea 最初是从 <a href="http://gogs.io/" class="external">Gogs</a> 分支而来,有关分支原因的详细信息可以在 <a href="https://blog.gitea.com/welcome-to-gitea/" class="external">这里</a> 找到。然而,自从 Gogs 分叉后Gitea 的社区壮大,但对内置 CI/CD 的需求也在不断增加。终于在 2020 年 11 月 13 日,南开大学软件学院的毕业生肖伦文( <em>Lunny</em> )提出了 <a href="https://github.com/go-gitea/gitea/issues/13539" class="external">#13539</a> 提案:</p>
<blockquote>
<p><em>An internal CI/CD system compatible with Github actions workflow yaml syntax, action yaml syntax and most action plugins.</em></p>
</blockquote>
<p>经过社区长达两年的不懈努力,从 Gitea 1.19 版本开始Gitea Actions 已经成为内置的 CI/CD 解决方案(需要手动启用)。然后又经过两个版本的迭代,从 1.21.0 版本开始,默认情况下启用了 Actions。总体而言Gitea Actions 与 <a href="https://github.com/features/actions" class="external">GitHub Actions</a> 相似且兼容,它的名称也受到了 GitHub Actions 的启发,可以简单地将 Gitea Actions 视为 GitHub Actions 的子集。尽管 Gitea Actions 旨在与 GitHub Actions 兼容,但它们之间仍存在一些 <a href="https://docs.gitea.com/zh-cn/usage/actions/comparison" class="external">差异</a></p>
<p>与其他 CI/CD 解决方案一样Gitea 不会自行运行 Job而是将 Job 委托给 Runner。Gitea Actions 的 Runner 被称为 act runner它是一个独立的程序使用 Go 语言编写。它是基于 nektos/act 的一个软分叉,而 <code>nektos/act</code> 是一个开源工具,用于在本地模拟 GitHub Actions 工作流程。</p>
<p>如果您非常熟悉 GitHub Actions几乎可以无缝迁移到 Gitea Actions。我想分享这篇文章主要是因为互联网上相关经验贴子较少同时分享一些我的心得体会。</p>
<h2 id="基本概念">基本概念<a aria-hidden="true" tabindex="-1" href="#基本概念" class="internal"> §</a></h2>
<ul>
<li><strong>工作流Workflows</strong>:在两者中,工作流是自动化过程的定义,描述了一系列任务(如构建、测试和部署应用)的执行方式。</li>
<li><strong>事件Events</strong>:工作流可以由各种事件触发,如代码推送、拉取请求、定时事件等。</li>
<li><strong>作业Jobs</strong>:作业是工作流中运行的一系列步骤。作业可以并行运行或按顺序运行。</li>
<li><strong>步骤Steps</strong>步骤是作业中的单个任务可以执行脚本命令或者使用特定的动作actions</li>
<li><strong>动作Actions</strong>:动作是在步骤中执行的独立任务,可以是内置的、来自市场的,或者是自定义的。</li>
<li><strong>变量与密钥Variables &amp; Secrets</strong>:可以设置环境变量来管理配置和共享数据。</li>
<li><strong>缓存Caching</strong>:缓存依赖项和其他常用资源可以帮助加快构建和部署过程。</li>
<li><strong>日志与监控Logging &amp; Monitoring</strong>:可以提供详细的执行日志,帮助监控和调试工作流。</li>
</ul>
<h2 id="环境配置">环境配置<a aria-hidden="true" tabindex="-1" href="#环境配置" class="internal"> §</a></h2>
<ul>
<li>
<p><a href="https://docs.gitea.com/zh-cn/category/installation" class="external">Gitea 安装</a></p>
</li>
<li>
<p><a href="https://docs.gitea.com/zh-cn/usage/actions/act-runner" class="external">Gitea Actions 的 Runner 部署</a></p>
</li>
</ul>
<p><em>由于 Gitea 提供了非常丰富的文档,所以我就不一一赘述了 ~</em></p>
<p>在实际体验中,将 Gitea 和 Act Runner 部署在一台 1 核心 2GB 的云服务器也是可以的。Act Runner 的日常运行仅占用约 30MB 左右的内存。不过每个 Runner 的具体资源消耗取决于仓库中的工作流脚本。</p>
<p>此外,您还可以将 Gitea 部署在公网服务器上,将 Act Runner 部署在本地服务器上。即使是一台二手服务器,只要满足以下网络架构要求,都可以使用。</p>
<h3 id="网络架构">网络架构<a aria-hidden="true" tabindex="-1" href="#网络架构" class="internal"> §</a></h3>
<pre><code class="mermaid">graph LR
subgraph internet[Internet]
github_com[github.com]
docker_hub_com[hub.docker.com]
other
end
subgraph server1[Server 1]
gitea[Gitea]
end
subgraph server2[Server 2]
act_runner[Act runner]
job_container[Job container 1&lt;br>Job container 2&lt;br>...]
end
act_runner -->|1| gitea
job_container -->|2| gitea
act_runner -->|3| internet
job_container -->|4| internet
</code></pre>
<p>使用 Gitea Actions 只需要确保 Runner 能够连接到 Gitea 实例。<strong>互联网访问是可选的</strong>,但如果没有互联网访问,将需要额外的工作。换句话说,当 Runner 能够自行查询互联网时,它的工作效果最好,但您不需要将其暴露给互联网(无论是单向还是双向)。</p>
<h2 id="工作流脚本">工作流脚本<a aria-hidden="true" tabindex="-1" href="#工作流脚本" class="internal"> §</a></h2>
<h3 id="要求">要求<a aria-hidden="true" tabindex="-1" href="#要求" class="internal"> §</a></h3>
<ul>
<li>默认情况下Gitea 需要手动启用 Actions也可以 <a href="https://docs.gitea.com/zh-cn/usage/actions/faq#%E4%B8%BA%E4%BB%80%E4%B9%88%E9%BB%98%E8%AE%A4%E6%83%85%E5%86%B5%E4%B8%8B%E4%B8%8D%E5%90%AF%E7%94%A8actions" class="external">手动配置默认启用</a> Actions 单元以适用于所有新仓库。</li>
<li>Gitea Actions 需要一个以 <code>.yaml</code> 扩展名的文件,放在存储库的 <code>.gitea/workflows/</code> 目录中,例如 <code>.gitea/workflows/demo.yaml</code></li>
</ul>
<h3 id="示例">示例<a aria-hidden="true" tabindex="-1" href="#示例" class="internal"> §</a></h3>
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="yaml" data-theme="default"><code data-language="yaml" data-theme="default"><span data-line><span style="color:var(--shiki-token-keyword);">name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">Gitea Actions Demo</span></span>
<span data-line><span style="color:var(--shiki-token-keyword);">run-name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">${{ gitea.actor }} is testing out Gitea Actions 🚀</span></span>
<span data-line><span style="color:var(--shiki-token-constant);">on</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> [</span><span style="color:var(--shiki-token-string);">push</span><span style="color:var(--shiki-color-text);">]</span></span>
<span data-line> </span>
<span data-line><span style="color:var(--shiki-token-keyword);">jobs</span><span style="color:var(--shiki-token-keyword);">:</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">Explore-Gitea-Actions</span><span style="color:var(--shiki-token-keyword);">:</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">runs-on</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">ubuntu-latest</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">steps</span><span style="color:var(--shiki-token-keyword);">:</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">echo &quot;🎉 The job was automatically triggered by a ${{ gitea.event_name }} event.&quot;</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">echo &quot;🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!&quot;</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">echo &quot;🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}.&quot;</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">Check out repository code</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">uses</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">actions/checkout@v3</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">echo &quot;💡 The ${{ gitea.repository }} repository has been cloned to the runner.&quot;</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">echo &quot;🖥️ The workflow is now ready to test your code on the runner.&quot;</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">List files in the repository</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">|</span></span>
<span data-line><span style="color:var(--shiki-token-string);"> ls ${{ gitea.workspace }}</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> - </span><span style="color:var(--shiki-token-keyword);">run</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">echo &quot;🍏 This job's status is ${{ job.status }}.&quot;</span></span></code></pre></div>
<h3 id="语法">语法<a aria-hidden="true" tabindex="-1" href="#语法" class="internal"> §</a></h3>
<p>目前 Gitea 官方尚未提供 Actions 语法的标准文档,但官方建议直接参考 <a href="https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions" class="external">GitHub Actions 工作流语法</a></p>
<h3 id="变量">变量<a aria-hidden="true" tabindex="-1" href="#变量" class="internal"> §</a></h3>
<p><strong>目前 Gitea 支持在用户、组织和仓库级别创建变量,变量的可见性级别取决于它们的创建位置。</strong></p>
<ul>
<li>用户级别:适用于用户所有仓库的 Actions。</li>
<li>组织级别:适用于组织内所有用户仓库的 Actions。</li>
<li>仓库级别:适用于仓库内所有 Actions。</li>
</ul>
<p>变量名称有特定的命名规则,例如只能包含字母、数字字符和下划线,不能以数字开头,不能以 <code>GITHUB_</code><code>GITEA_</code> 开头,并且必须是唯一的。创建后,变量会自动填充到 <code>vars</code><code>secrets</code> 上下文中,并可在工作流中使用。</p>
<p>变量的语法为 <code>${{ vars.xxx }}</code><code>${{ secrets.xxx }}</code></p>
<h2 id="进阶功能">进阶功能<a aria-hidden="true" tabindex="-1" href="#进阶功能" class="internal"> §</a></h2>
<h3 id="指定-act-运行-runner">指定 Act 运行 Runner<a aria-hidden="true" tabindex="-1" href="#指定-act-运行-runner" class="internal"> §</a></h3>
<p>如果你有多个 Act 节点,希望将某个工作流程运行在特定的 Runner 上,你可以在不同的 Runner 上分配不同的标签(可在 Runner 管理面板编辑标签),例如,你可以创建两个 Runner分别标记为 <code>linux_runner</code><code>windows_runner</code></p>
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="yaml" data-theme="default"><code data-language="yaml" data-theme="default"><span data-line><span style="color:var(--shiki-token-keyword);">jobs</span><span style="color:var(--shiki-token-keyword);">:</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">My-Gitea-Actions</span><span style="color:var(--shiki-token-keyword);">:</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">runs-on</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">linux_runner</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">runs-on</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">windows_runner</span></span></code></pre></div>
<h3 id="复用-github-的脚本">复用 Github 的脚本<a aria-hidden="true" tabindex="-1" href="#复用-github-的脚本" class="internal"> §</a></h3>
<p>在编写步骤配置时,通常会引用其他人编写的脚本,例如:</p>
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="yaml" data-theme="default"><code data-language="yaml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);">- </span><span style="color:var(--shiki-token-keyword);">name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">Login to DockerHub</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">uses</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">docker/login-action@v2</span></span>
<span data-line> </span>
<span data-line><span style="color:var(--shiki-color-text);">- </span><span style="color:var(--shiki-token-keyword);">name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">Login to DockerHub</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">uses</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">my_custom/other-action@v2</span></span></code></pre></div>
<p>然而,对于 Gitea Actions默认情况下在 <code>1.19</code> 之前,它会尝试访问 <a href="https://gitea.com/" class="external">Gitea.com</a> 这个代码托管仓库,因此,如果脚本位于 GitHub 上,它将无法下载脚本内容。而在 <code>1.20</code> 及以后版本中,默认会访问 <a href="https://github.com/" class="external">GitHub.com</a></p>
<p>因此,如果在下载脚本时遇到问题,建议明确指定脚本地址,例如:</p>
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="yaml" data-theme="default"><code data-language="yaml" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);">- </span><span style="color:var(--shiki-token-keyword);">name</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">Login to DockerHub</span></span>
<span data-line><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">uses</span><span style="color:var(--shiki-token-keyword);">:</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-string-expression);">https://github.com/my_custom/other-action@v2</span></span></code></pre></div>
<p>或者通过修改 Gitea 的 <code>app.ini</code> 配置,将下载源指定为相应的仓库:</p>
<div data-rehype-pretty-code-fragment><pre style="background-color:var(--shiki-color-background);" tabindex="0" data-language="ini" data-theme="default"><code data-language="ini" data-theme="default"><span data-line><span style="color:var(--shiki-color-text);">[actions]</span></span>
<span data-line><span style="color:var(--shiki-token-comment);"># 1.19 可直接填写任意url如https://github.com</span></span>
<span data-line><span style="color:var(--shiki-token-comment);"># 1.20起,不填默认从 github填self表示从自建仓库下载</span></span>
<span data-line><span style="color:var(--shiki-token-keyword);">DEFAULT_ACTIONS_URL</span><span style="color:var(--shiki-color-text);"> </span><span style="color:var(--shiki-token-keyword);">=</span><span style="color:var(--shiki-color-text);"> self</span></span></code></pre></div>
<h3 id="使用-docker-等工具">使用 Docker 等工具<a aria-hidden="true" tabindex="-1" href="#使用-docker-等工具" class="internal"> §</a></h3>
<p>在 GitHub Actions 中,默认工作环境可以直接使用 Docker 命令,但在 Gitea Actions 中无法运行,因为 <code>gitea act_runner</code> 默认运行在 <code>node:16-bullseye</code> 镜像上,不支持 Docker 命令。这个问题在 <a href="https://gitea.com/gitea/act_runner/issues/63#issuecomment-733637" class="external">Gitea act_runner issue</a> 中有详细讨论。</p>
<p>因为 Act Runner 可以部署在本地服务器上,因此最简单有效的解决方法是通过 SSH 直接操作本地主机。</p>
<h2 id="心得体会">心得体会<a aria-hidden="true" tabindex="-1" href="#心得体会" class="internal"> §</a></h2>
<p>DevOps 平台软件繁多,但轻量级的 DevOps 平台软件却寥寥无几。虽然 GitHub 也支持自托管的 Runner但它的可访问性受限。GitLab 则过于重量级。</p>
<p>目前 Gitea 官方社区表示 Gitea Actions 仍然在开发中,因此可能存在一些错误和缺失的功能。 并且在稳定版本v1.20 或更高版本)之前可能会进行一些重大的更改。</p>
<p>总而言之Gitea 的 Actions 为开发者提供了一种实用的解决方案,特别适用于日常使用场景。值得一试!</p>
<p>本文借鉴了 seepine 博主在 Gitea 系列文章中的部分内容不过请注意seepine 博主的文章撰写于 2023 年 3 月份,主要现在 Gitea 已经更新了。</p>
<ul>
<li><a href="https://seepine.com/git/gitea/starter/" class="external">Gitea - 搭建属于自己的代码仓库</a></li>
<li><a href="https://seepine.com/git/gitea/actions/" class="external">Gitea Actions 搭建</a></li>
<li><a href="https://seepine.com/git/gitea/actions/springboot/" class="external">Gitea Actions 构建 SpringBoot Docker镜像</a></li>
<li><a href="https://seepine.com/git/gitea/actions/quarkus/" class="external">Gitea Actions 构建 Quarkus native Docker镜像</a></li>
<li><a href="https://seepine.com/git/gitea/actions/vue/" class="external">Gitea Actions 构建 Vue Docker 镜像</a></li>
</ul></article></div><div class="right sidebar"><div class="graph "><h3>Graph View</h3><div class="graph-outer"><div id="graph-container" data-cfg="{&quot;drag&quot;:true,&quot;zoom&quot;:true,&quot;depth&quot;:1,&quot;scale&quot;:1.1,&quot;repelForce&quot;:0.5,&quot;centerForce&quot;:0.3,&quot;linkDistance&quot;:30,&quot;fontSize&quot;:0.6,&quot;opacityScale&quot;:1,&quot;showTags&quot;:true,&quot;removeTags&quot;:[]}"></div><svg version="1.1" id="global-graph-icon" xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 55 55" fill="currentColor" xmlSpace="preserve"><path d="M49,0c-3.309,0-6,2.691-6,6c0,1.035,0.263,2.009,0.726,2.86l-9.829,9.829C32.542,17.634,30.846,17,29,17
s-3.542,0.634-4.898,1.688l-7.669-7.669C16.785,10.424,17,9.74,17,9c0-2.206-1.794-4-4-4S9,6.794,9,9s1.794,4,4,4
c0.74,0,1.424-0.215,2.019-0.567l7.669,7.669C21.634,21.458,21,23.154,21,25s0.634,3.542,1.688,4.897L10.024,42.562
C8.958,41.595,7.549,41,6,41c-3.309,0-6,2.691-6,6s2.691,6,6,6s6-2.691,6-6c0-1.035-0.263-2.009-0.726-2.86l12.829-12.829
c1.106,0.86,2.44,1.436,3.898,1.619v10.16c-2.833,0.478-5,2.942-5,5.91c0,3.309,2.691,6,6,6s6-2.691,6-6c0-2.967-2.167-5.431-5-5.91
v-10.16c1.458-0.183,2.792-0.759,3.898-1.619l7.669,7.669C41.215,39.576,41,40.26,41,41c0,2.206,1.794,4,4,4s4-1.794,4-4
s-1.794-4-4-4c-0.74,0-1.424,0.215-2.019,0.567l-7.669-7.669C36.366,28.542,37,26.846,37,25s-0.634-3.542-1.688-4.897l9.665-9.665
C46.042,11.405,47.451,12,49,12c3.309,0,6-2.691,6-6S52.309,0,49,0z M11,9c0-1.103,0.897-2,2-2s2,0.897,2,2s-0.897,2-2,2
S11,10.103,11,9z M6,51c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S8.206,51,6,51z M33,49c0,2.206-1.794,4-4,4s-4-1.794-4-4
s1.794-4,4-4S33,46.794,33,49z M29,31c-3.309,0-6-2.691-6-6s2.691-6,6-6s6,2.691,6,6S32.309,31,29,31z M47,41c0,1.103-0.897,2-2,2
s-2-0.897-2-2s0.897-2,2-2S47,39.897,47,41z M49,10c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S51.206,10,49,10z"></path></svg></div><div id="global-graph-outer"><div id="global-graph-container" data-cfg="{&quot;drag&quot;:true,&quot;zoom&quot;:true,&quot;depth&quot;:-1,&quot;scale&quot;:0.9,&quot;repelForce&quot;:0.5,&quot;centerForce&quot;:0.3,&quot;linkDistance&quot;:30,&quot;fontSize&quot;:0.6,&quot;opacityScale&quot;:1,&quot;showTags&quot;:true,&quot;removeTags&quot;:[]}"></div></div></div><div class="toc desktop-only"><button type="button" id="toc" class><h3>Table of Contents</h3><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="fold"><polyline points="6 9 12 15 18 9"></polyline></svg></button><div id="toc-content"><ul class="overflow"><li class="depth-0"><a href="#前言" data-for="前言">前言</a></li><li class="depth-0"><a href="#基本概念" data-for="基本概念">基本概念</a></li><li class="depth-0"><a href="#环境配置" data-for="环境配置">环境配置</a></li><li class="depth-1"><a href="#网络架构" data-for="网络架构">网络架构</a></li><li class="depth-0"><a href="#工作流脚本" data-for="工作流脚本">工作流脚本</a></li><li class="depth-1"><a href="#要求" data-for="要求">要求</a></li><li class="depth-1"><a href="#示例" data-for="示例">示例</a></li><li class="depth-1"><a href="#语法" data-for="语法">语法</a></li><li class="depth-1"><a href="#变量" data-for="变量">变量</a></li><li class="depth-0"><a href="#进阶功能" data-for="进阶功能">进阶功能</a></li><li class="depth-1"><a href="#指定-act-运行-runner" data-for="指定-act-运行-runner">指定 Act 运行 Runner</a></li><li class="depth-1"><a href="#复用-github-的脚本" data-for="复用-github-的脚本">复用 Github 的脚本</a></li><li class="depth-1"><a href="#使用-docker-等工具" data-for="使用-docker-等工具">使用 Docker 等工具</a></li><li class="depth-0"><a href="#心得体会" data-for="心得体会">心得体会</a></li></ul></div></div><div class="backlinks "><h3>Backlinks</h3><ul class="overflow"><li>No backlinks found</li></ul></div><div class="explorer mobile-only"><button type="button" id="explorer" data-behavior="collapse" data-collapsed="collapsed" data-savestate="true" data-tree="[{&quot;path&quot;:&quot;Journal&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Journal/2024&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Journal/2024/W33&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Obsidian&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Obsidian/Templates&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2018&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2020&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2021&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2022&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2023&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2024&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/个人成长&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/医学健康&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/历史&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/哲学宗教&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/心理&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/政治军事&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/教育学习&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/文学&quot;,&
function toggleCallout() {
const outerBlock = this.parentElement;
outerBlock.classList.toggle(`is-collapsed`);
const collapsed = outerBlock.classList.contains(`is-collapsed`);
const height = collapsed ? this.scrollHeight : outerBlock.scrollHeight;
outerBlock.style.maxHeight = height + `px`;
let current = outerBlock;
let parent = outerBlock.parentElement;
while (parent) {
if (!parent.classList.contains(`callout`)) {
return;
}
const collapsed2 = parent.classList.contains(`is-collapsed`);
const height2 = collapsed2 ? parent.scrollHeight : parent.scrollHeight + current.scrollHeight;
parent.style.maxHeight = height2 + `px`;
current = parent;
parent = parent.parentElement;
}
}
function setupCallout() {
const collapsible = document.getElementsByClassName(
`callout is-collapsible`
);
for (const div of collapsible) {
const title = div.firstElementChild;
if (title) {
title.removeEventListener(`click`, toggleCallout);
title.addEventListener(`click`, toggleCallout);
const collapsed = div.classList.contains(`is-collapsed`);
const height = collapsed ? title.scrollHeight : div.scrollHeight;
div.style.maxHeight = height + `px`;
}
}
}
document.addEventListener(`nav`, setupCallout);
window.addEventListener(`resize`, setupCallout);
</script><script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
mermaid.initialize({
startOnLoad: false,
securityLevel: 'loose',
theme: darkMode ? 'dark' : 'default'
});
document.addEventListener('nav', async () => {
await mermaid.run({
querySelector: '.mermaid'
})
});
</script><script src="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/contrib/copy-tex.min.js" type="application/javascript"></script><script src="../../../postscript.js" type="module"></script></html>