能够通过复制粘贴 link URL 到 curl 来下载 Github Actions 工件吗?

Being able to download a Github Actions artifact by copy-past the link URL to curl?

我们正在进行概念验证,以研究 Github 为遗留系统的给定提交生成工件的操作,然后我们需要在内部进一步处理,所以我正在研究如何我们现在可以相对简单地做到这一点,以证明这是可行的。我们对拉链包装没意见。

此类工件的示例 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

我希望能够避免为此概念验证创建 API 客户端,而是允许用户从网页中传入 link,但是我一直找不到这样做的简单方法。

所以问题是,我如何用最少的编码从 https://github.com/tandeday/actions-artifacts/suites/1767549169/artifacts/33720037https://api.github.com/repos/tandeday/actions-artifacts/actions/artifacts/33720037/zip

如果您同意开源您的存储库(如果不同意,请在此答案中进一步向下滚动),如果您创建一个在每次提交时创建发布的工作流,然后构建,则无需进行身份验证即可执行此操作你的工件,然后将该工件上传到版本。诀窍是巧妙地使用发布标签的名称,该名称在发布 URL 中使用。描述了一个示例工作流程 here。我稍微修改了它以匹配您的示例 repo 的场景,而是使用标签名称中提交哈希的前 8 个字符来生成可预测但唯一的 URL:

on:
  push:
    # Runs on every pushed commit

name: Upload Release Asset

jobs:
  build:
    name: Upload Release Asset
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

        # For the sake of simplicity, we'll name the tag and the release with
        # the first 8 chars of the commit SHA:
      - name: Get short SHA
        id: short_sha
        run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"

      - name: Build project # This would actually build your project, using zip for your example date artifact
        run:  |
          date > date.txt
          zip -rT app.zip date.txt
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          # Using short SHA from 2nd step for tag and release name.
          tag_name: ${{steps.short_sha.outputs.sha8}}
          release_name: ${{steps.short_sha.outputs.sha8}}
          draft: false
          prerelease: false
        # Now we upload the artifact we generated in the first step to
        # the release we created in the 3nd step
      - name: Upload Release Asset
        id: upload-release-asset 
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing its ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 
          asset_path: ./app.zip
          asset_name: app.zip
          asset_content_type: application/zip

然后,最后,您的资产将以 URL 的模式可用:github.com/orgname/reponame/releases/download/${short_sha}/app.zip,其中 short_sha 是您提交的前 8 个字符。由于它具有这种已知格式,因此如果内部用户有权访问存储库(从存储库中提取,在头部获取 SHA,进行一些字符串插值,打印 URL 到控制台)。

Test repo workflow

Test release asset

如果您的回购必须在您的组织内保密:

有人编写了一个 nice Gist 和一些 shell 脚本来从私人仓库中获取一个版本 - 你需要一个访问令牌。

如果你不想污染你的 repo 的发布:

您可以修改上述工作流程的 tag_namerelease_name 以包含 intermediate 前缀,这样很明显它不是实际版本。不过,如果您选择这条路线,您的 URL 格式会有所不同 - /download/ 之后的位将是您的新标签名称。