Skip to content

Commit

Permalink
Setup for Editor Deployments, still need to do some validation, need …
Browse files Browse the repository at this point in the history
…about 4-6 compiles before we're perfect.
  • Loading branch information
Bioblaze committed Dec 13, 2024
1 parent d845200 commit afea794
Show file tree
Hide file tree
Showing 7 changed files with 801 additions and 4 deletions.
89 changes: 89 additions & 0 deletions .github/actions/multi-do-upload/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Upload Files to DigitalOcean Spaces
description: Upload multiple files to DigitalOcean Spaces based on a YAML array input.

inputs:
files:
description: A YAML array of files to upload with their paths relative to the repository root.
required: true
space_name:
description: The name of the DigitalOcean Space.
required: true
space_region:
description: The region of the DigitalOcean Space.
required: true
storage_type:
description: The storage class to use (e.g., STANDARD).
required: false
default: STANDARD
access_key:
description: The access key for DigitalOcean Spaces.
required: true
secret_key:
description: The secret key for DigitalOcean Spaces.
required: true
space_path:
description: The path within the Space where files will be uploaded.
required: true
acl:
description: The Access-Control List (ACL) for the files (e.g., public or private).
required: false
default: public

runs:
using: "composite"
steps:
- name: Validate Input Parameters
id: validate_inputs
shell: bash
run: |
FILES=$(echo "${{ inputs.files }}" | awk NF)
if [ -z "$FILES" ]; then
echo "Error: No files specified for upload."
exit 1
fi
echo "Files to upload: $FILES" >> $GITHUB_STEP_SUMMARY
- name: Upload Files to DigitalOcean Spaces
shell: bash
env:
SPACE: ${{ inputs.space_name }}
REGION: ${{ inputs.space_region }}
STORAGETYPE: ${{ inputs.storage_type }}
KEY: ${{ inputs.access_key }}
SECRET: ${{ inputs.secret_key }}
SPACE_PATH: ${{ inputs.space_path }}
ACL: ${{ inputs.acl }}
run: |
# Function to upload a file to DigitalOcean Spaces
function putS3 {
local path=$1
local file=$2
local space_path=$3
local space="${SPACE}"
local date=$(date +"%a, %d %b %Y %T %z")
local acl="x-amz-acl:${ACL}"
local content_type=$(file --mime-type -b "$path/$file")
local storage_type="x-amz-storage-class:${STORAGETYPE}"
local string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$space$space_path$file"
local signature=$(echo -en "${string}" | openssl sha1 -hmac "${SECRET}" -binary | base64)
curl -s -X PUT -T "$path/$file" \
-H "Host: $space.${REGION}.digitaloceanspaces.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${KEY}:$signature" \
"https://$space.${REGION}.digitaloceanspaces.com$space_path$file"
}
# Process and upload each file
FILES=$(echo "${{ inputs.files }}" | tr -d '[]' | tr ',' '\n' | sed 's/"//g' | awk NF)
for file_path in $FILES; do
if [ -f "$file_path" ]; then
file_name=$(basename "$file_path")
echo "Uploading $file_name to ${SPACE}/${SPACE_PATH}" >> $GITHUB_STEP_SUMMARY
putS3 "$(dirname "$file_path")" "$file_name" "/${SPACE_PATH}/"
else
echo "Warning: File $file_path does not exist. Skipping." >> $GITHUB_STEP_SUMMARY
fi
done
100 changes: 100 additions & 0 deletions .github/actions/multi-folder-zip/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Rename and Zip Folders Action
description: Renames folders in input_dir, zips them, and places the zip files in output_dir.

inputs:
input_dir:
description: The directory containing the original folders.
required: true
output_dir:
description: The directory where zip files will be placed.
required: true
names:
description: A YAML array of directory names to check within input_dir.
required: true
filename_new:
description: A YAML array of new folder names to rename the folders.
required: true

outputs:
zipped_files:
description: A list of paths to the zipped files.
value: ${{ steps.process_folders.outputs.zipped_files }}

runs:
using: "composite"
steps:
- name: Validate Input Parameters
id: validate_inputs
shell: bash
run: |
INPUT_DIR=${{ inputs.input_dir }}
OUTPUT_DIR=${{ inputs.output_dir }}
NAMES=$(echo "${{ inputs.names }}" | awk NF)
FILENAME_NEW=$(echo "${{ inputs.filename_new }}" | awk NF)
# Ensure output directory exists
if [ ! -d "$OUTPUT_DIR" ]; then
echo "Creating output directory: $OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
fi
# Check array lengths match
LEN_NAMES=$(echo "$NAMES" | wc -l)
LEN_NEW=$(echo "$FILENAME_NEW" | wc -l)
if [ "$LEN_NAMES" -ne "$LEN_NEW" ]; then
echo "Error: The input arrays must have the same length." >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "Input parameters validated successfully." >> $GITHUB_STEP_SUMMARY
- name: Process Folders
id: process_folders
shell: bash
run: |
INPUT_DIR=${{ inputs.input_dir }}
OUTPUT_DIR=${{ inputs.output_dir }}
NAMES=$(echo "${{ inputs.names }}" | awk NF)
FILENAME_NEW=$(echo "${{ inputs.filename_new }}" | awk NF)
echo "## Listing Input Directory Contents" >> $GITHUB_STEP_SUMMARY
ls -la "$INPUT_DIR" >> $GITHUB_STEP_SUMMARY
# Initialize array to store zipped file paths
ZIPPED_FILES=()
# Process each entry in the arrays
paste <(echo "$NAMES") <(echo "$FILENAME_NEW") | while IFS=$'\t' read -r OLD_FOLDER_NAME NEW_FOLDER_NAME; do
OLD_FOLDER_PATH="$INPUT_DIR/$OLD_FOLDER_NAME"
NEW_FOLDER_PATH="$INPUT_DIR/$NEW_FOLDER_NAME"
if [ ! -d "$OLD_FOLDER_PATH" ]; then
echo "Error: Directory $OLD_FOLDER_PATH does not exist. Skipping." >> $GITHUB_STEP_SUMMARY
continue
fi
# Rename the folder
mv "$OLD_FOLDER_PATH" "$NEW_FOLDER_PATH"
if [ $? -ne 0 ]; then
echo "Error: Failed to rename $OLD_FOLDER_PATH to $NEW_FOLDER_PATH" >> $GITHUB_STEP_SUMMARY
continue
fi
echo "Successfully renamed $OLD_FOLDER_PATH to $NEW_FOLDER_PATH" >> $GITHUB_STEP_SUMMARY
# Zip the folder
ZIP_FILE="$OUTPUT_DIR/${NEW_FOLDER_NAME}.zip"
zip -r "$ZIP_FILE" "$NEW_FOLDER_PATH" > /dev/null
if [ $? -eq 0 ]; then
echo "Successfully zipped $NEW_FOLDER_PATH to $ZIP_FILE" >> $GITHUB_STEP_SUMMARY
ZIPPED_FILES+=("$ZIP_FILE")
else
echo "Error: Failed to zip $NEW_FOLDER_PATH" >> $GITHUB_STEP_SUMMARY
fi
done
# Convert zipped files array to JSON and set output
echo "Zipped files: ${ZIPPED_FILES[@]}" >> $GITHUB_STEP_SUMMARY
echo "zipped_files=$(echo "${ZIPPED_FILES[@]}" | jq -c -R 'split(" ")')" >> $GITHUB_OUTPUT
echo "## Listing Output Directory Contents" >> $GITHUB_STEP_SUMMARY
ls -la "$OUTPUT_DIR" >> $GITHUB_STEP_SUMMARY
90 changes: 90 additions & 0 deletions .github/actions/multi-rename-inplace/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Rename Files in Place Action
description: Renames files in the same folder based on provided arrays.

inputs:
input_dir:
description: The directory containing the original files.
required: true
names:
description: A YAML array of directory names to check within input_dir.
required: true
filename_old:
description: A YAML array of old filenames to rename.
required: true
filename_new:
description: A YAML array of new filenames for the renamed files.
required: true

outputs:
renamed_files:
description: A list of paths to the renamed files.
value: ${{ steps.process_files.outputs.renamed_files }}

runs:
using: "composite"
steps:
- name: Validate Input Parameters
id: validate_inputs
shell: bash
run: |
INPUT_DIR=${{ inputs.input_dir }}
NAMES=$(echo "${{ inputs.names }}" | awk NF)
FILENAME_OLD=$(echo "${{ inputs.filename_old }}" | awk NF)
FILENAME_NEW=$(echo "${{ inputs.filename_new }}" | awk NF)
# Check array lengths match
LEN_NAMES=$(echo "$NAMES" | wc -l)
LEN_OLD=$(echo "$FILENAME_OLD" | wc -l)
LEN_NEW=$(echo "$FILENAME_NEW" | wc -l)
if [ "$LEN_NAMES" -ne "$LEN_OLD" ] || [ "$LEN_OLD" -ne "$LEN_NEW" ]; then
echo "Error: All input arrays must have the same length." >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "Input parameters validated successfully." >> $GITHUB_STEP_SUMMARY
- name: Rename Files
id: process_files
shell: bash
run: |
INPUT_DIR=${{ inputs.input_dir }}
NAMES=$(echo "${{ inputs.names }}" | awk NF)
FILENAME_OLD=$(echo "${{ inputs.filename_old }}" | awk NF)
FILENAME_NEW=$(echo "${{ inputs.filename_new }}" | awk NF)
echo "## Listing Input Directory Contents" >> $GITHUB_STEP_SUMMARY
ls -la "$INPUT_DIR" >> $GITHUB_STEP_SUMMARY
# Initialize array to store renamed file paths
RENAMED_FILES=()
# Process each entry in the arrays
paste <(echo "$NAMES") <(echo "$FILENAME_OLD") <(echo "$FILENAME_NEW") | while IFS=$'\t' read -r NAME OLD NEW; do
SOURCE_DIR="$INPUT_DIR/$NAME"
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Directory $SOURCE_DIR does not exist. Skipping." >> $GITHUB_STEP_SUMMARY
continue
fi
SOURCE_FILE="$SOURCE_DIR/$OLD"
DEST_FILE="$SOURCE_DIR/$NEW"
if [ ! -f "$SOURCE_FILE" ]; then
echo "Error: File $SOURCE_FILE does not exist. Skipping." >> $GITHUB_STEP_SUMMARY
continue
fi
mv "$SOURCE_FILE" "$DEST_FILE"
echo "## Listing Directory Contents After Rename" >> $GITHUB_STEP_SUMMARY
ls -la "$SOURCE_DIR" >> $GITHUB_STEP_SUMMARY
if [ $? -eq 0 ]; then
echo "Successfully renamed $SOURCE_FILE to $DEST_FILE" >> $GITHUB_STEP_SUMMARY
RENAMED_FILES+=("$DEST_FILE")
else
echo "Error: Failed to rename $SOURCE_FILE to $DEST_FILE" >> $GITHUB_STEP_SUMMARY
fi
done
# Convert renamed files array to JSON and set output
echo "Renamed files: ${RENAMED_FILES[@]}" >> $GITHUB_STEP_SUMMARY
echo "renamed_files=$(echo "${RENAMED_FILES[@]}" | jq -c -R 'split(" ")')" >> $GITHUB_OUTPUT
3 changes: 2 additions & 1 deletion .github/workflows/deploy_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ jobs:
secrets: inherit
with:
build_sha: ${{ inputs.build_sha }}
runner_id: ${{ inputs.runner_id }}
runner_id: ${{ inputs.runner_id }}
version_string: ${{ inputs.new_version }}
Loading

0 comments on commit afea794

Please sign in to comment.