From b887d4986bc3f27650445423be5536342d52d72d Mon Sep 17 00:00:00 2001 From: Andrew Davis <1709934+Savid@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:09:24 +1000 Subject: [PATCH] feat(ci): tomorrow --- gimp.sh | 14 ------ test.sh | 132 -------------------------------------------------------- 2 files changed, 146 deletions(-) delete mode 100755 gimp.sh delete mode 100755 test.sh diff --git a/gimp.sh b/gimp.sh deleted file mode 100755 index 4f05108..0000000 --- a/gimp.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -PLATFORMS='[{"platform":"linux/amd64", "runner": "ARM64", "slug": "something-arm64"},{"platform":"linux/arm64", "runner": "ubuntu-latest", "slug": "something-amd64"}]' -IMAGES="" - -# Iterate over the platforms and build the image list -len=$(echo $PLATFORMS | jq '. | length') -for ((i=0; i<$len; i++)); do - slug=$(echo $PLATFORMS | jq -r --argjson i $i '.[$i].slug') - IMAGES+="repo:tag-$slug " -done - -IMAGES=${IMAGES::-1} # Remove the trailing space -echo "images=$IMAGES" \ No newline at end of file diff --git a/test.sh b/test.sh deleted file mode 100755 index 2b0d8ab..0000000 --- a/test.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/bash - - - CONFIG_FILE="config.yaml" - PLATFORMS_FILE="platforms.yaml" - RUNNERS_FILE="runners.yaml" - - # Create a temporary directory for storing intermediate results - TEMP_DIR=$(mktemp -d) - # Ensure the temporary directory is removed when the script exits - trap "rm -rf $TEMP_DIR" EXIT - - process_commits() { - local LINE=$1 - local SOURCE_REPOSITORY=$2 - local SOURCE_REF=$3 - local TARGET_REPOSITORY=$4 - local TARGET_TAG=$5 - - local CLIENT="${TARGET_REPOSITORY#*/}" - local RESPONSE=$(curl -s -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - "https://api.github.com/repos/${SOURCE_REPOSITORY}/commits/${SOURCE_REF}?per_page=1") - local COMMIT_HASH=$(echo "$RESPONSE" | jq -r '.sha' | cut -c1-7) - - if [[ -z "$COMMIT_HASH" || "$COMMIT_HASH" == "null" ]]; then - # Log error but don't exit; just skip this configuration - echo "[LINE:$LINE] Error fetching commit hash for ${SOURCE_REPOSITORY}#${SOURCE_REF}, skipping." - return - fi - - local configOutput="${TEMP_DIR}/${LINE}_commits.json" - touch $configOutput - - echo "{\"line\": \"$LINE\", \"commit_hash\": \"$COMMIT_HASH\"}," >> $configOutput - } - - process_image() { - local LINE=$1 - local IMAGE=$2 - local URL=$3 - - local imageOutput="${TEMP_DIR}/${LINE}_image.json" - touch $imageOutput - local exists=$(curl -s $URL | jq '.results | length > 0') - - # check if exists == true - if [ "$exists" == "true" ]; then - exists=true - else - exists=false - fi - - echo "{\"line\": \"$LINE\", \"image\": \"$IMAGE\", \"exists\": $exists}" >> $imageOutput - } - - # Get commit hashes for each configuration in parallel - while IFS=$'\t' read -r LINE SOURCE_REPOSITORY SOURCE_REF TARGET_REPOSITORY TARGET_TAG; do - process_commits "$LINE" "$SOURCE_REPOSITORY" "$SOURCE_REF" "$TARGET_REPOSITORY" "$TARGET_TAG" & - done < <(yq -r 'to_entries | map_values({"value":.value, "index":.key}) | .[] | [.index, .value.source.repository, .value.source.ref, .value.target.repository, .value.target.tag] | @tsv' "$CONFIG_FILE") - - wait - - # Initialize JSON arrays - COMMITS="[" - - # Concatenate results, ensuring files exist before attempting to read - for file in $TEMP_DIR/*_commits.json; do - if [ -f "$file" ]; then - COMMITS+=$(cat "$file") - fi - done - - # Remove trailing commas and close JSON arrays - COMMITS="${COMMITS%,}]" - - echo "Checking if images exist in dockerhub..." - while IFS=$'\t' read -r LINE SOURCE_REPOSITORY SOURCE_REF TARGET_REPOSITORY TARGET_TAG; do - # get the image commit hash from LINE - COMMIT_HASH=$(echo "$COMMITS" | jq -r --arg LINE "$LINE" '.[] | select(.line == $LINE) | .commit_hash') - IMAGE_TAG="${TARGET_TAG}-${COMMIT_HASH}" - IMAGE="${TARGET_REPOSITORY}:${IMAGE_TAG}" - URL="https://hub.docker.com/v2/repositories/${TARGET_REPOSITORY}/tags?page_size=25&page=1&ordering=&name=${IMAGE_TAG}" - process_image $LINE $IMAGE $URL & - done < <(yq -r 'to_entries | map_values({"value":.value, "index":.key}) | .[] | [.index, .value.source.repository, .value.source.ref, .value.target.repository, .value.target.tag] | @tsv' "$CONFIG_FILE") - - wait - - declare -A images - - # Concatenate results, ensuring files exist before attempting to read - for file in $TEMP_DIR/*_image.json; do - if [ -f "$file" ]; then - - LINE=$(cat "$file" | jq -r '.line') - IMAGE=$(cat "$file" | jq -r '.image') - EXISTS=$(cat "$file" | jq -r '.exists') - images[$IMAGE]=$EXISTS - fi - done - - CONFIGS="configs=[" - - echo "Generating configuration files..." - while IFS=$'\t' read -r LINE SOURCE_REPOSITORY SOURCE_REF TARGET_REPOSITORY TARGET_TAG; do - # get the image commit hash from LINE - COMMIT_HASH=$(echo "$COMMITS" | jq -r --arg LINE "$LINE" '.[] | select(.line == $LINE) | .commit_hash') - IMAGE_TAG="${TARGET_TAG}-${COMMIT_HASH}" - IMAGE="${TARGET_REPOSITORY}:${IMAGE_TAG}" - CLIENT="${TARGET_REPOSITORY#*/}" - - if [ "${images[$IMAGE]}" == "false" ]; then - # Handle platforms and runners, ensuring output files are created even if empty - platforms=$(yq e ".$CLIENT[]" "$PLATFORMS_FILE") - platformsArr="" - - for platform in $platforms; do - runner=$(yq e ".\"$platform\"" "$RUNNERS_FILE") - slug=$(echo "$platform" | tr '/' '-') - platformsArr+="{\\\"platform\\\": \\\"$platform\\\", \\\"runner\\\": \\\"$runner\\\", \\\"slug\\\": \\\"$slug\\\"}," - done - platformsArr="${platformsArr%,}" - # convert to string - platformsOutput="{\"platforms\": \"[$platformsArr]\"}" - - CONFIGS+=$(echo "$(yq -r -o=json ".[${LINE}]" "$CONFIG_FILE" | jq --argjson plat "$platformsOutput" '. + $plat'),") - fi - done < <(yq -r 'to_entries | map_values({"value":.value, "index":.key}) | .[] | [.index, .value.source.repository, .value.source.ref, .value.target.repository, .value.target.tag] | @tsv' "$CONFIG_FILE") - - # Remove trailing commas and close JSON arrays - CONFIGS="${CONFIGS%,}]" -echo $CONFIGS \ No newline at end of file