在调查如何在 github 操作中,我可以将存储库中特定文件的“基本”版本与文件的拉取请求(“头”)版本进行比较......在调查这一点时,我发现了各种来源(例如,github.community和github.com/actions/checkout README 文件中的代码示例)...我发现以下上下文变量可用:
github.refgithub.shagithub.event.pull_request.head.refgithub.event.pull_request.head.shagithub.event.pull_request.base.refgithub.event.pull_request.base.sha但是,除了前两个(github.ref和github.sha)之外,我在任何 github actions 文档中都找不到其他四个。
我的问题是: 是否有任何地方记录了可用上下文变量的完整列表?
例如,我找到了 this,但它只列出了 github 上下文对象下一级的上下文变量。我找不到上述更深层嵌套变量的文档。可能还有其他可能非常有用的上下文变量,但我似乎找不到完整的列表,而只是那些碰巧被提及并分散在各种代码示例中的变量。
这是我的 GitHub Action 步骤。PRIVATE_REQUIREMENT_OWNER_TOKENSecret 已创建并包含具有完整repo范围的 GitHub 令牌:
- name: Build docker image
id: docker_build
uses: docker/build-push-action@v2
with:
push: false
context: .
tags: 'username/image:latest'
secrets: |
"github_token=${{ secrets.PRIVATE_REQUIREMENT_OWNER_TOKEN }}"
Run Code Online (Sandbox Code Playgroud)
这是requirements.txt 中的一行,其中包含指向私有存储库的链接,并在上述步骤中从 Dockerfile 构建 docker 映像时尝试安装:
git+ssh://git@github.com/username/private-repository
Run Code Online (Sandbox Code Playgroud)
该行已添加到Dockerfile
RUN --mount=type=secret,id=github_token pip install https://$(cat /run/secrets/github_token)@github.com/username/private-repository.git
Run Code Online (Sandbox Code Playgroud)
这会在 GitHub Actions 中引发以下错误:
#11 [ 6/12] RUN --mount=type=secret,id=PRIVATE_REQUIREMENT_OWNER_TOKEN_SECRET pip install https://$(cat /run/secrets/PRIVATE_REQUIREMENT_OWNER_TOKEN_SECRET)@github.com/username/private-repository.git
#11 sha256:b3d88dd9813db3257b15f53f1eb5a4c593c69ff98ec03cc4d70d564df1a1f7f6
#11 0.697 Collecting https://****@github.com/vassilyvv/django-sinbad.git
#11 0.790 ERROR: HTTP error 404 while getting https://****@github.com/username/private-repository
.git
#11 0.791 ERROR: Could …Run Code Online (Sandbox Code Playgroud) 我们正在做一个概念验证,研究 Github Actions 来为遗留系统的给定提交生成一个工件,然后我们需要在内部进一步处理它,所以我正在研究我们现在如何相对简单地做到这一点证明这是可行的。我们对拉链包装没问题。
通过在操作中的作业页面中右键单击工件来识别此类工件的示例 URL: https://github.com/tandeday/actions-artifacts/suites/1767549169/artifacts/33720037
据我所知,有一个完整的 API,并且我已经成功地手动使用它来本地化和下载工件,使用类似于以下内容的行:
curl -O -J -L -H 'Authorization: token ...' -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/tandeday/actions-artifacts/actions/artifacts/33720037/zip
Run Code Online (Sandbox Code Playgroud)
我希望能够避免为此概念验证创建 API 客户端,而是允许用户仅从网页传递链接,但我一直无法找到一种简单的方法来做到这一点。
所以问题是,我如何以最少的编码从https://github.com/tandeday/actions-artifacts/suites/1767549169/artifacts/33720037到https://api.github.com/repos/tandeday/动作-工件/动作/工件/33720037/zip?
长话短说:
如何手动ACTIONS_RUNTIME_TOKEN和 ACTIONS_CACHE_URL在 GitHub 中查找操作?
语境
我正在尝试在 GitHub 操作中的 buildkit 构建过程中缓存 docker 层。
理论上,使用docker/setup-buildx-action、docker/build-push-action和crazy-max/ghaction-github-runtime操作很容易。问题是,我不能使用它们(组织政策)。
我的工作流程的相关部分现在是:
$repo_url= "<ECR repo in aws>"
docker buildx create --use --driver=docker-container
docker buildx build --tag "${repo_url}:latest" --file docker/Dockerfile . --cache-to "type=gha,mode=max" --cache-from type=gha
Run Code Online (Sandbox Code Playgroud)
缓存需要 2 个变量/配置:ACTIONS_RUNTIME_TOKEN和
ACTIONS_CACHE_URL。它们将由 来设置ghaction-github-runtime,因此我无法使用。查看代码,似乎从环境中导出了2个变量,但我找不到它们。
我如何在没有其他操作帮助的情况下手动找到它们?
caching docker github-actions docker-buildkit github-actions-artifacts
我正在尝试使用 GitHub Actions 来构建完整的管道,包括自动 SemVer 版本控制(使用标签),然后我希望在构建 Docker 映像后使用它来使用当前版本对其进行标记。这是我用来提升版本的操作,它应该有一个 new_tag 输出,但我无法引用它,这就是我正在尝试的:
jobs:
setup:
...
version:
needs: [setup]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.26.0
id: autoversion
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
sonar:
...
anchore:
...
docker:
needs: [setup, version]
steps:
...
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ansfire/flaskql:${{ needs.version.autoversion.outputs.new_tag }}
Run Code Online (Sandbox Code Playgroud)
根据我所读到的内容,使用needs密钥应该允许一个作业访问上游作业,但我无法让它访问它。outputs我在舞台上需要钥匙吗version?谢谢!