标签: github-actions

GitHub Actions 的配置:将 PR 合并到 main 时避免运行 CI 两次

我正在使用 GitHub actions 来管理我的 CI,以下事件会触发我的工作流程:

on:
  pull_request:
    branches: main
  push:
    branches: main
Run Code Online (Sandbox Code Playgroud)

我观察到以下“问题”:当我创建 PR 时,CI 就会运行。如果测试通过并且我将其合并到 main 中,则会再次运行测试(在特定情况下我不希望这样做)。如何设置我的工作流程,以便在合并 PR(CI 已通过 PR)时不会触发 CI?

提前致谢!

github github-actions building-github-actions

7
推荐指数
1
解决办法
1478
查看次数

秘密不会从 github 操作秘密传递到 github 操作中的可重用工作流程

我在 github 操作中创建了秘密,并尝试在可重用的工作流程中使用它们,但我无法使其工作,但是,如果我传递从调用者文件中硬编码的秘密,它就可以正常工作

## set_env.yml
name: Sent Env Creds and Vars

on:
  push:
    branches:
      - main
      - dev
  pull_request:
    branches: [ main ]

jobs:
  deploy-dev:
    uses: ./.github/workflows/main.yml
    with:
      AWS_REGION: "us-east-2"
      PREFIX: "dev"
    secrets:
      AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
Run Code Online (Sandbox Code Playgroud)

可重用的工作流程 = main.yml

## main.yml
name: Deploy to AWS  

# Controls when the workflow will run
on:
  workflow_call:
    inputs:
      AWS_REGION:
        required: true
        type: string
      PREFIX:
        required: true
        type: string
    secrets:
      AWS_ACCESS_KEY_ID:
        required: true
      AWS_SECRET_ACCESS_KEY:
        required: true

# A workflow …
Run Code Online (Sandbox Code Playgroud)

github amazon-web-services terraform github-actions

7
推荐指数
1
解决办法
3964
查看次数

Github 操作 + Azure OIDC,任何分支的“主题”值

我正在使用 Github Actions 构建一些要推送到 Azure 容器注册表的 Docker 映像。我正在尝试基于此 GH Action使用 OIDC 作为身份验证机制。我知道该操作支持其他身份验证策略,出于某种原因,我已在我的用例中放弃了这些策略。

根据GH 文档,需要根据 GH 帐户、存储库名称和分支名称填充“主题”字段。然而,想要为多个分支构建 Docker 镜像,这似乎需要每个分支一个联合配置 - 在我看来,这不切实际。

所以我的问题是:有谁知道是否可以(以及如何)设置一个带有“主题”值的联合配置,该值可以作为某种通配符,涵盖给定存储库中的所有分支?

谢谢!

azure azure-active-directory openid-connect github-actions

7
推荐指数
1
解决办法
2044
查看次数

如何使 github 工作流程错误消息显示在日志和注释中?

我有一个工作流程步骤,循环运行 shell 命令的最后阶段:

|| echo "::error Filename $filename doesn't match possible files" && exit 1 ; done

退出被适当触发,但我看到的唯一注释是:

错误:进程已完成,退出代码为 1。

日志显示了整个 shell 命令管道以及相同的错误消息,但不是我的回显错误。

如何获取我的输出,包括 $filename 变量?

github-actions

7
推荐指数
1
解决办法
9803
查看次数

7
推荐指数
1
解决办法
5980
查看次数

在 GitHub Actions 中获取“参数列表太长”

我正在遵循 HashiCorp 的学习指南,了解如何设置 GitHub Actions 和 terraform。除了使用 Terraform 计划更新 PR 的步骤之外,一切都运行良好。

\n

我遇到以下错误:

\n
\nAn error occurred trying to start process \'/home/runner/runners/2.287.1/externals/node12/bin/node\' with working directory \'/home/runner/work/ccoe-aws-ou-scp-manage/ccoe-aws-ou-scp-manage\'. Argument list too long\n\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用的代码是:

\n
    - uses: actions/github-script@0.9.0\n      if: github.event_name == \'pull_request\'\n      env:\n        PLAN: "terraform\\n${{ steps.plan.outputs.stdout }}"\n      with:\n        github-token: ${{ secrets.GITHUB_TOKEN }}\n        script: |\n          const output = `#### Terraform Format and Style \\`${{ steps.fmt.outcome }}\\`\n          #### Terraform Initialization \xe2\x9a\x99\xef\xb8\x8f\\`${{ steps.init.outcome }}\\`\n          #### Terraform Plan \\`${{ steps.plan.outcome }}\\`\n          <details><summary>Show Plan</summary>\n          \\`\\`\\`${process.env.PLAN}\\`\\`\\`\n          </details>\n          *Pusher: …
Run Code Online (Sandbox Code Playgroud)

github terraform github-actions cicd

7
推荐指数
1
解决办法
5603
查看次数

Github 操作测试之前是否进行了包含特定单词的提交

我需要确保使用 github 操作进行测试,如果之前已进行过包含单词 的提交build。如果提交不包含该单词build,则不应运行 github 操作的测试。

你能给我一些建议吗?

测试:

name: "Testing"

on:
  push:
    branches:
      - master

jobs:
  test_the_action:
    name: Test the action
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2          
      - uses: suisei-cn/actions-download-file@master
        id: downloadfile
        name: Download a file
        with:
          url: "[API Endpoint](https://api.github.com/repos/suisei-cn/actions-download-file)"
          target: public/
          auto-match: true

      - name: Display the file
        run: head -n8 public/actions-download-file          
Run Code Online (Sandbox Code Playgroud)

yaml action build github github-actions

7
推荐指数
1
解决办法
9066
查看次数

自动创建标签时,Github 操作不会触发

我有一个 Github 工作流程,配置为在标签推送事件上触发:

on:
  push:
    tags:
      - "*"
Run Code Online (Sandbox Code Playgroud)

如果我创建一个标签并自己从命令行或使用 Egit/JGit 插件从 Eclipse GUI 推送它,Github 操作就会正常触发。

但是,如果我从另一个 Github 操作执行相同的命令行标签创建,则应在“推送标签”上触发的 Github 操作不会触发。

下面是我在其他 Github 操作中运行的命令,或者从 中运行的命令Git-Bash,在这两种情况下都成功运行:

git commit -a -m "prepare for new version $NEW_VERSION"
git push
git tag -a $NEW_VERSION -m "$NEW_VERSION"
git push origin $NEW_VERSION
Run Code Online (Sandbox Code Playgroud)

git tag $NEW_VERSION还通过命令行尝试了轻量级标签和各种身份(包括我自己git config --global user.name的)git config --global user.email

  • GitHub 操作 action@github.com
  • github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • github-actions github-actions@github.com

我在这里缺少什么?

git github github-actions

7
推荐指数
1
解决办法
4345
查看次数

运行 Github Action 当 PR 从特定分支名称提升到特定分支名称时?

我们有一个公共 SDK 存储库,我正在为其编写多个 github 工作流程。develop其中一个工作流程包括当 PR 从 发起到时生成发布 SDK(缩小,用私钥编码)mastertask/**另一个此类操作是在从一个分支到另一个分支引发 PR 时运行静态代码检查develop。我尝试使用以下工作流程:

name: validate PR raised from task/** branched to develop branch
on:
  pull_request:
    branches: [ task/** ]

  pull_request_target:
    branches: [ develop ]
  ...

Run Code Online (Sandbox Code Playgroud)

该代码被推送到开发分支。但这会在每次提出或修改 PR 时触发工作流程两次,表明该操作正在使用“OR”配置运行。我只想在“AND”条件下运行此工作流程一次(即当源分支为task/**AND 目标分支为develop

对于我的第一个用例,只有内部开发人员才能触发生成构建,这一点非常重要。那么是否可以针对特定目标和源分支运行操作?

github github-actions

7
推荐指数
1
解决办法
3926
查看次数

如何从 github actions 运行 ansible playbook - 不使用外部操作

我编写了一个工作流程文件,让运行程序准备使用 ssh 连接到所需的服务器,以便我可以运行 ansible playbook。

ssh -t -v theUser@theHost显示 SSH 连接有效。

然而,ansible 脚本告诉我,sudo 密码丢失了。

如果我忽略该行ssh -t -v theUser@theHost,ansible 会抛出连接超时并且无法连接到服务器。

=> fatal: [***]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host *** port 22: Connection timed out

首先我不明白,为什么ansible只有执行命令才能连接到服务器 ssh -t -v theUser@theHost

下一个问题是,用户不需要任何 sudo 密码即可拥有执行权限。同样的 ansible playbook 在我的本地机器上运行得很好,无需使用 sudo 密码。我配置了服务器,以便用户递归地在所需文件夹中拥有足够的权限。

它根本无法通过我的 GitHub Action 工作。你能告诉我我做错了什么吗?

我的工作流程文件如下所示:

name: CI

# Controls when the workflow will run
on:
  # …
Run Code Online (Sandbox Code Playgroud)

linux ssh ansible github-actions

7
推荐指数
1
解决办法
7814
查看次数