我们如何在多个分支上运行多个触发器的 github 工作流程?示例 - 如何在pull_request&push上运行工作流程prod& dev?参考下面的代码片段
on: [push, pull_request]
branches:
- 'dev'
- 'prod'
Run Code Online (Sandbox Code Playgroud)
以上是不允许的。我收到以下错误 -
Property branches is not allowed.yaml-schema: GitHub Workflow
Run Code Online (Sandbox Code Playgroud)
我该如何处理这个问题?
我在有Org两个不同存储库repo-1和repo-2.
我已将大约 50 个奇怪的 Maven 依赖项上传到 的 GitHub Packages 注册表repo-1,现在我们正在迁移到repo-2. pom.xml 和所有 GitHub Actions 工作流程都按原样复制。因此,我需要访问repo-2Maven 构建工作流程的同一组依赖项。但是,repo-2 无法从repo-1Packages 注册表下载依赖项。
工作流程片段:
- name: build
run: mvn clean package '-Dmaven.test.skip=true' '-Dmaven.wagon.http.pool=false' --file pom.xml -B -X
env:
GITHUB_TOKEN: ${{ github.token }}
MAVEN_OPTS: -Xmx3072M -Xss128M -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=2048M -XX:+CMSClassUnloadingEnabled
Run Code Online (Sandbox Code Playgroud)
pom.xml 中的存储库配置片段:
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>1_maven.apache.org</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout> …Run Code Online (Sandbox Code Playgroud) 我想创建一个 JavaScript Github 操作并使用 Jest 进行测试。根据文档,我开始解析输入,给出以下示例代码
import { getInput } from '@actions/core';
const myActionInput = getInput('my-key', { required: true });
Run Code Online (Sandbox Code Playgroud)
在开发过程中运行此代码会引发以下错误
需要输入但未提供:my-key
正如预期的那样,因为代码没有在 Github 操作环境中运行。但是否可以为此创建测试?例如
describe('getMyKey', () => {
it('throws if the input is not present.', () => {
expect(() => getMyKey()).toThrow();
});
});
Run Code Online (Sandbox Code Playgroud)
如何使用上下文“伪造”/模拟这样的环境,以确保我的代码按预期工作?
我有一个操作,可以在提交到 master 时和拉取请求时对代码进行 lint 并运行测试:
name: My Action
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16
uses: actions/setup-node@v2
with:
node-version: 16
- run: npm install
- run: npm run lint
- run: npm test
Run Code Online (Sandbox Code Playgroud)
我想在最后添加一个“部署”步骤,该步骤仅在提交到 master 触发操作时运行,而不是在拉取请求时运行(理想情况下,如果 linting 不成功,则不会运行)。我只需要制作两个单独的文件吗?
我有一个私有 GitHub 存储库,其中有一个 GitHub Action,它将在 Action 运行时创建的文件推送到存储库。从昨天(2022-04-12)开始,操作在以下步骤失败:
- name: Push data to repo
uses: github-actions-x/commit@v2.8
with:
push-branch: 'main'
commit-message: 'Add current data'
force-add: 'true'
files: *.zip
name: autoupdate
Run Code Online (Sandbox Code Playgroud)
运行此步骤会触发以下错误消息:
Command line: | /usr/bin/git checkout -B main
Stderr: | fatal: unsafe repository ('/github/workspace' is owned by someone else)
| To add an exception for this directory, call:
|
| git config --global --add safe.directory /github/workspace
Run Code Online (Sandbox Code Playgroud)
根据错误消息,我将以下内容添加到我的 GitHub Action 中:
- name: Fix issue with repository ownership
run: |
git config --global …Run Code Online (Sandbox Code Playgroud) 我们有两个运行程序,一个用于运行生产作业,另一个用于运行非生产作业,但我无法使用工作流程级别环境变量来做到这一点。
以下是我所拥有的:
name: Workflow file
on:
workflow-dispatch
env:
RUNNER_NAME: ${{ contains(github.ref, 'main') && 'Prod Runner' || 'non-Prod Runner' }}
jobs:
job-run:
runs-on: [${{ env.RUNNER_NAME }}]
needs: ...
steps:
..........
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
工作流程文件无效
You have an error in your yaml syntax on line ###
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?我不想为产品和非产品工作流程提供单独的工作流程文件。
我有一个使用 terraform 在 AWS 上部署的 GitHub 工作流程,但我很难传递 terraform 变量。
\n以下步骤失败,因为 can\xe2\x80\x99t 找不到在 Variables.tf 中定义的变量
\n- name: Terraform Plan\n id: plan\n if: github.event_name == 'pull_request'\n env:\n ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}\n ECR_REPOSITORY: ${{ secrets.ECR_REPO }}\n django_secret_key: ${{ secrets.TF_VAR_DJANGO_SECRET_KEY }}\n admin: ${{ secrets.TF_VAR_ADMIN }}\n admin_email: ${{ secrets.TF_VAR_ADMIN_EMAIL }}\n admin_password: ${{ secrets.TF_VAR_ADMIN_PASSWORD }}\n db_username: ${{ secrets.TF_VAR_DB_USERNAME }}\n db_password: ${{ secrets.TF_VAR_DB_PASSWORD }}\n run: |\n export ecr_image_api=$ECR_REGISTRY/$ECR_REPOSITORY:dev\n terraform init\n terraform workspace select staging || terraform workspace new staging\n terraform plan -no-color -input=false\n continue-on-error: true\n …Run Code Online (Sandbox Code Playgroud) 我有一个 Rails 7.0.3 应用程序,其模型具有加密属性。我有一个 RSpec 测试来测试模型的行为。我有一个运行 RSpec 的 GitHub Actions 工作流程设置。但是:特定提交的每次第一次运行都会失败,而接下来的每次运行都会成功。作为
\n错误:
\nActiveRecord::Encryption::Errors::Configuration:\n key_derivation_salt is not configured. Please configure it via credential active_record_encryption.key_derivation_salt or by setting config.active_record.encryption.key_derivation_salt\nRun Code Online (Sandbox Code Playgroud)\nGitHub 操作配置(为简洁起见,省略了非必要的细节):
\nActiveRecord::Encryption::Errors::Configuration:\n key_derivation_salt is not configured. Please configure it via credential active_record_encryption.key_derivation_salt or by setting config.active_record.encryption.key_derivation_salt\nRun Code Online (Sandbox Code Playgroud)\n我在回购配置中有秘密设置:
\n\n必要的加密配置存储在test.enc.yml:
name: CI\non: [push]\njobs:\n rspec:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v1\n - name: Set up Ruby\n uses: ruby/setup-ruby@v1\n with:\n …Run Code Online (Sandbox Code Playgroud) encryption rspec ruby-on-rails rails-activerecord github-actions
React 项目旨在托管在 Firebase 托管服务上。我按照说明操作并成功部署了我想要的版本。它还询问我是否想将该项目与 Github Workflow 结合起来。这意味着它将pull我的项目main分支并merge(自动部署)到 firebase、构建并完成部署。
这里的问题是 React 文件夹位于./frontend目录中,而不是根目录中。弹出的第一个错误是:
Verifying firebase.json exists
Error: firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this GitHub action.
Run Code Online (Sandbox Code Playgroud)
屁股建议说我entrypoint向...-merge.yml和...pull-request.yml文件添加了变量:
Verifying firebase.json exists
Error: firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this …Run Code Online (Sandbox Code Playgroud) Github 提供了秘密,其值可以在工作流程中使用。不幸的是,秘密的值受到保护,我们无法在存储库中轻松看到它,也无法在工作流程中调试它,因为它被清除了。
有没有办法在存储库中定义一个可以轻松查看和调试的“环境变量”?我的用例是在存储库被分叉时可以轻松修改的配置。
github-actions ×10
github ×4
encryption ×1
firebase ×1
git-push ×1
github-actions-self-hosted-runners ×1
javascript ×1
jestjs ×1
node.js ×1
reactjs ×1
repository ×1
rspec ×1
terraform ×1
workflow ×1