英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论