前言
一般來說,使用 Github Actions 都需要在 Repo 里完成相應(yīng)的 event 才能夠觸發(fā)(比如push/pull_request等),然后在 Github 提供的服務(wù)器(容器)中運(yùn)行。這樣有兩個(gè)缺點(diǎn):
每次都需要在 Repo 完成相應(yīng)的 evenet,操作較為費(fèi)時(shí)。
一個(gè) event 可能會(huì)觸發(fā)多個(gè) Action,并且在 Github 的服務(wù)器上運(yùn)行時(shí)需要排隊(duì),運(yùn)行較為耗時(shí)。
所以,本文介紹如何在本地運(yùn)行 Github Actions 來解決上述兩個(gè)問題,主要有以下兩個(gè)依賴:
Docker Desktop on Windows(Backend 是 WSL)
act
依賴安裝
Docker Desktop on Windows
安裝 Docker Desktop on Windows 前需要先安裝 WSL,安裝 WSL 的操作可以參考官方文檔
安裝 Docker Desktop on Windows,
進(jìn)入 Docker Desktop on Windows 時(shí)可能會(huì)一直停留在 starting the docker engine 界面,可以考慮以下解決方法:
重啟 Docker 服務(wù)
net stop com.docker.service
net start com.docker.service
先點(diǎn)擊右上角登錄 Docker 賬號(hào)
act
act 是在本地運(yùn)行 Github Actions 的工具,它依賴于 Docker。安裝可以參考 nektos/act: Run your GitHub Actions locally ,或者直接在這個(gè)倉(cāng)庫(kù)的 release 當(dāng)中下載,只有一個(gè) Windows 可執(zhí)行文件(exe)。
本地運(yùn)行 Github Actions
act 使用說明
Command structure:
act [] [options]
If no event name passed, will default to "on: push"
If actions handles only one event it will be used as default instead of "on: push"
List all actions for all events:
act -l
List the actions for a specific event:
act workflow_dispatch -l
List the actions for a specific job:
act -j test -l
Run the default (push
) event:
act
Run a specific event:
act pull_request
Run a specific job:
act -j test
Collect artifacts to the /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts
Run a job in a specific workflow (useful if you have duplicate job names)
act -j lint -W .github/workflows/checks.yml
Run in dry-run mode:
act -n
Enable verbose-logging (can be used with any of the above commands)
act -v
示例:RT-Thread 的 Github Actions
進(jìn)入 RT-Thread 源代碼目錄(只要進(jìn)入第一層即可,act 會(huì)自動(dòng)搜索 .github/workflow 目錄)
使用act -l?查看當(dāng)前目錄下的 Action
可以看到有重名(Job ID)的 Action,所以需要指定要運(yùn)行的 Action(act -j test -W ..githubworkflowsaction_tools.yml?)
如果運(yùn)行時(shí)拉不下鏡像可以修改一下 daemon.json 中的鏡像源
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
運(yùn)行結(jié)果如下:
-
觸發(fā)器
+關(guān)注
關(guān)注
14文章
2039瀏覽量
62145 -
RT-Thread
+關(guān)注
關(guān)注
32文章
1409瀏覽量
41958
發(fā)布評(píng)論請(qǐng)先 登錄
Github發(fā)布史上最大更新
【觸覺智能 Purple Pi開發(fā)板試用】 GitHub Actions 在線編譯 uboot by jf_84491108
【觸覺智能 Purple Pi開發(fā)板試用】 GitHub Actions 在線編譯 Buildroot by jf_84491108
【觸覺智能 Purple Pi開發(fā)板試用】 GitHub Actions 在線編譯 qmsd by jf_84491108
【觸覺智能 Purple Pi開發(fā)板試用】 GitHub Actions 在線編譯 OpenWrt 失敗 by jf_84491108
嘗試使用GitHub Actions在線編譯瑞薩RZ/G2UL Instructions images
本地測(cè)試環(huán)境搭建

GitHub宣布開放無限私有存儲(chǔ)庫(kù)以及限時(shí)訪問GitHub Actions
上傳本地項(xiàng)目代碼到github

RT-Thread中的Github Actions

評(píng)論