我有一个在两个不同事件上运行的 github 工作流程:pull_request 和手动。它看起来像这样:
\non:\n pull_request:\n branches: [master]\n workflow_dispatch: {}\n\nenv:\n API_URL: https://example.com/\nRun Code Online (Sandbox Code Playgroud)\nAPI_URL我想要的是当我手动触发工作流程时能够设置替代方案。但我希望工作流程在自动运行时也能以相同的方式运行。\n因此,首先,我将 \xe2\x80\x9c inputs\xe2\x80\x9d 添加到工作流程_dispatch 中:
on:\n pull_request:\n branches: [master]\n workflow_dispatch:\n inputs:\n API_URL:\n description:\n required: true\n default: https://example.com\n\nenv:\n API_URL: ${{ github.event.API_URL }}\nRun Code Online (Sandbox Code Playgroud)\n据我了解,这样API_URL只有在手动运行工作流程时才会设置环境变量。但是当它自动运行时,xe2x80x99s没有github.event.API_URL值。
在我看来,这里需要一个条件回退。\n这样的东西会起作用吗?
\nenv:\n API_URL: ${{ github.event.API_URL || \'https://example.com/\' }}\nRun Code Online (Sandbox Code Playgroud)\n但从文档来看,||运算符将计算为1or 0。
有没有好的办法解决这个问题呢?谢谢!
\n在每次提交时,我都会在不同的操作系统上构建我的项目。因此,我使用 CMake 作为我的 C++ 代码的构建系统。为了使构建速度更快,我尝试缓存较旧的构建,因此不必重新构建未更改的文件。我编写了以下 GH 动作脚本:
name: Build for MacOS, Ubuntu and Windows
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-11, windows-2022 ]
steps:
- uses: actions/checkout@v2
- name: Cache build
uses: actions/cache@v3
with:
path: ${{github.workspace}}/build
key: ${{ matrix.os }}-build
restore-keys: ${{ matrix.os }}-build
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DFORCE_COLORED_OUTPUT=1
- name: Build
run: cmake …Run Code Online (Sandbox Code Playgroud) 我正在尝试为矩阵中的每个失败作业单独上传日志。每组日志都需要有一个基于作业矩阵的名称,否则它们会互相破坏,我无法分辨生成的工件来自哪个作业。
我尝试打印所有上下文:
name: My workflow
on:
pull_request:
types: [opened, synchronize]
jobs:
my-job:
name: OS ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-18.04
- ubuntu-20.04
steps:
- run: echo "${{ toJSON(github) }}"
- run: echo "${{ toJSON(env) }}"
- run: echo "${{ toJSON(job) }}"
- run: echo "${{ toJSON(steps) }}"
- run: echo "${{ toJSON(runner) }}"
- run: echo "${{ toJSON(secrets) }}"
- run: echo "${{ toJSON(strategy) }}"
- run: echo "${{ toJSON(matrix) }}"
- run: echo …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以使用 GitHub Actions 在测试通过后自动合并分支。
我们有两个分支,“测试”和“主”。每次合并或推送到“测试”后,我们都会设置一个工作流程来运行测试。
是否可以让 GitHub 在测试完成后自动合并“test”->“main”,并且只有在测试成功完成时才进行合并?
我有一个带有 Postgres 默认数据库的 Django 应用程序,在 docker 中运行。我还使用 Github actions 作为 CI。当我使用命令在本地运行测试时
docker-compose run --rm app sh -c "python manage.py wait_for_db && pytest -s -v"
Run Code Online (Sandbox Code Playgroud)
一切正常。但是,当我在 GitHub 操作中使用相同的命令时,出现以下错误:
E django.db.utils.OperationalError: connection to server at "postgres" (172.18.0.2), port 5432 failed: Connection refused
E Is the server running on that host and accepting TCP/IP connections?
/usr/local/lib/python3.10/site-packages/psycopg2/__init__.py:122: OperationalError
Run Code Online (Sandbox Code Playgroud)
这是我的 github 工作流程代码:
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions …Run Code Online (Sandbox Code Playgroud) 希望确认这是处理问题的正确方法,以及是否有人有更好的主意。
我已经为 master 分支设置了保护,因此您可以对其进行 PR 并签署提交。
我想自动化 semver 和当前的使用:
- name: Automated Version Bump
id: version-bump
uses: 'phips28/gh-action-bump-version@master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
skip-commit: 'true'
skip-tag: 'true'
Run Code Online (Sandbox Code Playgroud)
通过删除我对分支的保护,目前它可以正常工作。
看起来解决方案是添加Allow specified actors to bypass生成 PAT 并将其用作令牌而不是 GITHUB_TOKEN。
我无法手动将 GITHUB_TOKEN 在该字段中排除,
所以
第一个问题:是否可以将 GITHUB_TOKEN 绕过列表(也许是变量语法或其他什么!)
第二个问题:如果我需要切换,如果这是一个好的解决方案,创建一个新帐户,请通过最低权限等?
我们希望通过 Github Actions 使我们的集成测试能够在 Linux 桌面(ubuntu-latest)上运行。
命令是
flutter config --enable-linux-desktop
flutter test -d linux integration_test
Run Code Online (Sandbox Code Playgroud)
但我们总是得到一个错误:
Error waiting for a debug connection: The log reader stopped unexpectedly, or never started.
//...
TestDeviceException(Unable to start the app on the device.)
package:flutter_tools/src/test/integration_test_device.dart 61:7 IntegrationTestTestDevice.start
Run Code Online (Sandbox Code Playgroud)
Github Actions 是否无法在 CPU 上足够快地处理 GPU/GUI 相关的内容或者发生了什么?这可能吗?我发现只有一个存储库可以为 Linux 环境调用类似的命令。
谢谢!
gui-testing flutter github-actions flutter-linux flutter-integration-test
我在一个名为的存储库中有这个工作流程terraform-do-database,我正在尝试使用来自公共存储库的可重用工作流程foo/git-workflows/.github/workflows/tag_validation.yaml@master
name: Tag Validation
on:
pull_request:
branches: [master]
push:
branches:
- '*' # matches every branch that doesn't contain a '/'
- '*/*' # matches every branch containing a single '/'
- '**' # matches every branch
- '!master' # excludes master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
tag_check:
uses: foo/git-workflows/.github/workflows/tag_validation.yaml@master
Run Code Online (Sandbox Code Playgroud)
这是来自公共存储库的可重用工作流程文件git-workflows,其中包含应在其上运行的脚本。发生的情况是工作流程正在尝试使用存储库内的脚本terraform-do-database
name: Tag Validation
on:
pull_request:
branches: [master]
workflow_call:
jobs:
tag_check:
# The type of …Run Code Online (Sandbox Code Playgroud) 我在 GitHub 存储库中使用两个工作流程。
第一个工作流程由每次推送触发dev,并在新分支内提升版本bump-version并创建新的拉取请求dev。
name: bump-version
on:
push:
branches:
- 'dev'
jobs:
bumpVersionNumber:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: 10
- run: npm ci
- name: Bump Version
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
npm run release
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: bump version
title: Bump version
body: Bump version to reflect release changes
branch: …Run Code Online (Sandbox Code Playgroud) 有没有办法从 GitHub Actions 收集统计信息,例如运行作业中每个步骤所需的时间?通过 GitHub API 还是操作本身?
github-actions ×10
github ×5
automation ×1
django ×1
docker ×1
flutter ×1
git ×1
git-merge ×1
github-api ×1
gui-testing ×1
postgresql ×1
pytest ×1
workflow ×1
yaml ×1