全球最实用的IT互联网信息网站!

AI人工智能P2P分享&下载搜索网页发布信息网站地图

当前位置:诺佳网 > 电子/半导体 > 嵌入式技术 >

如何本地运行和测试Github Actions?

时间:2023-08-02 16:44

人气:

作者:admin

标签: 测试  本地  如何  运行   

导读:一般来说,使用 Github Actions 都需要在 Repo 里完成相应的 event 才能够触发(比如push/pull_request等),然后在 Github 提供的服务器(容器)中运行。...

前言
一般来说,使用 Github Actions 都需要在 Repo 里完成相应的 event 才能够触发(比如push/pull_request等),然后在 Github 提供的服务器(容器)中运行。这样有两个缺点:

每次都需要在 Repo 完成相应的 evenet,操作较为费时。
一个 event 可能会触发多个 Action,并且在 Github 的服务器上运行时需要排队,运行较为耗时。
所以,本文介绍如何在本地运行 Github Actions 来解决上述两个问题,主要有以下两个依赖:

Docker Desktop on Windows(Backend 是 WSL)
act

依赖安装

Docker Desktop on Windows

安装 Docker Desktop on Windows 前需要先安装 WSL,安装 WSL 的操作可以参考官方文档

安装 Docker Desktop on Windows,

进入 Docker Desktop on Windows 时可能会一直停留在 starting the docker engine 界面,可以考虑以下解决方法:

重启 Docker 服务
net stop com.docker.service

net start com.docker.service

先点击右上角登录 Docker 账号
act
act 是在本地运行 Github Actions 的工具,它依赖于 Docker。安装可以参考 nektos/act: Run your GitHub Actions locally ,或者直接在这个仓库的 release 当中下载,只有一个 Windows 可执行文件(exe)。

本地运行 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
进入 RT-Thread 源代码目录(只要进入第一层即可,act 会自动搜索 .github/workflow 目录)
使用act -l​查看当前目录下的 Action

1.jpg

可以看到有重名(Job ID)的 Action,所以需要指定要运行的 Action(act -j test -W ..githubworkflowsaction_tools.yml​)
如果运行时拉不下镜像可以修改一下 daemon.json 中的镜像源

"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]

运行结果如下:

1.jpg

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信