Updated extract.

This commit is contained in:
2025-12-30 23:20:08 -08:00
parent fa757e6510
commit bc14aa473a
4 changed files with 71 additions and 15 deletions

View File

@@ -13,7 +13,7 @@ inputs:
region: region:
description: "AWS region." description: "AWS region."
required: true required: true
default: us-gov-west-1 default: us-west-1
outputs: outputs:
console: console:
description: "The console output of the aws command." description: "The console output of the aws command."

View File

@@ -16,7 +16,7 @@ inputs:
region: region:
description: "AWS region." description: "AWS region."
required: true required: true
default: us-gov-west-1 default: us-west-1
runs: runs:
using: "composite" using: "composite"
steps: steps:

View File

@@ -8,6 +8,10 @@ inputs:
description: "Directory to extract to." description: "Directory to extract to."
required: false required: false
default: "" default: ""
fileType:
description: "File type to extract (auto, zip, tgz). Auto will detect based on file extension."
required: false
default: "auto"
prefixArgs: prefixArgs:
description: "Additional arguments to pass in early." description: "Additional arguments to pass in early."
required: false required: false
@@ -23,19 +27,8 @@ runs:
steps: steps:
- name: "Build command." - name: "Build command."
id: command id: command
run: | run: bash ${{ github.action_path }}/extract.sh "${{ inputs.file }}" "${{ inputs.fileType }}" "${{ inputs.outputDir }}" "${{ inputs.prefixArgs }}" "${{ inputs.additionalArgs }}"
COMMAND="unzip ${{ inputs.prefixArgs }} -o ${{ inputs.file }} ${{ inputs.additionalArgs }}"
OUTPUT_DIR="${{ inputs.outputDir }}"
if [[ -n "$OUTPUT_DIR" ]]; then
COMMAND="$COMMAND -d \"$OUTPUT_DIR\""
fi
echo "command=$COMMAND" >> "$GITHUB_OUTPUT"
shell: bash shell: bash
- name: "Convert file."
id: convert
uses: act/common/distros/busybox@master
with:
args: ${{ steps.command.outputs.command }}
- name: "Delete source." - name: "Delete source."
run: | run: |
if [[ ${{ inputs.deleteSource }} != "true" ]]; then if [[ ${{ inputs.deleteSource }} != "true" ]]; then

63
utils/extract/extract.sh Normal file
View File

@@ -0,0 +1,63 @@
#!/bin/bash
set -euo pipefail # Best practice: fail fast on errors, unset vars, pipeline failures
FILE="${1:-}"
FILE_TYPE="${2:-auto}"
OUTPUT_DIR="${3:-}"
PREFIX_ARGS="${4:-}"
ADDITIONAL_ARGS="${5:-}"
# Validate that a file was provided
if [[ -z "$FILE" ]]; then
echo "Error: No file specified." >&2
exit 1
fi
# Resolve relative paths and check if file exists
if [[ ! -f "$FILE" ]]; then
echo "Error: File not found: '$FILE'" >&2
exit 1
fi
# Auto-detect file type if needed
if [[ "$FILE_TYPE" == "auto" ]]; then
if [[ "$FILE" =~ \.(tar\.gz|tgz)$ ]]; then
FILE_TYPE="tgz"
elif [[ "$FILE" =~ \.zip$ ]]; then
FILE_TYPE="zip"
else
echo "Error: Unable to auto-detect file type from extension '$FILE'. Specify 'zip' or 'tgz'." >&2
exit 1
fi
fi
# Ensure output directory exists if specified
if [[ -n "$OUTPUT_DIR" ]]; then
mkdir -p "$OUTPUT_DIR"
fi
# Build the extraction command
case "$FILE_TYPE" in
tgz)
COMMAND=(tar $PREFIX_ARGS -xzf "$FILE" $ADDITIONAL_ARGS)
[[ -n "$OUTPUT_DIR" ]] && COMMAND+=(-C "$OUTPUT_DIR")
;;
zip)
COMMAND=(unzip $PREFIX_ARGS -o "$FILE" $ADDITIONAL_ARGS)
[[ -n "$OUTPUT_DIR" ]] && COMMAND+=(-d "$OUTPUT_DIR")
;;
*)
echo "Error: Invalid fileType '$FILE_TYPE'. Must be 'auto', 'zip', or 'tgz'." >&2
exit 1
;;
esac
# Output the built command (for GitHub Actions step output or local debugging)
if [[ -z "${GITHUB_OUTPUT-}" ]]; then
GITHUB_OUTPUT="/dev/stdout"
fi
echo "command=${COMMAND[*]}" >> "$GITHUB_OUTPUT"
# Execute the command safely using an array (prevents word splitting issues)
exec "${COMMAND[@]}"