Skip to content

Commit 1c9ba64

Browse files
authored
Merge pull request #4 from reecetech/DE-5249-improve
Reduce transfer size of `checkout` mode transfers
2 parents c38e19e + df96f6d commit 1c9ba64

File tree

3 files changed

+114
-32
lines changed

3 files changed

+114
-32
lines changed

.github/workflows/test-and-release.yml

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,41 @@ jobs:
2828
- id: checkout
2929
name: Checkout code 🛒
3030
uses: actions/checkout@v3
31+
with:
32+
path: transfer-action
33+
34+
- id: create-file
35+
name: Create a file 🆕
36+
shell: bash
37+
run: |
38+
set -euo pipefail
39+
touch foo
40+
41+
- id: given-upload
42+
name: Upload a given file 📤
43+
uses: ./transfer-action/
44+
with:
45+
direction: 'upload'
46+
name: 'foo'
47+
path: './foo'
3148

3249
- id: checkout-upload
3350
name: Checkout and upload 📦
34-
uses: ./
51+
uses: ./transfer-action/
3552
with:
3653
checkout: 'true'
3754
direction: 'upload'
55+
56+
- id: checkout-again
57+
# have to do this because the `checkout-upload` step cleans the working dir
58+
name: Checkout code (again) 🛒
59+
uses: actions/checkout@v3
60+
with:
61+
path: transfer-action
62+
3863
outputs:
39-
name: ${{ steps.checkout-upload.outputs.name }}
64+
checkout-name: ${{ steps.checkout-upload.outputs.name }}
65+
given-name: ${{ steps.given-upload.outputs.name }}
4066

4167
test-down:
4268
runs-on: ubuntu-latest
@@ -45,21 +71,42 @@ jobs:
4571
- id: checkout
4672
name: Checkout code 🛒
4773
uses: actions/checkout@v3
74+
with:
75+
path: transfer-action
4876

4977
- id: checkout-download
5078
name: Download checkout 📥
51-
uses: ./
79+
uses: ./transfer-action/
5280
with:
81+
checkout: 'true'
5382
direction: 'download'
54-
name: ${{ needs.test-up.outputs.name }}
55-
path: 'download/'
83+
name: ${{ needs.test-up.outputs.checkout-name }} # not strictly needed, but tests the output was set
5684

5785
- id: test-git
5886
name: Git status 🤷
5987
run: |
6088
set -euo pipefail
61-
cd download
6289
git status
90+
if [[ ! -f action.yaml ]] ; then
91+
echo "🛑 'action.yaml' is not found!"
92+
exit 1
93+
fi
94+
95+
- id: given-download
96+
name: Download given file 📨
97+
uses: ./transfer-action/
98+
with:
99+
direction: 'download'
100+
name: ${{ needs.test-up.outputs.given-name }}
101+
102+
- id: test-file
103+
name: Did the file download? 🔎
104+
run: |
105+
set -euo pipefail
106+
if [[ ! -f foo ]] ; then
107+
echo "🛑 'foo' is not found!"
108+
exit 1
109+
fi
63110
64111
update-doc:
65112
if: ${{ github.ref_name != github.event.repository.default_branch }}

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This action transfers data to/from artefact storage
1212
runs-on: [self-hosted]
1313
steps:
1414
- name: Upload repo
15-
uses: reecetech/transfer-action@v1
15+
uses: reecetech/transfer-action@v2
1616
with:
1717
checkout: 'true'
1818
direction: 'upload'
@@ -27,18 +27,18 @@ This action transfers data to/from artefact storage
2727
- checkout
2828
steps:
2929
- name: Download repo
30-
uses: reecetech/transfer-action@v1
30+
uses: reecetech/transfer-action@v2
3131
with:
32+
checkout: 'true'
3233
direction: 'download'
33-
name: 'checkout'
3434
```
3535
3636
### Upload specific build results
3737
3838
```yaml
3939
- id: upload
4040
name: Upload build output
41-
uses: reecetech/transfer-action@v1
41+
uses: reecetech/transfer-action@v2
4242
with:
4343
direction: 'upload'
4444
name: 'build-result'
@@ -49,7 +49,7 @@ This action transfers data to/from artefact storage
4949
5050
```yaml
5151
- name: Download build output
52-
uses: reecetech/transfer-action@v1
52+
uses: reecetech/transfer-action@v2
5353
with:
5454
direction: 'download'
5555
name: 'build-result'
@@ -61,15 +61,15 @@ This action transfers data to/from artefact storage
6161
6262
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
6363
64-
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
65-
|----------------------|--------|----------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
66-
| checkout | string | false | `"false"` | Do a Git checkout before<br>transferring, either: `true` or `false`;<br>defaults to `false` |
67-
| checkout-fetch-depth | string | false | `"1"` | Number of commits to fetch.<br>0 indicates all history for<br>all branches and tags |
68-
| checkout-lfs | string | false | `"false"` | Whether to download Git-LFS files<br> |
69-
| direction | string | true | | Direction of transfer, either: `upload`<br>or `download` |
70-
| if-no-files-found | string | false | `"error"` | The desired behavior if no<br>files are found using the<br>provided path. Available Options: warn:<br>Output a warning but do<br>not fail the action error:<br>Fail the action with an<br>error message ignore: Do not<br>output any warnings or errors,<br>the action does not fail<br> |
71-
| name | string | false | | Artifact name: defaults to `checkout`<br>if checkout input is `true`,<br>otherwise, please provide a value<br> |
72-
| path | string | false | `"./"` | Defaults to `./` - additionally,<br>the meaning of `path` is:<br>if direction is `upload`: a<br>file, directory or wildcard pattern<br>that describes what to upload;<br>if direction is `download`: destination<br>path |
64+
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
65+
|----------------------|--------|----------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
66+
| checkout | string | false | `"false"` | Do a Git checkout before<br>transferring, either: `true` or `false`;<br>defaults to `false` |
67+
| checkout-fetch-depth | string | false | `"1"` | Number of commits to fetch.<br>0 indicates all history for<br>all branches and tags |
68+
| checkout-lfs | string | false | `"false"` | Whether to download Git-LFS files<br> |
69+
| direction | string | true | | Direction of transfer, either: `upload`<br>or `download` |
70+
| if-no-files-found | string | false | `"error"` | The desired behavior if no<br>files are found using the<br>provided path. Available Options: warn:<br>Output a warning but do<br>not fail the action error:<br>Fail the action with an<br>error message ignore: Do not<br>output any warnings or errors,<br>the action does not fail<br> |
71+
| name | string | false | | Artifact name: defaults to `checkout`<br>if checkout input is `true`,<br>otherwise, please provide a value<br> |
72+
| path | string | false | | ⚠️ Conditional defaults! - if<br>`checkout` is `true`; then defaults<br>to `./.git/` - if `checkout`<br>is `false`; then defaults to<br>`./` Additionally, the meaning of<br>`path` is: - if direction<br>is `upload`: a file, directory<br>or wildcard pattern that describes<br>what to upload; - if<br>direction is `download`: destination path<br> |
7373

7474
<!-- AUTO-DOC-INPUT:END -->
7575

action.yaml

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ inputs:
3333
description: 'Artifact name: defaults to `checkout` if checkout input is `true`, otherwise, please provide a value'
3434
path:
3535
description: |
36-
Defaults to `./` - additionally, the meaning of `path` is:
37-
if direction is `upload`: a file, directory or wildcard pattern that describes what to upload;
38-
if direction is `download`: destination path
39-
default: './'
36+
⚠️ Conditional defaults!
37+
- if `checkout` is `true`; then defaults to `./.git/`
38+
- if `checkout` is `false`; then defaults to `./`
39+
40+
Additionally, the meaning of `path` is:
41+
- if direction is `upload`: a file, directory or wildcard pattern that describes what to upload;
42+
- if direction is `download`: destination path
4043
4144
outputs:
4245
name:
@@ -53,9 +56,16 @@ runs:
5356
CHECKOUT: ${{ inputs.checkout }}
5457
DIRECTION: ${{ inputs.direction }}
5558
NAME: ${{ inputs.name }}
59+
PATH: ${{ inputs.path }}
60+
LFS: ${{ inputs.checkout-lfs }}
5661
run: |
5762
set -euo pipefail
5863
64+
if [[ "${LFS}" != 'false' ]] ; then
65+
echo "🛑 sorry, LFS functionality not yet implemented"
66+
exit 255
67+
fi
68+
5969
if [[ "${CHECKOUT}" != 'true' && "${CHECKOUT}" != 'false' ]] ; then
6070
echo "🛑 checkout input set to '${CHECKOUT}', should be either 'true' or 'false'"
6171
exit 1
@@ -77,28 +87,53 @@ runs:
7787
fi
7888
fi
7989
80-
- id: checkout
81-
if: inputs.checkout == 'true'
82-
name: Checkout repo
90+
if [[ -n "${PATH:-}" ]] ; then
91+
echo "::set-output name=path::${PATH}"
92+
else
93+
if [[ "${CHECKOUT}" == 'true' ]] ; then
94+
echo "::set-output name=path::./.git/"
95+
else
96+
echo "::set-output name=path::./"
97+
fi
98+
fi
99+
100+
- id: clone
101+
if: inputs.checkout == 'true' && inputs.direction == 'upload'
102+
name: Clone repo ⧉
83103
uses: actions/checkout@v3
84104
with:
85105
fetch-depth: ${{ inputs.checkout-fetch-depth }}
86-
lfs: ${{ inputs.checkout-lfs }}
106+
107+
- id: prepare-dot-git
108+
if: inputs.checkout == 'true' && inputs.direction == 'upload'
109+
name: Remove index 🗑
110+
shell: bash
111+
run: |
112+
set -euo pipefail
113+
rm -f .git/index
87114
88115
- id: transfer-up
89116
if: inputs.direction == 'upload'
90-
name: Transfer data to GitHub
117+
name: Transfer data to GitHub 🆙
91118
uses: actions/upload-artifact@v3
92119
with:
93120
if-no-files-found: ${{ inputs.if-no-files-found }}
94121
name: ${{ steps.verify.outputs.name }}
95-
path: ${{ inputs.path }}
122+
path: ${{ steps.verify.outputs.path }}
96123
retention-days: 1
97124

98125
- id: transfer-down
99126
if: inputs.direction == 'download'
100-
name: Transfer data from GitHub
127+
name: Transfer data from GitHub ⬇️
101128
uses: actions/download-artifact@v3
102129
with:
103130
name: ${{ steps.verify.outputs.name }}
104-
path: ${{ inputs.path }}
131+
path: ${{ steps.verify.outputs.path }}
132+
133+
- id: checkout
134+
if: inputs.checkout == 'true' && inputs.direction == 'download'
135+
name: Checkout repo 🛒
136+
shell: bash
137+
run: |
138+
set -euo pipefail
139+
git checkout --progress --force -B "${{ github.ref_name }}" "${{ github.ref }}"

0 commit comments

Comments
 (0)