是否可以使用 GitHub Actions 表达式有条件地连接字符串?
例如,就像我在下面的示例中尝试做的那样。
- name: Release
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist ${{ if (startsWith(github.ref, 'refs/tags/')) { '--snapshot' }}
Run Code Online (Sandbox Code Playgroud) 我创建了一个 Github 工作流程,该工作流程使用 cron 计划运行 python 脚本。工作流的每次运行都会生成 access_token,下一次运行时需要该令牌。
为了保存令牌,Python 脚本将令牌写入文件GITHUB_ENV。在下一步中,我使用该hmanzur/actions-set-secret@v2.0.0操作将令牌保存到 Github Secret。一切正常。
我唯一的问题是,令牌作为环境变量显示在第二步的日志中。
这是工作流程文件的最小版本:
name: Tests
on:
schedule:
- cron: "0 1 * * *"
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.9']
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
working-directory: ./src
run: python -m unittest
env:
ACCESS_TOKEN: ${{secrets.ACCESS_TOKEN}}
- uses: hmanzur/actions-set-secret@v2.0.0
with:
name: 'ACCESS_TOKEN'
value: ${{env.ACCESS_TOKEN}}
repository: …Run Code Online (Sandbox Code Playgroud) 可重用的工作流程应在顶级“jobs.*.uses”键处引用,而不是在步骤内引用
name: HelloWorld
on:
workflow_dispatch:
jobs:
checkout:
runs-on: windows-latest
steps:
- name: Checkout using the Template File
uses: actions/checkout@v2
- name: Compile Java
uses: org/repo/.github/workflows/build.yml@main
with:
jdk_version: 11
Run Code Online (Sandbox Code Playgroud)
错误:.github#L1 可重用工作流程应在顶级 `jobs.*.uses' 键处引用,而不是在步骤内引用
我想运行一个通知作业,让我知道我的工作流程失败了,有没有办法做到这一点,而不必执行needs每项作业并检查每项作业的状态?
这就是我现在必须这样做的方式,但如果我有大量工作,它会变得很麻烦:
jobs:
first-job:
runs-on: ubuntu-20.04
steps:
- exit 0
second-job:
runs-on: ubuntu-20.04
steps:
- exit 1
notify-job:
runs-on: ubuntu-20.04
needs: [first-job, second-job]
if: ${{ always() && (needs.first-job.result == 'failure' || needs.second-job.result == 'failure') }}
steps:
- ./notify.sh
Run Code Online (Sandbox Code Playgroud)
我想简单地检查工作流程最后是否以任何身份失败,即如果任何作业失败,这可能吗?
我看到此文档来检查触发工作流程是否失败(https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-另一个工作流程的结论)。
有没有办法在当前工作流程结束时运行finally或状态检查?ensure
我在 GitHub Action 中遇到了奇怪的行为workflow_call。
基本上,初始设置后一切正常,但是当我编辑工作流程文件的输入参数时,它不使用更新的值。很难用语言来解释,所以让我给你举个例子。
考虑这个基本设置:
文件:start-pipeline.yml
name: Start Pipeline
on:
workflow_dispatch:
inputs:
release_type:
required: true
type: choice
options:
- patch
- minor
- major
jobs:
call-sub-workflow:
uses: codezalot/workflow-call-issue/.github/workflows/sub-workflow.yml@main
with:
release_type: ${{ github.event.inputs.release_type }}
Run Code Online (Sandbox Code Playgroud)
文件:子工作流程.yml
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
Run Code Online (Sandbox Code Playgroud)
然后,我使用值补丁启动管道,子工作流程会很好地打印输入:

然后,我更新工作流程文件并添加额外的输入值,如下所示:
文件:start-pipeline.yml
...
jobs:
call-sub-workflow:
uses: codezalot/workflow-call-issue/.github/workflows/sub-workflow.yml@main
with:
release_type: ${{ …Run Code Online (Sandbox Code Playgroud) In the settings I've enabled Github Pages:
I have a Github Action which builds and deploy the page to the branch gh-pages.
name: Continuous Deployment
on:
push:
branches:
- master
schedule:
- cron: '0 0 * * *'
jobs:
build-and-deploy:
name: Build and deploy to Github Pages
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use nodejs
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache …Run Code Online (Sandbox Code Playgroud) 最近我遇到了一个问题https://github.com/kkohtaka/gh-actions-pr-size/issues/9,它有一个可能的解决方案contents: write,即为我的工作添加权限:
permissions:
contents: write
...
Run Code Online (Sandbox Code Playgroud)
我试图在https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs中找到它的解释,但发现只支持像contents: read|write|none.
contents: writeGitHub 工作流程中的权限是什么?它能带来什么?
我正在尝试在由 github 操作创建的 ssh 连接中运行 docker 命令。我什至在工作流程中使用了提及。这是我的工作流程
\n# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node\n# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions\n\nname: Node.js CI\n\non:\n pull_request:\n branches: ['main']\n\nenv:\n REGISTRY: 'ghcr.io/testing/api-gateway'\n IMAGE_NAME: ${{ format('{0}-{1}', github.event.repository.name, github.sha) }}\n USERNAME: ${{ secrets.USERNAME }}\n DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}\n\njobs:\n build:\n runs-on: ubuntu-latest\n\n strategy:\n matrix:\n node-version: [16.x]\n\n steps:\n - uses: actions/checkout@v3\n\n - name: Use Node.js ${{ matrix.node-version }}\n uses: actions/setup-node@v3\n with:\n …Run Code Online (Sandbox Code Playgroud) 我正在通过 Github 操作构建我的公司项目之一,在该项目中我们正在运行最新提出的拉取请求的工作流程。我注意到一件事,每当它尝试从主存储库执行秘密时,它都会给出错误的凭据错误。当我尝试从主存储库运行同一阶段时,它工作正常。我们是否已授予一些权限来拉取请求以从主存储库调用秘密。
任何建议都会有所帮助。