Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Dec 4, 2024
2 parents 847f861 + 1d792fd commit 4c8fc82
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 0 deletions.
161 changes: 161 additions & 0 deletions .github/workflows/ArtifactsUpload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Verification of Preserving Artifact Upload

on:
push:
workflow_dispatch:

jobs:
Build:
name: Upload artifact
runs-on: ubuntu-24.04

steps:
- name: 🖉 Build 1
run: |
echo "Document 1 $(date --utc '+%d.%m.%Y - %H:%M:%S')" > document1.txt
echo "Analysis log $(date --utc '+%d.%m.%Y - %H:%M:%S')" > analysis.log
echo "Build log $(date --utc '+%d.%m.%Y - %H:%M:%S')" > build.log
mkdir -p bin
echo "Program $(date --utc '+%d.%m.%Y - %H:%M:%S')" > bin/program.py
chmod u+x bin/program.py
mkdir -p lib
echo "Library $(date --utc '+%d.%m.%Y - %H:%M:%S')" > lib/common.py
chmod +x lib/common.py
- name: 🔎 Inspect directory structure
run: |
tree .
- name: 📤 Upload artifact
uses: pyTooling/upload-artifact@main
with:
name: release
path: |
document1.txt
*.log
bin/
lib/*.py
# if-no-files-found: error
# retention-days: 1

Verify:
name: Verify artifact content
runs-on: ubuntu-24.04
needs:
- Build

steps:
- name: 📥 Download artifact
uses: actions/download-artifact@v4
with:
name: release

- name: 🔎 Inspect downloaded artifact content
run: |
set +e
ANSI_LIGHT_RED="\e[91m"
ANSI_LIGHT_GREEN="\e[92m"
ANSI_NOCOLOR="\e[0m"
echo "List directory content"
ls -lAh .
echo "----------------------------------------"
echo -n "Does tarball exist ... "
if [[ ! -f __upload_artifact__.tar ]]; then
echo -e "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}"
echo -e "${ANSI_LIGHT_RED}Artifact doesn't contain a tar file named '__upload_artifact__.tar'.${ANSI_NOCOLOR}"
exit 1
else
echo -e "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}"
fi
- name: 📦 Extract tarball
run: |
set +e
ANSI_LIGHT_RED="\e[91m"
ANSI_LIGHT_GREEN="\e[92m"
ANSI_NOCOLOR="\e[0m"
echo -n "Extracting tarball ... "
tar -xf __upload_artifact__.tar
if [[ $? -ne 0 ]]; then
echo -e "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}"
fi
- name: 🔎 Inspect extracted tarball
run: |
tree .
- name: 📋 Verify extracted tarball content
run: |
set +e
ANSI_LIGHT_RED="\e[91m"
ANSI_LIGHT_GREEN="\e[92m"
ANSI_NOCOLOR="\e[0m"
expected=(
"document1.txt"
"analysis.log"
"build.log"
"bin/program.py"
"lib/common.py"
)
errors=0
for file in "${expected[@]}"; do
echo -n "Checking '${file}' ... "
if [[ -f "$file" ]]; then
echo -e "${ANSI_LIGHT_GREEN}[PASSED]${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}"
echo -e "${ANSI_LIGHT_RED}Extracted artifact doesn't contain file '${file}'.${ANSI_NOCOLOR}"
errors=$((errors + 1))
fi
done
echo ""
if [[ $errors -ne 0 ]]; then
echo -e "${ANSI_LIGHT_RED}Counted ${errors} errors.${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_GREEN}No errors found.${ANSI_NOCOLOR}"
fi
- name: 📋 Verify file permissions
run: |
set +e
ANSI_LIGHT_RED="\e[91m"
ANSI_LIGHT_GREEN="\e[92m"
ANSI_NOCOLOR="\e[0m"
expected=(
"bin/program.py"
"lib/common.py"
)
errors=0
for file in "${expected[@]}"; do
echo -n "Checking '${file}' ... "
if [[ -x "$file" ]]; then
echo -e "${ANSI_LIGHT_GREEN}[PASSED]${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}"
echo -e "${ANSI_LIGHT_RED}File '${file}' isn't executable.${ANSI_NOCOLOR}"
errors=$((errors + 1))
fi
done
echo ""
if [[ $errors -ne 0 ]]; then
echo -e "${ANSI_LIGHT_RED}Counted ${errors} errors.${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_GREEN}No errors found.${ANSI_NOCOLOR}"
fi
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/upload-artifact.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Preserving Artifact Upload Action

**Based on:**
* [actions/upload-artifact#38 - upload-artifact does not retain artifact permissions (08. Sep. 2024)](https://github.com/actions/upload-artifact/issues/38#issuecomment-2336484584)
* [Gist:
rcdailey/download-tar-action.yml](https://gist.github.com/rcdailey/cd3437bb2c63647126aa5740824b2a4f)
89 changes: 89 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Upload (preserving) Artifact
description: Tarball files before uploading the artifact to preserve file privileges.
author: Patrick Lehmann (@Paebbels)

inputs:
name:
description: "Name of the artifact."
type: string
path:
description: A list of file/directory pattern to be tarballed and uploaded as an artifact.
required: true
type: string
# if-no-files-found:
# retention-days:
# compression-level:
overwrite:
required: false
default: false
type: boolean
# include-hidden-files:
temp_tarball:
type: string
required: false
default: '__upload_artifact__.tar'

outputs:
artifact-id:
# description: "Random number"
value: ${{ steps.upload.outputs.artifact-id }}
artifact-url:
value: ${{ steps.upload.outputs.artifact-url }}

runs:
using: composite
steps:
- name: Create tarball from given file patterns
id: prepare
shell: bash
run: |
set +e
ANSI_LIGHT_RED="\e[91m"
ANSI_LIGHT_GREEN="\e[92m"
ANSI_NOCOLOR="\e[0m"
PATTERNS=()
while IFS=$'\r\n' read -r pattern; do
# skip empty or comment lines
[[ "${pattern}" == "" || "${pattern:0:1}" == "#" ]] && continue
PATTERNS+=($pattern)
done <<<'${{ inputs.path }}'
# echo "PATTERNS: ${PATTERNS[@]}"
echo -n "Creating temporary tarball ... "
tar -cf "${{ inputs.temp_tarball }}" "${PATTERNS[@]}"
if [[ $? -ne 0 ]]; then
echo -e "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}"
fi
# https://github.com/actions/upload-artifact
- name: Upload artifact
uses: actions/upload-artifact@v4
id: upload
with:
name: ${{ inputs.name }}
path: ${{ inputs.temp_tarball }}
overwrite: ${{ inputs.overwrite }}

- name: Remove temporary tarball
id: cleanup
shell: bash
run: |
set +e
ANSI_LIGHT_RED="\e[91m"
ANSI_LIGHT_GREEN="\e[92m"
ANSI_NOCOLOR="\e[0m"
echo -n "Removing temporary tarball ... "
rm -f "${{ inputs.temp_tarball }}"
if [[ $? -ne 0 ]]; then
echo -e "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}"
else
echo -e "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}"
fi

0 comments on commit 4c8fc82

Please sign in to comment.