From b8b851ff4fe9a9b4d79af4fc8570241707db3380 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Thu, 26 May 2022 13:42:03 +1000 Subject: [PATCH 1/5] Transfer only the `.git` directory to save data The checkout can be "re-hydrated" on the receiving side from the `.git` directory only --- .github/workflows/test-and-release.yml | 9 +++- README.md | 10 ++--- action.yaml | 59 +++++++++++++++++++++----- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index bbfe035..a02c690 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -50,9 +50,10 @@ jobs: name: Download checkout 📥 uses: ./ with: + checkout: 'true' direction: 'download' - name: ${{ needs.test-up.outputs.name }} - path: 'download/' + name: ${{ needs.test-up.outputs.name }} # not strictly needed, but tests the output was set + path: 'download/' # needs to be a subdir, because we had to checkout the repo in the prior step to actually test - id: test-git name: Git status 🤷 @@ -60,6 +61,10 @@ jobs: set -euo pipefail cd download git status + if [[ ! -f action.yaml ]] ; then + echo "🛑 'action.yaml' is not found!" + exit 1 + fi update-doc: if: ${{ github.ref_name != github.event.repository.default_branch }} diff --git a/README.md b/README.md index cebd8af..83f6ba8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This action transfers data to/from artefact storage runs-on: [self-hosted] steps: - name: Upload repo - uses: reecetech/transfer-action@v1 + uses: reecetech/transfer-action@v2 with: checkout: 'true' direction: 'upload' @@ -27,10 +27,10 @@ This action transfers data to/from artefact storage - checkout steps: - name: Download repo - uses: reecetech/transfer-action@v1 + uses: reecetech/transfer-action@v2 with: + checkout: 'true' direction: 'download' - name: 'checkout' ``` ### Upload specific build results @@ -38,7 +38,7 @@ This action transfers data to/from artefact storage ```yaml - id: upload name: Upload build output - uses: reecetech/transfer-action@v1 + uses: reecetech/transfer-action@v2 with: direction: 'upload' name: 'build-result' @@ -49,7 +49,7 @@ This action transfers data to/from artefact storage ```yaml - name: Download build output - uses: reecetech/transfer-action@v1 + uses: reecetech/transfer-action@v2 with: direction: 'download' name: 'build-result' diff --git a/action.yaml b/action.yaml index 128301b..69c9ef9 100644 --- a/action.yaml +++ b/action.yaml @@ -33,9 +33,13 @@ inputs: description: 'Artifact name: defaults to `checkout` if checkout input is `true`, otherwise, please provide a value' path: description: | - 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 + ⚠️ 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 default: './' outputs: @@ -53,9 +57,16 @@ runs: CHECKOUT: ${{ inputs.checkout }} DIRECTION: ${{ inputs.direction }} NAME: ${{ inputs.name }} + 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 @@ -77,28 +88,54 @@ runs: fi fi - - id: checkout - if: inputs.checkout == 'true' - name: Checkout repo + if [[ -n "${PATH:-}" ]] ; then + echo "::set-output name=path::${PATH}" + else + if [[ "${CHECKOUT}" == 'true' ]] ; then + echo "::set-output name=path::./.git/" + else + echo "🛑 path input has not been provided, need a value" + exit 4 + fi + fi + + - id: clone + if: inputs.checkout == 'true' && inputs.direction == 'upload' + name: Clone repo ⧉ uses: actions/checkout@v3 with: fetch-depth: ${{ inputs.checkout-fetch-depth }} - lfs: ${{ inputs.checkout-lfs }} + + - 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 + name: Transfer data to GitHub 🆙 uses: actions/upload-artifact@v3 with: if-no-files-found: ${{ inputs.if-no-files-found }} name: ${{ steps.verify.outputs.name }} - path: ${{ inputs.path }} + path: ${{ steps.verify.outputs.path }} retention-days: 1 - id: transfer-down if: inputs.direction == 'download' - name: Transfer data from GitHub + name: Transfer data from GitHub ⬇️ uses: actions/download-artifact@v3 with: name: ${{ steps.verify.outputs.name }} - path: ${{ inputs.path }} + path: ${{ steps.verify.outputs.path }} + + - id: checkout + if: inputs.checkout == 'true' && inputs.direction == 'download' + name: Checkout repo 🛒 + shell: bash + run: | + set -euo pipefail + git checkout "${{ github.ref_name }}" From 06c260facab4c168b8bb58c9129ecd14c5ba7b19 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Thu, 26 May 2022 14:01:46 +1000 Subject: [PATCH 2/5] Fix logic for paths & improve checkout --- action.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/action.yaml b/action.yaml index 69c9ef9..452dcd8 100644 --- a/action.yaml +++ b/action.yaml @@ -40,7 +40,6 @@ inputs: 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 - default: './' outputs: name: @@ -94,8 +93,7 @@ runs: if [[ "${CHECKOUT}" == 'true' ]] ; then echo "::set-output name=path::./.git/" else - echo "🛑 path input has not been provided, need a value" - exit 4 + echo "::set-output name=path::./" fi fi @@ -138,4 +136,4 @@ runs: shell: bash run: | set -euo pipefail - git checkout "${{ github.ref_name }}" + git checkout --progress --force -B "${{ github.ref_name }}" "${{ github.ref }}" From 1f9d0033ee98c450cc6e5d511d0781c19a02735d Mon Sep 17 00:00:00 2001 From: ps-jay Date: Thu, 26 May 2022 03:46:08 +0000 Subject: [PATCH 3/5] Update README --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 83f6ba8..87da9d1 100644 --- a/README.md +++ b/README.md @@ -61,15 +61,15 @@ This action transfers data to/from artefact storage -| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | -|----------------------|--------|----------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| checkout | string | false | `"false"` | Do a Git checkout before
transferring, either: `true` or `false`;
defaults to `false` | -| checkout-fetch-depth | string | false | `"1"` | Number of commits to fetch.
0 indicates all history for
all branches and tags | -| checkout-lfs | string | false | `"false"` | Whether to download Git-LFS files
| -| direction | string | true | | Direction of transfer, either: `upload`
or `download` | -| if-no-files-found | string | false | `"error"` | 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
| -| name | string | false | | Artifact name: defaults to `checkout`
if checkout input is `true`,
otherwise, please provide a value
| -| path | string | false | `"./"` | 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 | +| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | +|----------------------|--------|----------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| checkout | string | false | `"false"` | Do a Git checkout before
transferring, either: `true` or `false`;
defaults to `false` | +| checkout-fetch-depth | string | false | `"1"` | Number of commits to fetch.
0 indicates all history for
all branches and tags | +| checkout-lfs | string | false | `"false"` | Whether to download Git-LFS files
| +| direction | string | true | | Direction of transfer, either: `upload`
or `download` | +| if-no-files-found | string | false | `"error"` | 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
| +| name | string | false | | Artifact name: defaults to `checkout`
if checkout input is `true`,
otherwise, please provide a value
| +| path | string | false | | ⚠️ 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
| From 54d4d6ed924d52e224affb93e12e8c982d0b9240 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Thu, 26 May 2022 14:05:58 +1000 Subject: [PATCH 4/5] Improve tests by moving the action out of the way --- .github/workflows/test-and-release.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index a02c690..4d2d88b 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -28,13 +28,23 @@ jobs: - id: checkout name: Checkout code 🛒 uses: actions/checkout@v3 + with: + path: transfer-action - id: checkout-upload name: Checkout and upload 📦 - uses: ./ + uses: ./transfer-action/ with: checkout: 'true' direction: 'upload' + + - id: checkout-again + # have to do this because the `checkout-upload` step cleans the working dir + name: Checkout code (again) 🛒 + uses: actions/checkout@v3 + with: + path: transfer-action + outputs: name: ${{ steps.checkout-upload.outputs.name }} @@ -45,21 +55,21 @@ jobs: - id: checkout name: Checkout code 🛒 uses: actions/checkout@v3 + with: + path: transfer-action - id: checkout-download name: Download checkout 📥 - uses: ./ + uses: ./transfer-action/ with: checkout: 'true' direction: 'download' name: ${{ needs.test-up.outputs.name }} # not strictly needed, but tests the output was set - path: 'download/' # needs to be a subdir, because we had to checkout the repo in the prior step to actually test - id: test-git name: Git status 🤷 run: | set -euo pipefail - cd download git status if [[ ! -f action.yaml ]] ; then echo "🛑 'action.yaml' is not found!" From df96f6df2c2ffd7c013c5ebaf2a80a84bb2139dd Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Thu, 26 May 2022 14:26:25 +1000 Subject: [PATCH 5/5] Add test for non-checkout transfers --- .github/workflows/test-and-release.yml | 36 ++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 4d2d88b..0b9c975 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -31,6 +31,21 @@ jobs: with: path: transfer-action + - id: create-file + name: Create a file 🆕 + shell: bash + run: | + set -euo pipefail + touch foo + + - id: given-upload + name: Upload a given file 📤 + uses: ./transfer-action/ + with: + direction: 'upload' + name: 'foo' + path: './foo' + - id: checkout-upload name: Checkout and upload 📦 uses: ./transfer-action/ @@ -46,7 +61,8 @@ jobs: path: transfer-action outputs: - name: ${{ steps.checkout-upload.outputs.name }} + checkout-name: ${{ steps.checkout-upload.outputs.name }} + given-name: ${{ steps.given-upload.outputs.name }} test-down: runs-on: ubuntu-latest @@ -64,7 +80,7 @@ jobs: with: checkout: 'true' direction: 'download' - name: ${{ needs.test-up.outputs.name }} # not strictly needed, but tests the output was set + name: ${{ needs.test-up.outputs.checkout-name }} # not strictly needed, but tests the output was set - id: test-git name: Git status 🤷 @@ -76,6 +92,22 @@ jobs: exit 1 fi + - id: given-download + name: Download given file 📨 + uses: ./transfer-action/ + with: + direction: 'download' + name: ${{ needs.test-up.outputs.given-name }} + + - id: test-file + name: Did the file download? 🔎 + run: | + set -euo pipefail + if [[ ! -f foo ]] ; then + echo "🛑 'foo' is not found!" + exit 1 + fi + update-doc: if: ${{ github.ref_name != github.event.repository.default_branch }} runs-on: ubuntu-latest