TL; DR:并行运行作业 a、b。如果 a 失败,则停止仍在运行的 b 的执行。
我的公司使用 GitHub Actions 来部署我们的代码。
我们部署的第一步是构建 docker 并将它们推送到 DockerHub。
我们为代码编写了一个测试,希望与构建 Docker 并行运行。
这两项都是独立的工作,根据前两项的成功,我们还有更多的工作。
现在,如果测试作业失败,另一个作业会继续运行,但显然下一个作业不会运行,因为测试作业失败了。
我想做的是,如果测试失败,则在运行时取消 docker 构建作业。
那可能吗?在搜索了网络、StackOverflow 和 GitHub Actions 页面后,我还没有找到一种方法来做到这一点。
谢谢!
我目前正在此存储库上测试 GitHub Actions 工作流程。我正在尝试使用这个工作流程:
on:
workflow_dispatch:
jobs:
job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
date > report.txt
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "generate or update report.txt file"
git push
Run Code Online (Sandbox Code Playgroud)
触发此工作流程:
on:
push:
paths:
- '**/report.txt'
pull_request:
paths:
- '**/report.txt'
jobs:
job:
runs-on: ubuntu-latest
steps:
- run: echo "Report .txt file has been updated"
Run Code Online (Sandbox Code Playgroud)
我按照GitHub Actions 文档使用过滤器模式实现了第二个工作流程。
当我report.txt在本地更新文件,然后提交代码并将其推送到存储库时,第二个工作流程将触发。 …
on:
workflow_dispatch:
inputs:
test_password:
description: 'test_password'
required: true
env:
TEST_PASSWORD: ${{ github.event.inputs.test_password }}
Run Code Online (Sandbox Code Playgroud)
问题是它TEST_PASSWORD在日志中打印输入。有没有一种方法可以加密/屏蔽它,类似于${{ secrets.test_password }}?
此解决方法似乎不再有效。
我有一个托管在 GitHub 组织中的私有 GitHub 存储库。\n该存储库包含带有选项的 GitHub 操作workflow_dispatch\n(参见GitHub 文档)。
操作 YAML 文件摘录:
\non:\n # Allows you to run this workflow manually from the Actions tab\n workflow_dispatch:\n\njobs:\n build:\n runs-on: ubuntu-latest\nRun Code Online (Sandbox Code Playgroud)\n我可以从 GitHub Actions 选项卡成功触发此操作。
\n不过,我希望能够通过POST对 GitHub API 的请求来触发此操作。\n这应该可以使用 GitHub API 实现。\n相关的 API 端点似乎如\n文档/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches中所述。
该文件进一步指出:
\n\n\n您必须使用具有存储库范围的访问令牌进行身份验证才能使用此端点。
\n
因此,在我的个人帐户设置中的“开发人员设置”\xe2\x86\x92“个人访问令牌”下,\n我创建了一个令牌并授予对所有“存储库”项以及“工作流”项的访问权限。
\n我已测试通过使用PostmanPOST发出请求来触发 GitHub Action 。\n为此,我根据\n GitHub 文档使用以下参数:curl
accept:(application/vnd.github.v3+json根据 …我正在尝试将存储库从 GitHub 克隆到远程服务器。
我使用appleboy/ssh-action GitHub 操作的解决方案有效,但我被告知使用actions/checkout@v2 GitHub 操作也可以实现相同的效果。我尝试将- use: value 更改为actions/checkout@V2 ` 但代码不起作用。
我找不到任何有关如何使用actions/checkout@v2进行操作的模板。任何建议将不胜感激。
name: deploy to a server on push
on:
push:
branches: [ master ]
jobs:
deploy-to-server:
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action@master
with:
host: 123.132.123.132
username: tomas
key: ${{ secrets.PRIVATE_KEY }}
port: 59666
script:
git clone https://github.com/Tomas-R/website.git
Run Code Online (Sandbox Code Playgroud) 我有一个简单的工作流程:
name: Test CI
env:
path_to_watch_for_commits: 'testdir/testfile'
on:
push:
branches:
- master
paths:
- ${{ env.path_to_watch_for_commits }}
workflow_dispatch:
jobs:
build:
runs-on: ubuntu
steps:
- uses: actions/checkout@v2
Run Code Online (Sandbox Code Playgroud)
我想path_to_watch_for_commits在路径中使用变量。但这个语法是错误的。我也尝试过${{ path_to_watch_for_commits }}但$path_to_watch_for_commits没有结果。我究竟做错了什么?
on:
push
concurrency:
# Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers.
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
...
Run Code Online (Sandbox Code Playgroud)
这会为每个分支创建一个单独的组,并在稍后推送/强制推送到分支时取消构建。可悲的是,这也取消了master构建,这是我不想要的。所有提交都master应该完成运行,因此很容易看到何时出现问题。
我本质上是在寻找一种方式来表达:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
if: github.ref != 'refs/heads/master'
Run Code Online (Sandbox Code Playgroud) 我正在使用 Github Actions 构建我的项目,并通过以下工作流程部分将工件上传到 Github:
- uses: actions/upload-artifact@v2
with:
name: some-file
path: some-path
Run Code Online (Sandbox Code Playgroud)
问题是工件非常大并且很快就会消耗可用的存储配额。而且我什至不需要所有这些,只需要每个分支上最新版本的那些。
设置保留期并不是一个解决方案,因为它还会从最新版本中删除工件。
问题
我有一个私有 Rust 项目 (A),它依赖于另一个私有 Rust 项目 (B)。在我的本地机器上,它可以工作,因为我登录了 git。我不知道如何在 Github Actions 中登录 git。我不确定是否需要。我读了很多关于 SSH 和 HTTPS 的内容,以至于我忘记了我必须做什么。
我看到了https://github.com/webfactory/ssh-agent、https://github.com/fusion-engineering/setup-git-credentials和其他一些操作,但我只是猜测我需要做的事情我无法让它工作。
设置
这是我在项目 A 中的 Cargo.toml 文件:
...
[dependencies]
b = { git = "https://github.com/me/b.git" }
Run Code Online (Sandbox Code Playgroud)
这在 Github Actions 中失败,因为 Github Actions 无法在没有某些令牌的情况下下载私有存储库。我创建了一个个人访问令牌并将我的 Cargo.toml 更改为:
...
[dependencies]
b = { git = "https://ignore:MyPersonalAccessToken@github.com/me/b" }
Run Code Online (Sandbox Code Playgroud)
但我收到一封来自 Github 的电子邮件,说我的令牌已被撤销,因为不允许将其硬编码在代码中......
现在我不知道该怎么办。我可以将令牌放入我的 github 秘密中,但我不知道我的 Cargo.toml 如何使用它。
有没有一种简单的方法可以在 Github Actions 中登录 git?我尝试了https://github.com/OleksiyRudenko/gha-git-credentials并配置了我的工作流程,如下所示:
- uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
token: '${{ secrets.GIT_CREDENTIALS }}'
global: true …Run Code Online (Sandbox Code Playgroud) name: master builder
on:
push:
branches:
- master
~~~
Run Code Online (Sandbox Code Playgroud)
我有一个这样的工作流程。因此,每当我推送到主分支时,操作就会运行。但我希望构建仅在最后一次推送时起作用。例如,
主分支 - 功能 1(人员 1)
主分支 - 功能 2 (person2)
主分支 - feature3 (person3)
在这个结构中,如果features1,2,3几乎同时合并,构建将运行3次。但我希望仅在最后一次合并的基础上构建主分支。就一次。有办法做到这一点吗?就像..在推送时等待大约 1 分钟后仅运行一次构建。
这是我按照您回答的方式进行的示例代码。但我收到错误“不允许键‘并发’”。怎么了?
name: test
on:
push:
branches:
- feature/**
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
~~~
Run Code Online (Sandbox Code Playgroud)