This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
forked from snow-actions/sparse-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
166 lines (149 loc) · 5.3 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: 'Sparse checkout action'
description: 'Sparse checkout a git repository'
branding:
icon: 'minimize-2'
color: 'gray-dark'
inputs:
# Sparse checkout
patterns:
description: >
Write a set of patterns to the sparse-checkout file.
[Learn more about set](https://git-scm.com/docs/git-sparse-checkout#Documentation/git-sparse-checkout.txt-emsetem)
required: true
# Same as actions/checkout
repository:
description: 'Repository name with owner. For example, snow-actions/sparse-checkout'
default: ${{ github.repository }}
required: false
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
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)
default: ${{ github.token }}
required: false
path:
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
default: '.'
required: false
runs:
using: composite
steps:
- name: Setting git path
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
echo "GIT=/usr/local/bin/git" >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "Windows" ]; then
echo "GIT=/cmd/git" >> $GITHUB_ENV
else
echo "GIT=/usr/bin/git" >> $GITHUB_ENV
fi
shell: bash
- name: Creating directory
run: |
if [ -n "$DIRECTORY" ]; then
/bin/mkdir -p $DIRECTORY
fi
env:
DIRECTORY: ${{ inputs.path }}
shell: bash
- name: Getting Git version info
run: |
echo "::group::Getting Git version info"
$GIT version
echo "::endgroup::"
shell: bash
- name: Initializing the repository
run: |
echo "::group::Initializing the repository"
$GIT init
$GIT remote add origin ${GITHUB_SERVER_URL/https:\/\//https:\/\/x-access-token:${TOKEN}@}/${REPOSITORY}
#$GIT remote add origin ${GITHUB_SERVER_URL}/${REPOSITORY}
$GIT remote -v
echo "::endgroup::"
env:
REPOSITORY: ${{ inputs.repository }}
TOKEN: ${{ inputs.token }}
working-directory: ${{ inputs.path }}
shell: bash
- name: Disabling automatic garbage collection
run: |
echo "::group::Disabling automatic garbage collection"
$GIT config --local gc.auto 0
echo "::endgroup::"
working-directory: ${{ inputs.path }}
shell: bash
# This doesn't work. What is wrong?
# - name: Setting up auth
# run: |
# echo "::group::Setting up auth"
# BASIC_CREDENTIAL=$(echo "x-access-token:${TOKEN}" | base64 -w0)
# echo "::add-mask::${BASIC_CREDENTIAL}"
# $GIT config --local http.${GITHUB_SERVER_URL}/.extraHeader "AUTHORIZATION: basic ${BASIC_CREDENTIAL}"
# echo "::endgroup::"
# env:
# TOKEN: ${{ inputs.token }}
# shell: bash
- name: Setting up sparse checkout
run: |
echo "::group::Setting up sparse checkout"
$GIT sparse-checkout init --cone --sparse-index
$GIT sparse-checkout set $PATTERNS
echo "::endgroup::"
env:
PATTERNS: ${{ inputs.patterns }}
working-directory: ${{ inputs.path }}
shell: bash
- name: Fetching the repository
run: |
echo "::group::Fetching the repository"
if [ -z "$REF" ]; then
if [ "$REPOSITORY" == "$GITHUB_REPOSITORY" ]; then
REF="${GITHUB_REF#refs/heads/}"
else
REF=$(gh api repos/$REPOSITORY --jq '.default_branch')
fi
fi
$GIT -c protocol.version=2 fetch --no-tags --prune --progress
# $GIT -c protocol.version=2 fetch --no-tags --prune --progress --depth=1 origin +${REF}:refs/remotes/origin/${REF}
echo "::endgroup::"
env:
REF: ${{ inputs.ref }}
REPOSITORY: ${{ inputs.repository }}
GH_TOKEN: ${{ inputs.token }}
working-directory: ${{ inputs.path }}
shell: bash
- name: Checking out the ref
run: |
echo "::group::Checking out the ref"
# FIXME: duplication with fetch
echo $REF
if [ -z "$REF" ]; then
if [ "$REPOSITORY" == "$GITHUB_REPOSITORY" ]; then
REF="${GITHUB_REF#refs/heads/}"
else
REF=$(gh api repos/$REPOSITORY --jq '.default_branch')
fi
fi
echo $REF
$GIT pull origin $REF
echo "::endgroup::"
env:
REF: ${{ inputs.ref }}
REPOSITORY: ${{ inputs.repository }}
GH_TOKEN: ${{ inputs.token }}
working-directory: ${{ inputs.path }}
shell: bash
- name: Logging commit sha
run: $GIT log -1 --format='%H'
working-directory: ${{ inputs.path }}
shell: bash