From 7dafbc2a6e9a19bf54f472f323514938377943d9 Mon Sep 17 00:00:00 2001 From: Alexander Eimer Date: Wed, 25 Oct 2023 17:05:53 +0200 Subject: [PATCH] fix: adapt to brew --- .ci-scripts/enforce-formula-policies.sh | 27 ----- .ci-scripts/env.sh | 16 --- .ci-scripts/generate-aliases.sh | 106 ------------------ .ci-scripts/install-packages.sh | 35 ------ .ci-scripts/parse-formulas.sh | 55 --------- .ci-scripts/update-toc.sh | 18 +-- .../{create-aliases.yml => update-toc.yml} | 19 +--- Aliases/protocurl.rb | 1 - Aliases/protocurl@1.rb | 1 - Formula/protocurl@1.9.rb | 50 --------- 10 files changed, 13 insertions(+), 315 deletions(-) delete mode 100755 .ci-scripts/enforce-formula-policies.sh delete mode 100644 .ci-scripts/env.sh delete mode 100755 .ci-scripts/generate-aliases.sh delete mode 100755 .ci-scripts/install-packages.sh delete mode 100755 .ci-scripts/parse-formulas.sh rename .github/workflows/{create-aliases.yml => update-toc.yml} (59%) delete mode 120000 Aliases/protocurl.rb delete mode 120000 Aliases/protocurl@1.rb delete mode 100644 Formula/protocurl@1.9.rb diff --git a/.ci-scripts/enforce-formula-policies.sh b/.ci-scripts/enforce-formula-policies.sh deleted file mode 100755 index 03fb76c..0000000 --- a/.ci-scripts/enforce-formula-policies.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Enable debug - print commands -#set -x - -TAP_GEN_TMP_PATH=".parsed-formula" - -# Check if needed programms are installed -yq --version >/dev/null || { - echo "yq needs to be installed" - exit 1 -} - -echo "Remove over-specific versions:" -while read -r formulaVersionsFile; do - fName=$(basename "${formulaVersionsFile%.yaml}") - echo "- $fName ($(yq 'length' "$formulaVersionsFile") versions)" - - # Remove over-specific formula - while read -r fVersion; do - fFilename=$(yq -e -ot '.filename' <<<"$fVersion") - - echo " - Removing $fFilename" - rm -f "Formula/$fFilename" - done < <(yq -e -oj -I0 '.[] | select(.bugfix != "" or .buildtag != "")' <"$formulaVersionsFile" 2>/dev/null) -done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -name '*.yaml') diff --git a/.ci-scripts/env.sh b/.ci-scripts/env.sh deleted file mode 100644 index 6f37c1d..0000000 --- a/.ci-scripts/env.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Detect environment -if [[ -n "${GITLAB_CI:-}" ]]; then - echo "Detected GitLab" - runnerType="gitlab" -elif [[ -n "${GITHUB_REPOSITORY:-}" ]]; then - echo "Detected GitHub" - runnerType="github" -else - echo "No runnerType/platform detected" - exit 1 -fi - -export runnerType diff --git a/.ci-scripts/generate-aliases.sh b/.ci-scripts/generate-aliases.sh deleted file mode 100755 index fbbbe3c..0000000 --- a/.ci-scripts/generate-aliases.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Enable debug - print commands -#set -x - -TAP_GEN_TMP_PATH=".parsed-formula" - -# Functions - -function createSymlink() { - if [[ -z "$1" ]]; then - echo "Arg1 was empty" - exit 1 - fi - if [[ -z "$2" ]]; then - echo "Arg2 was empty" - exit 1 - fi - # Go to subfolder and create symlink - ( - cd Aliases - ln -s "../Formula/$1" "$2" - ) -} - -# CODE - -# Check if needed programms are installed -yq --version >/dev/null || { - echo "yq needs to be installed" - exit 1 -} - -aliasesCountBefore=$( (ls -1 Aliases/*.rb 2>/dev/null || true) | wc -l | tr -d ' ') -echo "Found $aliasesCountBefore aliases beforehand" - -# TODO: Use search for symlinks and delete instead of plain rm -echo "Delete symlinks in Aliases folder" -rm -f Aliases/*.rb - -echo "Generating Aliases from provided config:" -while read -r formulaVersionsFile; do - fName=$(basename "${formulaVersionsFile%.yaml}") - echo "- $fName ($(yq 'length' "$formulaVersionsFile") versions found)" - - # Check for valid object - test -n "$(yq -ot '[.[] | .bugfix + .buildtag | select(. != "")] | join(";")' "$formulaVersionsFile")" && { - echo "ERROR! INVALID INPUT! Bugfix or Buildtag field is set, parse-formulas must be buggy!" - exit 1 - } - - # Create latest if does not exists - if [[ ! -f "Formula/$fName.rb" ]]; then - # Get latest version - latestMajor=$(yq -ot \ - '[.[] | .major] | unique | sort | .[-1] // ""' \ - "$formulaVersionsFile") - latestMinor=$(yq -ot \ - '[.[] | select(.major == "'"$latestMajor"'") | .minor] | unique | sort | .[-1] // ""' \ - "$formulaVersionsFile") - - if [[ -z "$latestMajor" ]]; then - echo "WARNING! Major was empty ($latestMajor) => Must be a bug" - exit 1 - fi - - # Prepend dot if latest minor is not empty - test -n "$latestMinor" && latestMinor=".$latestMinor" - - # Build symlink names and create it - symlinkName="$fName.rb" - symlinkTarget=$(printf '%s@%s%s.rb' "$fName" "$latestMajor" "$latestMinor") - echo " - Creating $symlinkName for $symlinkTarget" - createSymlink "$symlinkTarget" "$symlinkName" - else - echo " - Skipping $fName for latest => already exists" - fi - - # Create all major of does not exist - while read -r majorVersion; do - echo " - Processing major-version $majorVersion" - - latestMinor=$(yq -ot \ - '[.[] | select(.major == "'"$majorVersion"'") | .minor] | unique | sort | .[-1] // ""' \ - "$formulaVersionsFile") - - # Prepend dot if latest minor is not empty - test -n "$latestMinor" && latestMinor=".$latestMinor" - - # Build symlink names and create it - symlinkName=$(printf '%s@%s.rb' "$fName" "$majorVersion") - symlinkTarget=$(printf '%s@%s%s.rb' "$fName" "$majorVersion" "$latestMinor") - - # Check if Formula exists, skip if so - if [[ ! -f "Formula/$symlinkName" ]]; then - echo " - Creating $symlinkName for $symlinkTarget" - createSymlink "$symlinkTarget" "$symlinkName" - else - echo " - Skipping $symlinkName for $symlinkTarget => Formula exists" - fi - done < <(yq -e -ot -I0 '[.[] | .major] | unique | sort | .[]' <"$formulaVersionsFile") -done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -name '*.yaml') - -aliasesCountAfter=$( (ls -1 Aliases/*.rb 2>/dev/null || true) | wc -l | tr -d ' ') -echo "Found $aliasesCountAfter aliases afterwards -- a change of $((aliasesCountAfter - aliasesCountBefore))" diff --git a/.ci-scripts/install-packages.sh b/.ci-scripts/install-packages.sh deleted file mode 100755 index 07c9274..0000000 --- a/.ci-scripts/install-packages.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Enable debug - print commands -#set -x - -SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" -# shellcheck source-path=.ci-scripts -source "$SCRIPT_PATH/env.sh" - -aptGetInstallPackages=(git wget) - -# Install needed packages -echo "Installing ${#aptGetInstallPackages[*]} packages with apt: ${aptGetInstallPackages[*]}" -# Install apt requirements -if [[ "$runnerType" == "gitlab" ]]; then - echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections - apt-get update - apt-get -qy install "${aptGetInstallPackages[@]}" -elif [[ "$runnerType" == "github" ]]; then - echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections - sudo apt-get -q update - sudo apt-get -qy install "${aptGetInstallPackages[@]}" -fi - -# Install yq -# https://github.com/marketplace/actions/yq-portable-yaml-processor -echo "Installing yq" -wget -q -O yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -chmod +x yq -if [[ "$runnerType" == "gitlab" ]]; then - mv yq /usr/bin/yq -elif [[ "$runnerType" == "github" ]]; then - sudo mv yq /usr/bin/yq -fi diff --git a/.ci-scripts/parse-formulas.sh b/.ci-scripts/parse-formulas.sh deleted file mode 100755 index aa434fe..0000000 --- a/.ci-scripts/parse-formulas.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Enable debug - print commands -#set -x - -TAP_GEN_TMP_PATH=".parsed-formula" - -if [[ -d "$TAP_GEN_TMP_PATH" ]]; then - echo "$TAP_GEN_TMP_PATH already exists, deleting!" - rm -rf "$TAP_GEN_TMP_PATH" -fi - -mkdir "$TAP_GEN_TMP_PATH" - -echo "Sort Formula:" -while read -r formulaFile; do - formulaFile=$(basename "$formulaFile") - - if [[ "$formulaFile" =~ ^\. ]]; then - echo -e "- $formulaFile\t| Skipping file as it starts with a dot" - continue - fi - - # Remove .rb suffix - formula=${formulaFile%.rb} - - if [[ ! "$formula" =~ ^[a-z0-9-]{2,}@([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-.+)?$ ]]; then - # https://regex101.com/r/DSC7cM/1 - echo -e "- $formula\t| Skipping Formula as it doesn't seem to versioned" - continue - fi - echo -e "- $formula\t| Processing..." - fName=$(sed -rn 's/^([a-z0-9-]{2,})@([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(-.+)?$/\1/p' <<<"$formula") - fMajor=$(sed -rn 's/^([a-z0-9-]{2,})@([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(-.+)?$/\2/p' <<<"$formula") - fMinor=$(sed -rn 's/^([a-z0-9-]{2,})@([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(-.+)?$/\4/p' <<<"$formula") - fBugfix=$(sed -rn 's/^([a-z0-9-]{2,})@([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(-.+)?$/\6/p' <<<"$formula") - fBuildtag=$(sed -rn 's/^([a-z0-9-]{2,})@([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(-.+)?$/\7/p' <<<"$formula") - - echo -e "- $formula\t| Found values: '$fName' '$fMajor' '$fMinor' '$fBugfix' '$fBuildtag'" - - cat <>"$TAP_GEN_TMP_PATH/$fName.yaml" -- major: '$fMajor' - minor: '$fMinor' - bugfix: '$fBugfix' - buildtag: '$fBuildtag' - filename: '$formulaFile' -EOF -done < <(find Formula -maxdepth 1 -type f -name '*.rb') - -echo "Config files wrote to $TAP_GEN_TMP_PATH:" -( - cd "$TAP_GEN_TMP_PATH" - ls -a1 ./*.yaml || echo "No config files written..." -) || true diff --git a/.ci-scripts/update-toc.sh b/.ci-scripts/update-toc.sh index 01f4045..1ac9339 100755 --- a/.ci-scripts/update-toc.sh +++ b/.ci-scripts/update-toc.sh @@ -4,16 +4,20 @@ set -euo pipefail # Enable debug - print commands #set -x -TAP_GEN_TMP_PATH=".parsed-formula" - function generateToc() { + programNameList=() + while read -r file; do - formulaName=${file//.yaml/} - 1>&2 echo " - $formulaName" - printf -- "* %s\n" "$formulaName" - done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -name '*.yaml' -exec basename {} \; | sort) + # shellcheck disable=SC2001 + programName=$(sed -E 's/(@.+)?\.rb//g' <<<"$file") + programNameList+=("$programName") + done < <(find "Formula" -maxdepth 1 -type f -name '*.rb' -exec basename {} \; | sort) + + printf "* %s\n" "${programNameList[@]}" | sort -u } echo "Generating TOC in README.md" +toc=$(generateToc) +echo "$toc" # https://stackoverflow.com/questions/2699666/replace-delimited-block-of-text-in-file-with-the-contents-of-another-file -sed -i -ne '// {p; r '<(generateToc) -e ':a; n; // {p; b}; ba}; p' README.md +sed -i -ne '// {p; r '<<<"$toc" -e ':a; n; // {p; b}; ba}; p' README.md diff --git a/.github/workflows/create-aliases.yml b/.github/workflows/update-toc.yml similarity index 59% rename from .github/workflows/create-aliases.yml rename to .github/workflows/update-toc.yml index 282a829..3973c66 100644 --- a/.github/workflows/create-aliases.yml +++ b/.github/workflows/update-toc.yml @@ -1,5 +1,5 @@ -name: Update brew Aliases -run-name: Updating brew Aliases 🚀 +name: Update TOC +run-name: Update TOC 🚀 on: push: branches: @@ -17,21 +17,6 @@ jobs: - name: Check out repository code uses: actions/checkout@v4 - - name: Install packages - run: .ci-scripts/install-packages.sh - - - name: Parse Formulas 1 - run: .ci-scripts/parse-formulas.sh - - - name: Enforce Formula Policies - run: .ci-scripts/enforce-formula-policies.sh - - - name: Parse Formulas 2 - run: .ci-scripts/parse-formulas.sh - - - name: Generate Aliases - run: .ci-scripts/generate-aliases.sh - - name: Update TOC run: .ci-scripts/update-toc.sh diff --git a/Aliases/protocurl.rb b/Aliases/protocurl.rb deleted file mode 120000 index 98ae016..0000000 --- a/Aliases/protocurl.rb +++ /dev/null @@ -1 +0,0 @@ -../Formula/protocurl@1.9.rb \ No newline at end of file diff --git a/Aliases/protocurl@1.rb b/Aliases/protocurl@1.rb deleted file mode 120000 index 98ae016..0000000 --- a/Aliases/protocurl@1.rb +++ /dev/null @@ -1 +0,0 @@ -../Formula/protocurl@1.9.rb \ No newline at end of file diff --git a/Formula/protocurl@1.9.rb b/Formula/protocurl@1.9.rb deleted file mode 100644 index c708e22..0000000 --- a/Formula/protocurl@1.9.rb +++ /dev/null @@ -1,50 +0,0 @@ -# typed: false -# frozen_string_literal: true - -# This file was generated by GoReleaser. DO NOT EDIT. -class ProtocurlAT190 < Formula - desc "protoCURL is cURL for Protobuf: The command-line tool for interacting with Protobuf over HTTP REST endpoints using human-readable text formats." - homepage "https://gitlab.com/qaware/protocurl" - version "1.9.0-rc" - license "MIT" - - depends_on "curl" - - on_macos do - if Hardware::CPU.intel? - url "https://github.com/qaware/protocurl/releases/v1.9.0-rc/protocurl_1.9.0-rc_darwin_amd64.zip" - sha256 "bb28baba4ba1013bee325be5a0a9e15776f724e82f8cd53d70fa41426d0f203e" - - def install - bin.install "protocurl" - end - end - if Hardware::CPU.arm? - url "https://github.com/qaware/protocurl/releases/v1.9.0-rc/protocurl_1.9.0-rc_darwin_arm64.zip" - sha256 "63f61e78e5cdf24501000e33d66f45488a04f2b135d636d6b31b51afb4cf919f" - - def install - bin.install "protocurl" - end - end - end - - on_linux do - if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? - url "https://github.com/qaware/protocurl/releases/v1.9.0-rc/protocurl_1.9.0-rc_linux_arm64.zip" - sha256 "36dfec0181402150009ec331d5e8145162e9fc9965f1f91e87d85508809a9101" - - def install - bin.install "protocurl" - end - end - if Hardware::CPU.intel? - url "https://github.com/qaware/protocurl/releases/v1.9.0-rc/protocurl_1.9.0-rc_linux_amd64.zip" - sha256 "5cf7384281016a7cd5c73ec7d559602fc114ac1a3643499fa72cc849dae05823" - - def install - bin.install "protocurl" - end - end - end -end