Skip to content

Instantly share code, notes, and snippets.

@rcdailey
Created September 7, 2024 23:50
Show Gist options
  • Save rcdailey/cd3437bb2c63647126aa5740824b2a4f to your computer and use it in GitHub Desktop.
Save rcdailey/cd3437bb2c63647126aa5740824b2a4f to your computer and use it in GitHub Desktop.
Custom actions to preserve file permissions when uploading and downloading artifacts in a Github Workflow
# File: .github/actions/download-tar/action.yml
name: Download Tar Artifact
description: >
Download and extract a tar artifact that was previously uploaded in the workflow by the upload-tar
action
inputs:
name:
description: Artifact name
path:
description: Destination path
required: false
runs:
using: composite
steps:
- uses: actions/[email protected]
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
- run: ${{ github.action_path }}/untar.sh "${{ inputs.name }}"
working-directory: ${{ inputs.path }}
shell: bash
#!/usr/bin/env bash
# File: .github/actions/download-tar/untar.sh
set -x
name="$1"
if [[ "$name" == '' ]]; then
dirs=(*/)
else
dirs=(.)
fi
for dir in ${dirs[@]}; do
echo "> Extracting: $dir"
pushd "$dir" > /dev/null
tar xvf artifact.tar
rm artifact.tar
popd > /dev/null
done
# File: .github/actions/upload-tar/action.yml
name: Upload Tar Artifact
description: Compress files with tar prior to artifacting to keep file privileges.
inputs:
name:
description: Artifact name
path:
description: A directory path. The contents of that directory will be tarballed and uploaded.
required: true
runs:
using: composite
steps:
- run: tar cvf artifact.tar *
shell: bash
working-directory: ${{ inputs.path }}
- uses: actions/[email protected]
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}/artifact.tar
overwrite: true
- run: rm artifact.tar
shell: bash
working-directory: ${{ inputs.path }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment