如何在使用GitHub Actions时从远程仓库中检出单个文件夹/文件。

huangapple go评论87阅读模式
英文:

How do i checkout a single folder / file from a remote repo using github actions

问题

  • name: 使用 GitHub Actions Runner 在 Windows 上
  • name: 尝试从远程仓库 betech 的分支 mm365 中仅检出 scripts 文件夹,位于 current-folder\betech 内;但它检出整个仓库内容。
  • name: 配置 Sparse Checkout
  • name: 这是 Sparse Checkout 文件
  • name: 请建议如何仅检出 scripts 文件夹或任何单个文件[如果逻辑有较大不同]
  • name: 更新:
  • name: 我尝试了下面的答案,它有效。
英文:

I'm using github actions runner on windows.

I tried the below to checkout only the scripts folder from remote repo called betech from branch mm365 inside the current-folder\betech; but it checks out the entire repo contents.

  - name: Checkout just the scripts folder
    uses: actions/checkout@v3
    with:
      repository: mytech/betech
      ref: mm365
      path: betech
      token: ${{ secrets.MYGITHUBTOKEN }}

  - name: Configure Sparse Checkout   
    run: |
      echo "scripts/*" >> .git/info.sparse-checkout
      git read-tree -mu HEAD
    working-directory: betech

    env:
      token: ${{ secrets.MYGITHUBTOKEN }}
      secrets: inherit 

here is the sparse file

cat betech\.git\info.sparse-checkout

scripts/*

Can you please suggest how I can checkout only the scripts folder or any single file [If the logic is comparatively different]

*** Update: ***
I tied the below answer and it works.

  - name: Checkout just the scripts folder
    uses: actions/checkout@v3
    with:
      repository: mytech/betech
      ref: mm365
      path: betech
      sparse-checkout: |
        scripts
      sparse-checkout-cone-mode: false
      token: ${{ secrets.MYGITHUBTOKEN }}

答案1

得分: 1

以下是翻译好的部分:

- uses: actions/checkout@v3   
  with:
    sparse-checkout: .
- uses: actions/checkout@v3
  with:
    sparse-checkout: |
      .github
      src      
- uses: actions/checkout@v3
  with:
    sparse-checkout: |
            README.md
    sparse-checkout-cone-mode: false

您还可以使用 checkout-files action 来仅检出特定文件和/或文件夹。此操作使用 Github REST API 下载存储库内容

- name: 检出文件
  uses: Bhacaz/checkout-files@v2
  with:
    files: package.json

在这里,files 是文件列表,路径之间用空格分隔,相对于您存储库的根目录。这也可以是一个文件夹,操作将递归地拉取所有文件。

英文:

The checkout action documentation have few examples demonstrating how to fetch specific files.

> Fetch only the root files
>
> <pre>
> - uses: actions/checkout@v3
> with:
> sparse-checkout: . </pre>
>
> Fetch only the root files and .github and src folder
>
> - uses: actions/checkout@v3
> with:
> sparse-checkout: |
> .github
> src
>
> Fetch only a single file
>
> - uses: actions/checkout@v3
> with:
> sparse-checkout: |
> README.md
> sparse-checkout-cone-mode: false

You can also use checkout-files action to checkout only certain files and/or folders. This action uses Github REST API to download the repository content.

- name: Checkout files
  uses: Bhacaz/checkout-files@v2
  with:
   files: package.json

Here the files is a list of files with the path separated by a space, relative to root of your repository. This can also be a folder and the action will recursively pull all the files.

huangapple
  • 本文由 发表于 2023年6月19日 13:38:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76503858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定