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: |
|
2024-06-07 07:37:06 -04:00
|
|
|
set -euo pipefail
|
2024-05-08 04:34:10 -04:00
|
|
|
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-24 02:46:22 -04:00
|
|
|
if compgen -G "${target}" > /dev/null
|
2024-05-23 03:24:15 -04:00
|
|
|
then
|
2024-06-07 07:37:06 -04:00
|
|
|
pushd "$(dirname "${target}")"
|
2024-05-23 03:24:15 -04:00
|
|
|
7zz a -p'${{ inputs.encryptionSecret }}' -bso0 -bsp0 -t7z -ms=on -mhe=on "${{ steps.tempdir.outputs.directory }}/archive.7z" "$(basename "${target}")"
|
2024-06-07 07:37:06 -04:00
|
|
|
popd
|
2024-05-23 03:24:15 -04:00
|
|
|
fi
|
2024-05-08 04:34:10 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
- name: Upload archive as artifact
|
2024-07-18 02:49:57 -04:00
|
|
|
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
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 }}
|