forked from nschloe/action-cached-lfs-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
106 lines (98 loc) · 3.97 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: "Cached LFS checkout"
description: "Git checkout with LFS files from cache"
branding:
icon: "download"
color: "green"
inputs:
include:
description: "Explicitly include files for LFS"
required: false
default: "*"
exclude:
description: "Explicitly exclude files for LFS"
required: false
default: ""
fetch-depth:
description: "Number of commits to fetch. 0 indicates all history for all tags and branches"
required: false
default: 1
ref:
description: >
The branch, tag or SHA to checkout. When checking out the repository that
triggered a workflow, this defaults to the reference or SHA for that
event. Otherwise, uses the default branch.
required: false
default: ""
repository:
description: "Repository name with owner. For example, actions/checkout"
default: ${{ github.repository }}
token:
description: >
Personal access token (PAT) used to fetch the repository. The PAT is configured
with the local git config, which enables your scripts to run authenticated git
commands. The post-job step removes the PAT.
We recommend using a service account with the least permissions necessary.
Also when generating a new PAT, select the least scopes necessary.
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
required: false
default: ${{ github.token }}
submodules:
description: >
Whether to checkout submodules: `true` to checkout submodules or `recursive` to
recursively checkout submodules.
required: false
default: false
persist-credentials:
description: >
'Whether to configure the token or SSH key with the local git config'
required: false
default: true
enableCrossOsArchive:
description: >
Whether the cache is cross-os compatible. This is useful to cache dependencies which
are independent of the runner platform. This will help reduce the consumption of the
cache quota and help build for multiple platforms from the same cache.
[Learn more about cross-os caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache).
required: false
default: false
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.fetch-depth }}
ref: ${{ inputs.ref }}
repository: ${{ inputs.repository }}
token: ${{ inputs.token }}
submodules: ${{ inputs.submodules }}
persist-credentials: ${{ inputs.persist-credentials }}
- name: Create LFS file list
run: |
hash=$({
git lfs ls-files --long --include "${{ inputs.include }}" --exclude "${{ inputs.exclude }}" | cut -d ' ' -f1
git submodule foreach --quiet 'git lfs ls-files --long --include "${{ inputs.include }}" --exclude "${{ inputs.exclude }}" | cut -d " " -f1 | sed -e "s#^#${sm_path}/#"'
} | sort | sha256sum - | cut -d ' ' -f1)
echo "hash=$hash" >> $GITHUB_OUTPUT
id: cache-hash
shell: bash
- name: Create Submodule LFS Cache Paths
run: |
paths='.git/lfs'
while read line; do
paths+=$'\n'".git/modules/$line/lfs"
done < <(git submodule foreach --quiet 'echo $name')
printf 'paths<<EOF\n%s\nEOF\n' "$paths" >> "$GITHUB_OUTPUT"
id: cache-paths
shell: bash
- name: Restore LFS cache
uses: actions/cache@v4
with:
path: '${{ steps.cache-paths.outputs.paths }}'
key: ${{ runner.os }}-lfs-${{ steps.cache-hash.outputs.hash }}-v1
enableCrossOsArchive: ${{ inputs.enableCrossOsArchive }}
- name: Git LFS Pull
run: |
git lfs pull --include "${{ inputs.include }}" --exclude "${{ inputs.exclude }}"
git submodule foreach git lfs pull --include "${{ inputs.include }}" --exclude "${{ inputs.exclude }}"
shell: bash