标签: github-actions

文件未使用“-s”进行“gofmt”编辑:为什么会发生这种情况以及如何解决?

每次我们在存储库上打开或更新拉取请求时,我们都会使用 linter(适用于 Golang)来运行 Github Actions 工作流程。

它最近开始返回以下错误

File is not `gofmt`-ed with `-s` (gofmt)

在该文件的其他 PR中发生的事情之后pkg/api/api/go
(编辑:添加链接以评估并最终重现错误)

证据:

原始提交

短绒输出

我想了解这个错误的根源是什么,以及如何解决它?

go gofmt linter github-actions

12
推荐指数
2
解决办法
4万
查看次数

GitHub Actions cronjob 触发器似乎在一小时后触发

虽然我使用过 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 的调度是这样的,它可能会延迟几分钟之类的,但这似乎很奇怪,它在一周半的时间里以相当一致的方式延迟了一个多小时。

有人知道如何解决这个问题吗?我知道这很小,但有点烦人,如果我需要在指定时间发生事件,我想了解一些事情。

cron github github-actions

11
推荐指数
1
解决办法
2470
查看次数

Github Action:在矩阵组合之前运行一步

我正在创建一个 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)

build github github-actions

11
推荐指数
1
解决办法
7205
查看次数

如何处理 Github Actions Workflow 中的长条件表达式

如何最好地处理 GitHub Actions Workflow 中的长条件表达式?

我有一个工作流程,我想在两种情况下运行:

  1. 当拉取请求关闭时
  2. 当在拉取请求上创建包含特定字符串的评论时

这导致工作流定义具有长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,我想避免这种情况。

我搜索了一些想法,但没有找到以下可行的解决方案:

  • 在多行上定义表达式
  • 将 if 拆分为多个 if 表达式

github-actions

11
推荐指数
1
解决办法
7773
查看次数

Github Actions下构建作业时如何安装本地python包?

我正在构建一个 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)

python pip github requirements.txt github-actions

11
推荐指数
1
解决办法
2万
查看次数

Github Action 在多个 on:push: 路径上触发

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-actions building-github-actions

11
推荐指数
1
解决办法
2万
查看次数

如何使用私有存储库中存在的复合操作?

我们对第三方服务进行了大量的健康检查。我们希望它们定期运行,因为当它们出现故障时,它会像代码中的错误一样影响我们的应用程序。知道“是他们而不是我们”可以显着减少故障排除时间。

我们已经通过 github 操作设置了此运行状况检查并计划运行,但我们希望每个第三方服务都有一个运行状况检查。这样,有关失败的 slack 消息将非常具体地说明发生了什么情况。但这会创建大量重复的 yml 内容。

我发现了一个叫做github 复合操作的东西,它似乎是为了解决这个问题,但我找不到有关复合操作是否可以存在于私有存储库中的信息。

uses密钥的文档仅在提及存储库时才提及公共存储库。有没有办法在私有存储库中进行复合操作并使用它?

我尝试制作他们的 hello world 示例,运行它,并且运行正确。然后我将操作存储库设为私有,并且使用操作构建的存储库失败并显示:

Unable to resolve action `user/repo@v1`, repository not found
Run Code Online (Sandbox Code Playgroud)

github repository github-actions

11
推荐指数
3
解决办法
9129
查看次数

GitHub Actions 中的“shell: bash -l {0}”

当我使用setup-minicondashell: bash -l {0}时,它在 GitHub Actions 中使用:

\n
jobs:\n  foo:\n    name: Foo\n    runs-on: "ubuntu-latest"\n    defaults:\n      run:\n        shell: bash -l {0}\n
Run Code Online (Sandbox Code Playgroud)\n

当我使用CML时。它只使用shell: bash没有-l {0}.

\n

我在GitHub Actions doc找到了一些解释:

\n
\n

您可以shell使用 将该值设置为模板字符串command [\xe2\x80\xa6options] {0} [..more_options]。GitHub 将字符串的第一个空格分隔的单词解释为命令,并在 处插入临时脚本的文件名{0}

\n
\n

-l不过我还是不太明白和 的作用是什么{0}?对于-l,它是 的参数bash吗?

\n

感谢一些解释!

\n

bash shell github-actions

11
推荐指数
1
解决办法
2591
查看次数

在初始运行 30 天后,如何在 github actions 中重新运行旧工作流程?

我正在寻找一种方法来重新运行 github actions 中的旧工作流程,该工作流程上次运行一个多月前。我从 github actions 中看到了这份文档https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs 有没有办法在 30 天后重新运行旧的工作流程初始运行?

干杯并提前致谢!

github github-actions

11
推荐指数
1
解决办法
1432
查看次数

无法从 garygrossgarten/github-action-ssh@release 的非 TTY 设备执行交互式登录错误

我正在尝试在由 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)

ssh command docker github-actions

11
推荐指数
1
解决办法
2万
查看次数