From 088bf872b9d800ee68fe02733e74c866b0b5e86a Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 25 Dec 2024 21:34:23 +0100 Subject: [PATCH] Filter hidden files. --- .github/workflows/ArtifactsUpload.yml | 2 ++ README.md | 30 ++++++++++++++------------- action.yml | 22 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ArtifactsUpload.yml b/.github/workflows/ArtifactsUpload.yml index 676f0e4..0cfe4a4 100644 --- a/.github/workflows/ArtifactsUpload.yml +++ b/.github/workflows/ArtifactsUpload.yml @@ -291,6 +291,8 @@ jobs: - name: 🔎 Inspect downloaded artifact content uses: ./.github/actions/check-artifact-content + with: + must-exist: true - name: 📦 Extract tarball run: | diff --git a/README.md b/README.md index c44dd9a..8608949 100644 --- a/README.md +++ b/README.md @@ -55,22 +55,24 @@ jobs: ### Input Parameters -| Parameter | Required | Default | Description | -|------------------------|:--------:|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `name` | no | `'artifact'` | Name of the artifact to upload. | -| `working-directory` | no | `''` | | -| `path` | yes | | A list of files, directories or wildcard patterns that describes what to upload. | -| `if-no-files-found` | no | `'warn'` | 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 | -| `retention-days` | no | repository settings | Duration after which artifact will expire in days. 0 means using default retention.
Minimum 1 day.
Maximum 90 days unless changed from the repository settings page. | -| `compression-level` | no | `6` | The level of compression for Zlib to be applied to the artifact archive.
The value can range from 0 to 9.
For large files that are not easily compressed, a value of 0 is recommended for significantly faster uploads. | -| `overwrite` | no | `false` | If true, an artifact with a matching name will be deleted before a new one is uploaded.
If false, the action will fail if an artifact for the given name already exists.
Does not fail if the artifact does not exist. | -| `include-hidden-files` | no | `false` | Whether to include hidden files in the provided path in the artifact.
The file contents of any hidden files in the path should be validated before enabled this to avoid uploading sensitive information. | -| `mode` | no | `'tar'` | Mode of operation. Allowed modes:
 • `tar` (default),
 • `legacy` | -| `debug` | no | `false` | Enabled debug mode. List content of the created tarball. | -| `tarball-name` | no | [^1] | Filename of the embedded tarball. | +| Parameter | Required | Default | Description | +|----------------------------|:--------:|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `name` | no | `'artifact'` | Name of the artifact to upload. | +| `working-directory` | no | `''` | | +| `path` | yes | | A list of files, directories or wildcard patterns that describes what to upload. | +| `if-no-files-found`[^3] | no | `'warn'` | 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 | +| `retention-days` | no | repository settings | Duration after which artifact will expire in days. 0 means using default retention.
Minimum 1 day.
Maximum 90 days unless changed from the repository settings page. | +| `compression-level` | no | `6` | The level of compression for Zlib to be applied to the artifact archive.
The value can range from 0 to 9.
For large files that are not easily compressed, a value of 0 is recommended for significantly faster uploads. | +| `overwrite` | no | `false` | If true, an artifact with a matching name will be deleted before a new one is uploaded.
If false, the action will fail if an artifact for the given name already exists.
Does not fail if the artifact does not exist. | +| `include-hidden-files`[^2] | no | `false` | Whether to include hidden files in the provided path in the artifact.
The file contents of any hidden files in the path should be validated before enabled this to avoid uploading sensitive information. | +| `mode`[^4] | no | `'tar'` | Mode of operation. Allowed modes:
 • `tar` (default),
 • `legacy` | +| `debug` | no | `false` | Enabled debug mode. List content of the created tarball. | +| `tarball-name` | no | [^1] | Filename of the embedded tarball. | [^1]: `'__pyTooling_upload_artifact__.tar'` - +[^2]: [Hidden files are included, when directories are uploaded bug](https://github.com/pyTooling/upload-artifact/issues/20) +[^3]: [Parameter 'if-no-files-found' has no effect bug](https://github.com/pyTooling/upload-artifact/issues/21) +[^4]: [Add a legacy mode](https://github.com/pyTooling/upload-artifact/issues/22) ### Output Parameters diff --git a/action.yml b/action.yml index 0b16ee3..82c0794 100644 --- a/action.yml +++ b/action.yml @@ -233,6 +233,28 @@ runs: printf " %s\n" "${ANSI_CYAN}Directories: ${dirCount}${ANSI_NOCOLOR}" printf " %s\n" "${ANSI_CYAN}Files: ${fileCount}${ANSI_NOCOLOR}" + - name: Remove dot-files if not explicitly included + id: clean + if: inputs.include-hidden-files == 'false' + shell: bash + run: | + # List content of the generated tarball + set +e + + ANSI_CYAN=$'\x1b[36m' + ANSI_LIGHT_RED=$'\x1b[91m' + ANSI_LIGHT_GREEN=$'\x1b[92m' + ANSI_LIGHT_YELLOW=$'\x1b[93m' + ANSI_LIGHT_BLUE="\e[94m" + ANSI_NOCOLOR=$'\x1b[0m' + + printf "::group::${ANSI_LIGHT_BLUE}Removing unwanted files from '${{ inputs.tarball-name }}' ...:${ANSI_NOCOLOR}\n" + while IFS=$'\r\n' read -r file; do + printf " %s\n" "${file}" + tar -vf "${{ inputs.tarball-name }}" --delete "${file}" + done <<<$(tar -tf "${{ inputs.tarball-name }}" | grep -E '^\.|/\.') + printf "::endgroup::\n" + - name: List content of the generated tarball id: debug if: inputs.mode == 'tar' && inputs.debug == 'true'