-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
154 lines (136 loc) · 4.83 KB
/
action.yaml
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
---
name: 'Data transfer action'
description: |
This action transfers data to/from artefact storage
branding:
icon: package
color: purple
inputs:
checkout:
description: 'Do a Git checkout before transferring, either: `true` or `false`; defaults to `false`'
default: 'false'
checkout-fetch-depth:
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags'
default: 1
checkout-lfs:
description: 'Whether to download Git-LFS files'
default: 'false'
direction:
description: 'Direction of transfer, either: `upload` or `download`'
required: true
if-no-files-found:
description: >
The desired behavior if no files are found using the provided path.
Available Options:
warn: Output a warning but do not fail the action
error: Fail the action with an error message
ignore: Do not output any warnings or errors, the action does not fail
default: 'error'
name:
description: 'Artifact name: defaults to `checkout` if checkout input is `true`, otherwise, please provide a value'
path:
description: |
⚠️ Conditional defaults!
- if `checkout` is `true`; then defaults to `./.git/`
- if `checkout` is `false`; then defaults to `./`
Additionally, the meaning of `path` is:
- if direction is `upload`: a file, directory or wildcard pattern that describes what to upload;
- if direction is `download`: destination path
outputs:
name:
description: 'Artifact name'
value: ${{ steps.verify.outputs.name }}
runs:
using: "composite"
steps:
- id: verify
name: Verify inputs 🔎
shell: bash
env:
CHECKOUT: ${{ inputs.checkout }}
DIRECTION: ${{ inputs.direction }}
NAME: ${{ inputs.name }}
DIR_PATH: ${{ inputs.path }}
LFS: ${{ inputs.checkout-lfs }}
run: |
set -euo pipefail
if [[ "${LFS}" != 'false' ]] ; then
echo "🛑 sorry, LFS functionality not yet implemented"
exit 255
fi
if [[ "${CHECKOUT}" != 'true' && "${CHECKOUT}" != 'false' ]] ; then
echo "🛑 checkout input set to '${CHECKOUT}', should be either 'true' or 'false'"
exit 1
fi
if [[ "${DIRECTION}" != 'upload' && "${DIRECTION}" != 'download' ]] ; then
echo "🛑 direction input set to '${DIRECTION}', should be either 'upload' or 'download'"
exit 2
fi
if [[ -n "${NAME:-}" ]] ; then
echo "name=${NAME}" >> $GITHUB_OUTPUT
else
if [[ "${CHECKOUT}" == 'true' ]] ; then
echo "name=checkout" >> $GITHUB_OUTPUT
else
echo "🛑 name input has not been provided, need a value"
exit 3
fi
fi
if [[ -n "${DIR_PATH:-}" ]] ; then
echo "path=${DIR_PATH}" >> $GITHUB_OUTPUT
else
if [[ "${CHECKOUT}" == 'true' ]] ; then
echo "path=./.git/" >> $GITHUB_OUTPUT
else
echo "path=./" >> $GITHUB_OUTPUT
fi
fi
- id: clone
if: inputs.checkout == 'true' && inputs.direction == 'upload'
name: Clone repo ⧉
uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.checkout-fetch-depth }}
- id: prepare-dot-git
if: inputs.checkout == 'true' && inputs.direction == 'upload'
name: Remove index 🗑
shell: bash
run: |
set -euo pipefail
rm -f .git/index
- id: transfer-up
if: inputs.direction == 'upload'
name: Transfer data to GitHub 🆙
uses: actions/upload-artifact@v4
with:
if-no-files-found: ${{ inputs.if-no-files-found }}
name: ${{ steps.verify.outputs.name }}
path: ${{ steps.verify.outputs.path }}
retention-days: 1
include-hidden-files: true
- id: transfer-down
if: inputs.direction == 'download'
name: Transfer data from GitHub ⬇️
uses: actions/download-artifact@v4
with:
name: ${{ steps.verify.outputs.name }}
path: ${{ steps.verify.outputs.path }}
- id: checkout
if: inputs.checkout == 'true' && inputs.direction == 'download'
name: Checkout repo 🛒
shell: bash
run: |
set -euo pipefail
# Compatibility with pull request triggers
if [[ -n "${{ github.head_ref }}" ]] ; then # if `head_ref` set, then it's a pull request
export ref="refs/remotes/pull/${{ github.ref_name }}"
export ref_name="${{ github.head_ref }}"
else
export ref="${{ github.ref }}"
export ref_name="${{ github.ref_name }}"
fi
if [[ "${{ github.ref_type }}" == 'branch' && -z "${{ github.head_ref }}" ]] ; then
git checkout --progress --force -B "${ref_name}" "${ref}"
else
git checkout --progress --force "${ref}"
fi