标签: github-actions

github.event 的简单回显在 Github Actions 中失败

我只想打印github.eventGitHub Actions 步骤中的上下文,因此我正在执行以下操作

      - name: check context
        shell: bash
        run: echo ${{ toJSON(github.event) }}
Run Code Online (Sandbox Code Playgroud)

但是,这会失败,如下所示:

/home/runner/work/_temp/hd73999-5309-44cf-9218-9e2e3805d525.sh: line 2: after:: command not found
Error: Process completed with exit code 127.
Run Code Online (Sandbox Code Playgroud)

(尽管github.event 确实在错误发生之前打印了。

这是为什么?

我正在使用该toJSON函数,因为如果我不这样做,所有打印的内容都是:

Run echo Object
Object
Run Code Online (Sandbox Code Playgroud)

continuous-integration github github-actions

3
推荐指数
1
解决办法
1115
查看次数

github 私人页面中私人存储库中的 Github 操作徽章

随着 Github 私人页面的出现。我实际上可以将在私人存储库中运行的 github 操作放在其中。但是,私有页面无法呈现应有权访问此私有存储库的徽章。

在此输入图像描述

但是,如果我单击图像,就会看到徽章。这是因为我在 Github 中进行了身份验证,并且可以看到有关存储库的所有内容。我想知道为什么行动徽章没有显示。

github github-pages github-actions

3
推荐指数
1
解决办法
849
查看次数

如何加快 GitHub PyTest 执行速度?

我有一个包含数百个测试的存储库,到目前为止已经足够快了,但是随着我们继续扩大代码库,我担心它会变得如此缓慢,以至于我的团队将陷入等待 CI 运行完成的困境。

我可以做些什么来加快速度并使我的测试在短期和长期内都更快?

我需要考虑:

  1. 可扩展性
  2. 成本
  3. 推出

python performance continuous-integration pytest github-actions

3
推荐指数
1
解决办法
1177
查看次数

在可重用工作流程中“找不到‘action.yml’”

我有以下结构:

\n
.github\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 workflows\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.yml\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 send_alerts.yml\n
Run Code Online (Sandbox Code Playgroud)\n

现在主要是,我正在使用

\n
jobs:\n  main:\n    steps:\n      - name: Git Checkout\n        uses: actions/checkout@v3\n      - name: some job\n        run: |\n          ......\n  send_alerts:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v3\n      - uses: ./.github/workflows/send_alerts.yml@feature/workflow1\n        with:\n          provision_status: "Success"\n  \n
Run Code Online (Sandbox Code Playgroud)\n

在我的send_alerts.yml

\n
name: Creating and Sending Alerts/Status\non:\n  workflow_call:\n  \n    provision_status:\n      required: true\n      type: string\n\njobs:\n  create_send_alerts:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Git Checkout\n        uses: actions/checkout@v3\n      - name: Some other jobs\n        run: |\n        .....\n
Run Code Online (Sandbox Code Playgroud)\n

所以这让我犯了错误:

\n
Can't find …
Run Code Online (Sandbox Code Playgroud)

github github-actions

3
推荐指数
1
解决办法
2673
查看次数

Windows 托管运行器上 Github Actions 的输出

我想在 Windows 自托管运行器上访问之前作业的步骤结果。为了做到这一点,我使用如下输出变量,效果很好(在最后一步中打印“成功”)。

name: Debug workflow

on: workflow_dispatch
jobs:
  job1:
    runs-on: tester-1
    outputs:
      output1: ${{ steps.step1.outputs.MY_OUTPUT }}
    steps:
      - name: Checkout with submodules
        id: checkout_step
        uses: actions/checkout@v3
      - name: Write variable to output
        id: step1
        run: echo '::set-output name=MY_OUTPUT::${{ steps.checkout_step.outcome }}'
  job2:
    runs-on: tester-1
    needs: job1
    env:
      OUTPUT1: '${{needs.job1.outputs.output1}}'
    steps:
    - name: Print outputs from previous 
      run: echo ${{ env.OUTPUT1 }}
Run Code Online (Sandbox Code Playgroud)

然而::set-output 已被弃用,所以我想转换为正确的方法。根据另一个问题,我已经尝试将我的替换echo '::set-output name=MY_OUTPUT::${{ steps.checkout_step.outcome }}'

  1. echo "MY_OUTPUT=${{ steps.checkout_step.outcome }}" >> $env:GITHUB_ENV
  2. echo …

powershell github github-actions

3
推荐指数
1
解决办法
1590
查看次数

GitHub 工作流工作流_dispatch 在“操作”选项卡中丢失

我创建了一个工作流程文件,但该工作流程未显示在 GitHub 操作选项卡中

name: AZ Deploy Workflow
on:
  workflow_dispatch:  
    inputs:
      deploy-environment:
        description: 'Environment to deploy to'
        required: true
        default: 'dev'
      image-tag:
        description: 'Docker tag to deploy'
        required: true
        default: 'latest'
Run Code Online (Sandbox Code Playgroud)

任何想法有什么问题。

早些时候,我已将其他工作流程添加到 .github 目录中,即使放置一个空文件,它也会在操作中显示,但不会出现问题

workflow github github-actions cicd

3
推荐指数
1
解决办法
2434
查看次数

构建 docker 镜像后 Github runner 磁盘空间不足

我有两个 github 存储库(称为 A 和 B),它们都有一个.github/workflows/build_and_test.yml看起来几乎与此相同的文件:

name: Build and test

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

jobs:
  build-with-docker:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
      - uses: docker/setup-buildx-action@v2
      - uses: docker/build-push-action@v3
        with:
          tags: my_tag:latest
          load: true
          context: .
          cache-from: type=gha
          cache-to: type=gha,mode=max

      - run: docker run my_tag pytest
Run Code Online (Sandbox Code Playgroud)

在回购协议A中

  • 我的基础镜像Dockerfiler-base:4.2.1,大约 782MB
  • 我构建的镜像最终约为 1.71GB
  • github 工作流程从头到尾运行得很愉快(图像构建,步骤docker run my_tag pytest运行,一切都很好)

在仓库 B 中

  • 我的基础镜像Dockerfilepytorch/pytorch,大约 5.82GB
  • 我构建的镜像最终约为 …

diskspace docker github-actions

3
推荐指数
2
解决办法
5697
查看次数

GitHub Actions: How to override the default matrix with workflow_dispatch inputs?

If I want to let a user override the default values in the matrix, how do I do that?

Consider the following simplified example:

name: CICD
on:
  push:
    branches:
      - main
  workflow_dispatch:
    inputs:
      py_version:
        description: "Python version"
        default: "3.11"

jobs:
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        py_version: [3.7, 3.10]
    steps:
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.py_version }}
Run Code Online (Sandbox Code Playgroud)

I want to let a user override the py_version matrix list with the list provided in the workflow_dispatch input. Is there a way? …

github-actions

3
推荐指数
1
解决办法
1347
查看次数

Github:具有写入权限的审阅者需要至少 1 次批准审阅

最近,我换了一台新计算机,并在main使用简单的保护规则推送到我自己的分支时遇到了此“警告消息”。

保护规则为:

在此输入图像描述

我面临以下警告消息:

remote: Bypassed rule violations for refs/heads/main:
remote: 
remote: - At least 1 approving review is required by reviewers with write access.
Run Code Online (Sandbox Code Playgroud)

当推送到我的main分支时。我想知道这是否值得关注?由于我是所有者,我认为该消息不会出现。

git github-actions

3
推荐指数
1
解决办法
9346
查看次数

GitHub 操作失败,错误:无权执行 sts:AssumeRoleWithWebIdentity

我有两个 GitHub Actions,两者都是相同的,只是一个是手动触发的,另一个是在主分支上完成拉取请求时触发的。手动部署工作流程工作得很好,但是部署工作流程失败,并显示“错误:未授权执行 sts:AssumeRoleWithWebIdentity”。我缺少什么?我的猜测是两个事件之间的子项一定是不同的?我该如何检查?

这有效

name: manual-deploy
on:
  workflow_dispatch:

env:
  REACT_APP_VERSION: 0.1.0

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    steps:
      - name: checkout code
        uses: actions/checkout@v3
        
      - name: install node
        uses: actions/setup-node@v3
        # using later versions of node breaks due to react-scripts v5.0.1 incompatible with typescript v5;
        # this specific node version works though
        with:
          node-version: "16.14.2"

      - name: install dependencies
        run: npm install
        
      - name: run tests
        run: npm run test

      - name: get current date
        id: …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-iam github-actions

3
推荐指数
1
解决办法
2442
查看次数