forked from nschloe/action-cached-lfs-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
118 lines (107 loc) · 4.44 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
107
108
109
110
111
112
113
114
115
116
117
118
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: |
git lfs ls-files --long --include "${{ inputs.include }}" --exclude "${{ inputs.exclude }}" | cut -d ' ' -f1 > .lfs-assets-id-unsorted
git submodule foreach git lfs ls-files --long --include "${{ inputs.include }}" --exclude "${{ inputs.exclude }}" | cut -d ' ' -f1 >> .lfs-assets-id-unsorted
cat .lfs-assets-id-unsorted | sort > .lfs-assets-id
shell: bash
- name: Create Submodule LFS Cache Paths
run: |
CACHE_PATHS=""
# loop over the git submodule paths to generate a list of module directories to cache
# `git config` is used to extract the `path` value for each git submodule
# for more information about the .gitmodules file, see: https://git-scm.com/docs/gitmodules
while read line; do
CACHE_PATHS+=".git/modules/$line/lfs "
done < <(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
echo "CACHE_PATHS=$CACHE_PATHS" >> $GITHUB_OUTPUT
id: cache-paths
shell: bash
- name: Restore LFS cache
uses: actions/cache@v4
id: lfs-cache
with:
path: |
.git/lfs
${{ steps.cache-paths.outputs.CACHE_PATHS }}
key: lfs-${{ hashFiles('.lfs-assets-id') }}-v2
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
# Don't leave behind temp files in case build system checks for dirty workspace
- name: Cleanup Temp Files
run: |
rm .lfs-assets-id-unsorted
rm .lfs-assets-id
shell: bash