标签: github-actions

在 GitHub Actions 工作流作业中使用环境的动态输入值

我正在尝试创建一个 GitHub Actions 工作流程,其中一项作业对其environment设置具有动态值。https://docs.github.com/en/actions/reference/environments我在此工作流程中有两项工作。第一个作业决定第二environment个作业将在哪个作业中运行,而这又取决于操作作业从哪个 git 分支运行。

\n

这是我天真的尝试让它工作,但我收到一个错误,上面写着

\n
\n

(行:29,列:18):无法识别的命名值:\'需要\'。位于表达式中的位置 1:needs.get-environment.outputs.environment_name

\n
\n
name: Environments\n\non:\n  push:\n  workflow_dispatch:\n\njobs:\n  get-environment:\n    runs-on: ubuntu-latest\n    outputs:\n      environment_name: ${{ steps.get_environment.outputs.environment_name }}\n    steps:\n      - id: get_environment\n        run: |\n          if [ "$GITHUB_REF" = "refs/heads/test" ]\n          then\n            echo "::set-output name=environment_name::test"\n          elif [ "$GITHUB_REF" = "refs/heads/qa" ]\n          then\n            echo "::set-output name=environment_name::qa"\n          elif [ "$GITHUB_REF" = "refs/heads/master" ]\n          then\n            echo "::set-output name=environment_name::production"\n          fi\n    \n  use-environment:\n    runs-on: ubuntu-latest\n    needs: [get-environment]\n    environment: ${{ needs.get-environment.outputs.environment_name }}\n    steps:\n …
Run Code Online (Sandbox Code Playgroud)

github-actions

5
推荐指数
1
解决办法
6888
查看次数

如何在 GitHub 操作 YML 文件中添加注释?

在下面的语法中:

jobs:
  testing:
    name: some test
    runs-on: [ self-hosted, linux, xyz ]
    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.0
        id: go

      - name: Configure git client
        run: git config --global url."ssh://git@github.com:".insteadOf "https://github.com/"
Run Code Online (Sandbox Code Playgroud)

如何添加run git client to fix some issue运行命令的注释?

github github-actions

5
推荐指数
2
解决办法
5596
查看次数

在 GitHub Actions 上使用 Vagrant(最好包括 VirtualBox)

从这个答案中知道,可以使用 TravisCIlibvirt而不是 VirtualBox 在 TravisCI 上启动并运行 Vagrant Boxes。

GitHub Actions 也可以实现这一点吗?由于新的定价模型,我们将把所有内容从 TravisCI 上移走,因此我们还需要切换基于 Vagrant 的测试用例。

continuous-integration virtualbox virtual-machine vagrant github-actions

5
推荐指数
1
解决办法
3090
查看次数

在 Github 操作中从 Github 包安装 Nuget 包

我正在尝试在运行 Github Action 时安装托管在 Github Packages 中的 Nuget 包。

此命令用于添加源并且构建正在运行:

dotnet nuget add source https://nuget.pkg.github.com/<ORGNAME>/index.json -n github -u <MY_USERNAME> -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
Run Code Online (Sandbox Code Playgroud)

所以 - 这是有效的,我的构建运行良好。

但是 -我想-u <MY_USERNAME>从行动中删除。我想使用像 这样的通用值${{ secrets.GITHUB_TOKEN }}。如果我离开组织或其他什么 - 我不希望依赖于特定帐户。

github nuget github-actions github-package-registry

5
推荐指数
1
解决办法
847
查看次数

shell: /bin/bash -e {0} 在 github Action Worker 的 bash shell 输出中意味着什么?

因为当没有要提交的更改时 git 会使用非零代码提交退出,这会导致 github 操作失败。为了克服这个问题,我尝试在提交之前检查是否有任何更改,如下所示 -

if git diff-index --quiet HEAD --; then
    echo "changes_exist=true" >> $GITHUB_ENV
else
    echo "changes_exist=false" >> $GITHUB_ENV
fi
Run Code Online (Sandbox Code Playgroud)

然后 GitHub 在其下方向我展示了这一点 - shell: /bin/bash -e {0}

谷歌搜索似乎没有产生任何结果。知道这意味着什么吗?

跑步者的精确输出 -

Run if git diff-index --quiet HEAD --; then
  if git diff-index --quiet HEAD --; then
      echo "changes_exist=true" >> $GITHUB_ENV
  else
      echo "changes_exist=false" >> $GITHUB_ENV
  fi
  shell: /bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.1/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.1/x64/lib
Run Code Online (Sandbox Code Playgroud)

git bash shell github github-actions

5
推荐指数
1
解决办法
3047
查看次数

GitHub 操作无法连接到 MongoDB 服务

我在使用 GitHub 操作运行自动化测试时遇到问题。我不明白为什么我无法连接到运行集成测试的 MongoDB 服务。我尝试了不同的主机:localhost、127.0.0.1、0.0.0.0,但它们都无法连接数据库。

它在我的 docker 设置中运行得很好,但由于某种原因不能与 GitHub 操作一起运行。

    name: CI master
    
    on: [push, pull_request]
    
    env:
      RUST_BACKTRACE: 1
      CARGO_TERM_COLOR: always
      APP_ENV: development
      APP_MONGO_USER: test
      APP_MONGO_PASS: password
      APP_MONGO_DB: test
    
    jobs:
      # Run tests
      test:
        name: Test
        runs-on: ubuntu-latest
        services:
          mongo:
            image: mongo
            env:
              MONGO_INITDB_ROOT_USERNAME: ${APP_MONGO_USER}
              MONGO_INITDB_ROOT_PASSWORD: ${APP_MONGO_PASS}
              MONGO_INITDB_DATABASE: ${APP_MONGO_DB}
            ports:
              - 27017:27017
        steps:
          - uses: actions/checkout@v2
          - uses: actions-rs/toolchain@v1
            with:
              profile: minimal
              toolchain: stable
              override: true
          - uses: actions-rs/cargo@v1
            with:
              command: test
Run Code Online (Sandbox Code Playgroud)

配置文件(development.toml)。

[application]
host = "127.0.0.1"
port = 8080 …
Run Code Online (Sandbox Code Playgroud)

github mongodb rust docker github-actions

5
推荐指数
1
解决办法
6703
查看次数

尝试解析 Github Action 中的 JSON 输出

我正在尝试在 GitHub 操作中提取 HTTP 请求的值,然后在另一个步骤中使用该值。

这是当前的代码:

  - run: call some https endpoint
Run Code Online (Sandbox Code Playgroud)

然后返回到控制台输出:

{
    "authorizationToken": "<snip>",
    "expiration": "2021-02-26T18:18:38+00:00"
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试提取该authorizationToken值,然后在下一步中使用它,例如

  -name: Get auth token
   run: call some https endpoint
   
  -name: set something which uses the token
   run: set blah --token $token_from_previous_step
Run Code Online (Sandbox Code Playgroud) 现在,我什至无法使用“jq”程序从 json 输出中提取身份验证令牌的值:
~  - run: call some https endpoint | echo "jq '.authorizationToken'"~
Run Code Online (Sandbox Code Playgroud)

其中错误:

jq '.authorizationToken'
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
Run Code Online (Sandbox Code Playgroud)

我现在可以提取键/值..但不确定如何将其设置为环境变量,以便在其他步骤中使用。

这有效:

    - run: call some https endpoint …
Run Code Online (Sandbox Code Playgroud)

command-line-interface jq github-actions

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

如何在 Github 工作流程中的多个作业中重用策略矩阵

我想避免在不同的工作中重复策略矩阵:

\n
jobs:\n  build-sdk:\n\n    runs-on: macOS-latest\n    strategy:\n      fail-fast: false\n      matrix:\n        qt-version: ['5.15.1']\n        ios-deployment-architecture: ['arm64', 'x86_64']\n        ios-deployment-target: '12.0'\n\n\n    steps:\n      \xe2\x80\xa6\n\n  create-release:\n    needs: build-sdk\n    runs-on: macOS-latest\n    steps:\n      \xe2\x80\xa6\n\n\n  publish-sdk:\n    needs: [build-sdk, create-release]\n    runs-on: macOS-latest\n    strategy:\n      fail-fast: false\n       matrix: ?????\n\n    steps:\n      \xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n

这可能吗(无需创建作业来将矩阵创建为 JSON 本身)?

\n

continuous-integration github-actions

5
推荐指数
1
解决办法
2337
查看次数

iOS Build 无法在 fastlane 和 Github Action 上运行

我对 iOS 应用程序的 github Actions CI 有问题(反应本机),除了在本地和 Travis 上运行良好的应用程序构建之外,我的所有通道都运行良好,但在 Github Actions 上它仍然被阻止

Running script '[CP] Copy Pods Resources'
Running script 'Run Script'
Run Code Online (Sandbox Code Playgroud)

我把它取下来Running script 'Run Script',它就卡在了之前的台阶上!

尝试了很多构建方法还是不行!

这是我尝试的车道

build_app(workspace: "myapp.xcworkspace", scheme: "myapp")
Run Code Online (Sandbox Code Playgroud)

和/或

gym(
  workspace: "myapp.xcworkspace", 
  configuration: "Release",
  scheme: "myapp",
  clean: true,
  export_method: "ad-hoc"
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ios react-native fastlane github-actions

5
推荐指数
0
解决办法
361
查看次数

在 GitHub 操作的 Shell 脚本中使用环境变量

我有一个项目,正在使用 GitHub Actions 进行 CI/CD。我有一个 shell 脚本,我想从我的 Actions yml 中注入环境变量。这是我到目前为止所拥有的:

  - name: docker-push
    env:
      USER: joesan
      SOME_GITHUB_REPO_NAME: github-repo-name
      GH_REPO: github.com/$USER/$SOME_GITHUB_REPO_NAME
    run: |
      echo "Running sbt assembly"
      echo $GITHUB_REF
      echo "Pushing tag into Docker Registry"
      sh ./scripts/tag_deployment.sh
Run Code Online (Sandbox Code Playgroud)

在 tag_deployment.sh 中,我尝试使用这些变量:

....
....
git clone https://${GH_REPO}
cd "${SOME_GITHUB_REPO_NAME}"
....
....
Run Code Online (Sandbox Code Playgroud)

但我看到当操作运行时它不会打印设置的内容!

Cloning into '$SOME_GITHUB_REPO_NAME'...
fatal: unable to access 'https://github.com/$USER/$SOME_GITHUB_REPO_NAME/': The requested URL returned error: 400
Run Code Online (Sandbox Code Playgroud)

如何将这些环境变量正确注入到我的 shell 脚本中?

shell github-actions

5
推荐指数
1
解决办法
2531
查看次数