虽然我使用过 GitHub Actions(带有推送触发器),但对于根据指定时间安排它们还相当陌生。简单地说:我cronjob使用以下触发器在 GitHub Actions 上进行了简单的运行:
on:
schedule:
- cron: "0 0 * * *"
Run Code Online (Sandbox Code Playgroud)
这应该在每天 UTC 0 点运行,但我在日志中看到它至少在 1 小时后(在 UTC 01:04-01:11 之间)启动。我知道 GitHub Actions 的调度是这样的,它可能会延迟几分钟之类的,但这似乎很奇怪,它在一周半的时间里以相当一致的方式延迟了一个多小时。
有人知道如何解决这个问题吗?我知道这很小,但有点烦人,如果我需要在指定时间发生事件,我想了解一些事情。
我正在创建一个 Github 操作工作流程。
有一个 phing 构建文件,可根据产品变体创建多个 zip。这是通过矩阵完成的。
在构建产品之前,需要构建一个 JS 文件。这是通过汇总构建文件完成的。
一切正常,但 JS 构建只需要完成一次,而不是每个矩阵组合都需要完成。
我不知道该怎么做。也许在开始时运行一个单独的工作流程,但是如何将完成的 JS 文件推送到下一个工作流程中?或者也许一种工作流程就可以了?
name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
env:
VERSION: 1.0.1
strategy:
matrix:
edition: ["product1", "product2", "product3"]
limits: [100, 200, 300]
exclude:
- edition: product1
limits: 100
- edition: product2
limits: 100
- edition: product1
limits: 200
- edition: product2
limits: 200
steps:
- uses: actions/checkout@v2
- name: Build JS
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: …Run Code Online (Sandbox Code Playgroud) 如何最好地处理 GitHub Actions Workflow 中的长条件表达式?
我有一个工作流程,我想在两种情况下运行:
这导致工作流定义具有长if表达式:
on:
pull_request:
types: [ closed ]
issue_comment:
types: [ created ]
jobs:
do:
if: ${{ github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, 'specific string')) }}
steps:
...
Run Code Online (Sandbox Code Playgroud)
我看到的一个解决方案是将工作流程分成 2 个定义,但由于 DRY,我想避免这种情况。
我搜索了一些想法,但没有找到以下可行的解决方案:
我正在构建一个 python 项目—— potion. 我想在将新分支合并到 master 之前使用 Github 操作来自动执行一些 linting 和测试。
为此,我使用了对 Github 推荐的 python actions 启动工作流程——Python Application的轻微修改。
在作业中的“安装依赖项”步骤中,我收到错误。这是因为 pip 尝试安装我的本地软件包potion但失败。
失败的代码if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
对应的错误是:
ERROR: git+https@github.com:<github_username>/potion.git@82210990ac6190306ab1183d5e5b9962545f7714#egg=potion is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, …Run Code Online (Sandbox Code Playgroud) paths: 'frontend/**'在单个存储库中,我想为不同的路径 [和]创建多个触发器,paths: 'backend/**'并为(相同的)构建作业使用不同的参数。以下是两个工作流程。
name: Trigger Jenkins Build [ Build-Portal ]
on:
push:
branches: [ develop ]
paths: 'frontend/**'
types: [closed]
jobs:
build:
name: Triggering Jenkins Build [ Build-Portal ]
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Trigger Build-Portal
uses: actions/trigger-jenkins@develop
with:
...
job_name: "Build-Portal"
job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
...
Run Code Online (Sandbox Code Playgroud)
和
name: Trigger Jenkins Build [ Build-Portal ]
on:
push:
branches: [ develop ]
paths: 'backend/**'
types: [closed]
jobs:
build:
name: Triggering Jenkins Build …Run Code Online (Sandbox Code Playgroud) 我们对第三方服务进行了大量的健康检查。我们希望它们定期运行,因为当它们出现故障时,它会像代码中的错误一样影响我们的应用程序。知道“是他们而不是我们”可以显着减少故障排除时间。
我们已经通过 github 操作设置了此运行状况检查并计划运行,但我们希望每个第三方服务都有一个运行状况检查。这样,有关失败的 slack 消息将非常具体地说明发生了什么情况。但这会创建大量重复的 yml 内容。
我发现了一个叫做github 复合操作的东西,它似乎是为了解决这个问题,但我找不到有关复合操作是否可以存在于私有存储库中的信息。
uses密钥的文档仅在提及存储库时才提及公共存储库。有没有办法在私有存储库中进行复合操作并使用它?
我尝试制作他们的 hello world 示例,运行它,并且运行正确。然后我将操作存储库设为私有,并且使用操作构建的存储库失败并显示:
Unable to resolve action `user/repo@v1`, repository not found
Run Code Online (Sandbox Code Playgroud) 当我使用setup-minicondashell: bash -l {0}时,它在 GitHub Actions 中使用:
jobs:\n foo:\n name: Foo\n runs-on: "ubuntu-latest"\n defaults:\n run:\n shell: bash -l {0}\nRun Code Online (Sandbox Code Playgroud)\n当我使用CML时。它只使用shell: bash没有-l {0}.
我在GitHub Actions doc找到了一些解释:
\n\n\n您可以
\nshell使用 将该值设置为模板字符串command [\xe2\x80\xa6options] {0} [..more_options]。GitHub 将字符串的第一个空格分隔的单词解释为命令,并在 处插入临时脚本的文件名{0}。
-l不过我还是不太明白和 的作用是什么{0}?对于-l,它是 的参数bash吗?
感谢一些解释!
\n我正在寻找一种方法来重新运行 github actions 中的旧工作流程,该工作流程上次运行一个多月前。我从 github actions 中看到了这份文档https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs 有没有办法在 30 天后重新运行旧的工作流程初始运行?
干杯并提前致谢!
我正在尝试在由 github 操作创建的 ssh 连接中运行 docker 命令。我什至在工作流程中使用了提及。这是我的工作流程
\n# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node\n# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions\n\nname: Node.js CI\n\non:\n pull_request:\n branches: ['main']\n\nenv:\n REGISTRY: 'ghcr.io/testing/api-gateway'\n IMAGE_NAME: ${{ format('{0}-{1}', github.event.repository.name, github.sha) }}\n USERNAME: ${{ secrets.USERNAME }}\n DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}\n\njobs:\n build:\n runs-on: ubuntu-latest\n\n strategy:\n matrix:\n node-version: [16.x]\n\n steps:\n - uses: actions/checkout@v3\n\n - name: Use Node.js ${{ matrix.node-version }}\n uses: actions/setup-node@v3\n with:\n …Run Code Online (Sandbox Code Playgroud)