2023-12-20 09:17:49 -05:00
|
|
|
name: Upload artifact
|
|
|
|
description: Upload an encrypted zip archive as a github artifact.
|
|
|
|
|
|
|
|
inputs:
|
|
|
|
path:
|
2023-12-21 13:28:18 -05:00
|
|
|
description: 'The path(s) that should be uploaded. Paths may contain globs. Only the final component of a path is uploaded.'
|
2023-12-20 09:17:49 -05:00
|
|
|
required: true
|
|
|
|
name:
|
|
|
|
description: 'The name of the artifact.'
|
|
|
|
required: true
|
|
|
|
retention-days:
|
|
|
|
description: 'How long the artifact should be retained for.'
|
|
|
|
default: 60
|
2023-12-21 13:28:18 -05:00
|
|
|
encryptionSecret:
|
2023-12-20 09:17:49 -05:00
|
|
|
description: 'The secret to use for encrypting the files.'
|
|
|
|
required: true
|
2024-04-26 06:06:01 -04:00
|
|
|
overwrite:
|
|
|
|
description: 'Overwrite an artifact with the same name.'
|
|
|
|
default: false
|
|
|
|
required: false
|
2023-12-20 09:17:49 -05:00
|
|
|
|
|
|
|
runs:
|
|
|
|
using: "composite"
|
|
|
|
steps:
|
2024-05-08 04:34:10 -04:00
|
|
|
- name: Install 7zip
|
2023-12-20 09:17:49 -05:00
|
|
|
uses: ./.github/actions/setup_bazel_nix
|
|
|
|
with:
|
|
|
|
nixTools: |
|
2024-05-08 04:34:10 -04:00
|
|
|
_7zz
|
2023-12-20 09:17:49 -05:00
|
|
|
|
|
|
|
- name: Create temporary directory
|
|
|
|
id: tempdir
|
|
|
|
shell: bash
|
|
|
|
run: echo "directory=$(mktemp -d)" >> "$GITHUB_OUTPUT"
|
2024-05-08 04:34:10 -04:00
|
|
|
|
|
|
|
- name: Create archive
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
shopt -s extglob
|
|
|
|
paths="${{ inputs.path }}"
|
|
|
|
paths=${paths%$'\n'} # Remove trailing newline
|
|
|
|
# Check if any file matches the given pattern(s).
|
|
|
|
something_exists=false
|
|
|
|
for pattern in ${paths}
|
|
|
|
do
|
|
|
|
if compgen -G "${pattern}" > /dev/null; then
|
|
|
|
something_exists=true
|
|
|
|
fi
|
|
|
|
done
|
2024-05-23 03:24:15 -04:00
|
|
|
|
2024-05-08 04:34:10 -04:00
|
|
|
# Create an archive if files exist.
|
|
|
|
# Don't create an archive file if no files are found
|
|
|
|
# and warn.
|
|
|
|
if ! ${something_exists}
|
|
|
|
then
|
|
|
|
echo "::warning:: No files/directories found with the provided path(s): ${paths}. No artifact will be uploaded."
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-05-23 03:24:15 -04:00
|
|
|
|
2024-05-08 04:34:10 -04:00
|
|
|
for target in ${paths}
|
|
|
|
do
|
2024-05-23 03:24:15 -04:00
|
|
|
if [[ -f "${target}" ]]
|
|
|
|
then
|
|
|
|
pushd "$(dirname "${target}")" || exit 1
|
|
|
|
7zz a -p'${{ inputs.encryptionSecret }}' -bso0 -bsp0 -t7z -ms=on -mhe=on "${{ steps.tempdir.outputs.directory }}/archive.7z" "$(basename "${target}")"
|
|
|
|
popd || exit 1
|
|
|
|
fi
|
2024-05-08 04:34:10 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
- name: Upload archive as artifact
|
2024-05-08 08:33:35 -04:00
|
|
|
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
2024-05-08 04:34:10 -04:00
|
|
|
with:
|
|
|
|
name: ${{ inputs.name }}
|
|
|
|
path: ${{ steps.tempdir.outputs.directory }}/archive.7z
|
|
|
|
retention-days: ${{ inputs.retention-days }}
|
|
|
|
if-no-files-found: ignore
|
|
|
|
overwrite: ${{ inputs.overwrite }}
|