标签: github-actions

如何在 github 操作中激活 virtualenv?

我习惯使用 virtualenvs。但是由于某种原因,我无法在 github 操作作业中激活环境。

为了调试我添加了这一步:

      - name: Activate virtualenv
        run: |
          echo $PATH
          . .venv/bin/activate
          ls /home/runner/work/<APP>/<APP>/.venv/bin
          echo $PATH
Run Code Online (Sandbox Code Playgroud)

在操作日志上我可以看到

/opt/hostedtoolcache/Python/3.9.13/x64/bin:/opt/hostedtoolcache/Python/3.9.13/x64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[...]  # Cut here because a lot of lines are displayed. My executables are present including the one I'm trying to execute : pre-commit.
/home/runner/work/<APP>/<APP>/.venv/bin:/opt/hostedtoolcache/Python/3.9.13/x64/bin:/opt/hostedtoolcache/Python/3.9.13/x64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Run Code Online (Sandbox Code Playgroud)

所以它应该有效...

但接下来的步骤是

      - name: Linters
        run: pre-commit
Run Code Online (Sandbox Code Playgroud)

生成这些错误日志

Run pre-commit
  pre-commit
  shell: /usr/bin/bash -e {0}
  env:
    [...]  # private
/home/runner/work/_temp/8e893c8d-5032-4dbb-8a15-59be68cb0f5d.sh: line 1: pre-commit: command not found
Error: Process completed with exit code 127.
Run Code Online (Sandbox Code Playgroud)

如果我这样转换上面的步骤,我没有问题: …

bash virtualenv github-actions

6
推荐指数
1
解决办法
3906
查看次数

如何访问可重用工作流程中的参考

语境

公共存储库中的可重用工作流程可以通过附加引用来调用,该引用可以是 SHA、发布标签或分支名称,例如: {owner}/{repo}/.github/workflows/{filename}@{ref}

Github文档指出:

当调用者工作流触发可重用工作流时,github 上下文始终与调用者工作流关联。

问题

由于 github 上下文始终与调用者工作流关联,因此可重用工作流无法访问引用,例如 tag v1.0.0。但是,当可重用工作流需要签出存储库以便使用复合操作时,了解引用非常重要。

例子

假设调用者工作流正在分支内执行,并调用可重用工作流的main引用:v1.0.0.

name: Caller workflow
on:
  workflow_dispatch:

jobs:
  caller:
    uses: owner/public-repo/.github/workflows/reusable-workflow.yml@v1.0.0

Run Code Online (Sandbox Code Playgroud)

以下是使用复合操作的可重用工作流程:

name: reusable workflows
on:
  workflow_call:

jobs:
  first-job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3.1.0
        with:
          repository: owner/public-repo
          ref: ${{ github.ref_name }}

      - name: composite action
        uses: ./actions/my-composite-action
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中,${{ github.ref_name }}main而不是v1.0.0因为 github 上下文始终与调用者工作流程相关联。因此,复合动作代码是基于main而不是基于v1.0.0. 然而,打电话的人想要v1.0.0。因此我的问题是:可重用工作流程如何能够访问调用者给出的引用?

github-actions github-actions-reusable-workflows

6
推荐指数
0
解决办法
1256
查看次数

如何将手动工作流程运行附加到拉取请求的状态检查?

我有一个工作流程,可以test在给定情况下自动运行作业,也可以手动运行它:

name: Test

on:
  workflow_dispatch:
    inputs:
      used-branch:
        description: Branch the test shall be run on
        default: master
        required: true
  push:
    branches: ['main', 'master']
    tags: ['!**']
  pull_request:
    types: [opened, reopened, ready_for_review]

jobs:
  test:
    steps:
      - name: Checkout selected branch
        uses: actions/checkout@v3
        if: inputs.used-branch != ''
        with:
          ref: ${{ github.event.inputs.used-branch }}
      - name: Checkout current branch
        uses: actions/checkout@v3
        with:
          ref: ${{github.ref}}
        if: inputs.used-branch == ''
      - name: Run test
        ...
Run Code Online (Sandbox Code Playgroud)

我希望在合并之前需要进行测试。Require status check to pass before merging因此,我检查并在存储库的分支设置中Require …

pull-request github-actions

6
推荐指数
1
解决办法
2275
查看次数

需要(仅)矩阵中的一项特定工作来完成其他相关工作

GitHub Actions中,假设我有一个像这样的构建配置,它在 3 个不同的操作系统上构建我的程序并在 Ubuntu 上测试它:

name: build-and-test

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]


  test:
    runs-on: ubuntu-latest
    needs: build
Run Code Online (Sandbox Code Playgroud)

我希望该test作业依赖于该build作业运行的 Ubuntu。然而,现在这取决于这三个人。我如何指定作业test只需要 ubuntu 从build作业中运行即可在开始运行之前完成,而不是全部三个?

TL;DR:我希望testUbuntu 构建作业完成后立即运行该作业,而不是等待 macOS 和 Windows 构建作业。

github-actions

6
推荐指数
1
解决办法
1496
查看次数

PNPM Github 操作流程

我刚刚将项目从 npm 和 lerna 移至 pnpm,但现在使用 GitHub actions 时出现以下错误

“第 1 行:pnpm:未找到命令”

有人可以建议 .yml 文件应该是什么样子吗?我已经在下面发布了当前版本?

name: Lint & Unit Test

on: [pull_request]

jobs:
  run-linters:
    name: Run linter and Unit tests
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: ACTIONS_ALLOW_UNSECURE_COMMANDS
        run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16.18.1

      - name: Portal Install Node.js dependencies
        working-directory: ./portals
        run: |
          pnpm install

      - name: Portals Lint & tests
        working-directory: ./portals
        run: …
Run Code Online (Sandbox Code Playgroud)

github pnpm github-actions cicd

6
推荐指数
1
解决办法
6012
查看次数

使用在 [windows-latest] 上运行的工作流程创建 Github 存储库的 Zip 文件

我正在尝试使用 git hub 工作流程创建我的存储库的 zip 文件。下面是代码:

name: .NET    
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: [windows-latest]

    steps:
    - uses: actions/checkout@v3
    
    - name: Set Up MS Build
      uses: microsoft/setup-msbuild@v1
      
    - name: Restore dependencies
      run: nuget restore Solution.sln
      
    - name: Build Solution
      run: msbuild Solution.sln 
    
    - name: Creating Zip
      run: zip -r release.zip . -x ".git/*" ".github/*"
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误:

> The term 'zip' is not recognized as a name of a cmdlet, function,
> script file, …
Run Code Online (Sandbox Code Playgroud)

github github-for-windows github-actions

6
推荐指数
1
解决办法
2137
查看次数

今天从 GitHub 操作构建 SAM 突然失败:模块“lib”没有属性“OpenSSL_add_all_algorithms”

昨天,我的 SAM 构建正在使用以下 GitHub 操作。今天突然开始失败并出现错误:

AttributeError:模块“lib”没有属性“OpenSSL_add_all_algorithms”

经我验证,SAM 模板没有任何错误;还有其他人面临这个问题吗?

name: SAM deploy
on:
  push:
    branches:
      - main
jobs:
  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
      - uses: aws-actions/setup-sam@v2
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.MY_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.MY_AWS_SECRET_ACCESS_KEY }}
          aws-region: us-west-2
      - name: SAM Build
        run: sam build --use-container --template-file source/deploy-template.yml
      - name: SAM Deploy
        run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --stack-name my-stack --resolve-s3 --capabilities CAPABILITY_IAM --region us-west-2 --parameter-overrides Environment=npd
Run Code Online (Sandbox Code Playgroud)

SAM 构建的 GitHub 操作错误详细信息

        Traceback (most recent call …
Run Code Online (Sandbox Code Playgroud)

sam amazon-web-services github-actions

6
推荐指数
1
解决办法
1894
查看次数

TSC 在 github-action 期间构建错误,但在本地编译正常

通过actDocker 在本地测试 github-actions 时,我在 github-action 工作流程中遇到了各种 TS 错误(TS2345、TS18046、TS2339 等...)。在本地开发期间不会观察到这些错误,并且tsc -p tsconfig.build.json在本地计算机上运行会导致编译成功。

github-action 正在运行ubuntu-latest,我已确认运行器已配置为使用与本地版本相同的节点、npm、yarn 和 tsc 版本。

  • 节点-v18.13.0
  • npm -v8.19.3
  • 纱线-1.22.19
  • tsc-v4.9.4

此外,我已经确认 TSC 在 github-action 期间使用的配置与我的本地配置相同(来自 的输出tsc --showConfig,比较本地和 github-action 的差异)。使用 github-action 中的相同 docker 容器,我可以访问终端并运行相同的命令,而不会看到错误。

鉴于节点、npm、yarn 和 tsc 版本在我的本地和 github-action 中是相同的,什么可能导致这种不同的行为?

tsconfig.json

{
  "compilerOptions": {
    "rootDir": "./src",
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "skipLibCheck": true,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true, …
Run Code Online (Sandbox Code Playgroud)

typescript github-actions

6
推荐指数
1
解决办法
1793
查看次数

使用 GitHub 操作执行 maven 插件时缺少所需的类

最近,我的GitHub 操作在特定的 Maven 目标上失败,抱怨缺少所需的类(来自 plexus-utils)

\n

到目前为止,一切都运行良好,并且在本地仍然运行良好。

\n

(\xe2\x9a\xa0 在我的情况下这会影响,impsort-maven-plugin但这可能会影响其他maven插件,请参阅答案以更好地理解)

\n

这是我的完整日志 \xe2\x9d\x8c :

\n
Error:  \n\nFailed to execute goal net.revelc.code:impsort-maven-plugin:1.6.2:check (default-cli) on project leshan-core: \nExecution default-cli of goal net.revelc.code:impsort-maven-plugin:1.6.2:check failed:\nA required class was missing while executing net.revelc.code:impsort-maven-plugin:1.6.2:check:\norg/codehaus/plexus/util/DirectoryScanner\n\nError:  -----------------------------------------------------\nError:  realm =    plugin>net.revelc.code:impsort-maven-plugin:1.6.2\nError:  strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy\nError:  urls[0] = file:/home/runner/.m2/repository/net/revelc/code/impsort-maven-plugin/1.6.2/impsort-maven-plugin-1.6.2.jar\nError:  urls[1] = file:/home/runner/.m2/repository/com/github/javaparser/javaparser-core/3.22.1/javaparser-core-3.22.1.jar\nError:  urls[2] = file:/home/runner/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar\nError:  urls[3] = file:/home/runner/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar\nError:  urls[4] = file:/home/runner/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar\nError:  urls[5] = file:/home/runner/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar\nError:  urls[6] = file:/home/runner/.m2/repository/org/checkerframework/checker-qual/3.8.0/checker-qual-3.8.0.jar\nError:  urls[7] = file:/home/runner/.m2/repository/com/google/errorprone/error_prone_annotations/2.5.1/error_prone_annotations-2.5.1.jar\nError:  urls[8] = file:/home/runner/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar\nError:  Number of …
Run Code Online (Sandbox Code Playgroud)

maven-plugin maven github-actions

6
推荐指数
1
解决办法
3809
查看次数

如何通过 Github Actions runner 上的 CDK 构建 ARM64 Docker 映像

我正在尝试在 Github Actions 工作流程中部署我的 Fargate 服务(使用 ARM64 Graviton 处理器)。但是,当我的 Docker 尝试构建映像时,RUN语句失败:

Warning: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
 ---> Running in 025f2d97f759
exec /bin/sh: exec format error
Removing intermediate container f2c3858b0496
The command '/bin/sh -c apt-get update' returned a non-zero code: 1
 ---> 02ceb19d6208
[66%] fail: docker build --tag cdkasset-7e1b96b9aea331ad2efd7e6fbf6f075033eca830469ea4ab8d57bf4a8eeb86cd --file Dockerfile --platform linux/arm64 . exited with error code 1: The command '/bin/sh -c apt-get …
Run Code Online (Sandbox Code Playgroud)

arm docker aws-fargate aws-cdk github-actions

6
推荐指数
1
解决办法
1411
查看次数