Skip to content

Commit

Permalink
feat: harden scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
aeimer committed Oct 25, 2023
1 parent 38ca6ac commit 3771f75
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .ci-scripts/enforce-formula-policies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ yq --version >/dev/null || {
}

echo "Remove over-specific versions:"
for formulaVersionsFile in "$TAP_GEN_TMP_PATH"/*.yaml; do
while read -r formulaVersionsFile; do
fName=$(basename "${formulaVersionsFile%.yaml}")
echo "- $fName ($(yq 'length' "$formulaVersionsFile") versions found)"
echo "- $fName ($(yq 'length' "$formulaVersionsFile") versions)"

# Remove over-specific formula
while read -r fVersion; do
Expand All @@ -24,4 +24,4 @@ for formulaVersionsFile in "$TAP_GEN_TMP_PATH"/*.yaml; do
echo " - Removing $fFilename"
rm -f "Formula/$fFilename"
done < <(yq -e -oj -I0 '.[] | select(.bugfix != "" or .buildtag != "")' <"$formulaVersionsFile" 2>/dev/null)
done
done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -name '*.yaml')
4 changes: 2 additions & 2 deletions .ci-scripts/generate-aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ echo "Delete symlinks in Aliases folder"
rm -f Aliases/*.rb

echo "Generating Aliases from provided config:"
for formulaVersionsFile in "$TAP_GEN_TMP_PATH"/*.yaml; do
while read -r formulaVersionsFile; do
fName=$(basename "${formulaVersionsFile%.yaml}")
echo "- $fName ($(yq 'length' "$formulaVersionsFile") versions found)"

Expand Down Expand Up @@ -100,7 +100,7 @@ for formulaVersionsFile in "$TAP_GEN_TMP_PATH"/*.yaml; do
echo " - Skipping $symlinkName for $symlinkTarget => Formula exists"
fi
done < <(yq -e -ot -I0 '[.[] | .major] | unique | sort | .[]' <"$formulaVersionsFile")
done
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))"
8 changes: 4 additions & 4 deletions .ci-scripts/install-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
# Enable debug - print commands
#set -x

aptGetInstallPackages=(wget)
aptGetInstallPackages=(git wget)

# Detect environment
if [[ -n "${GITLAB_CI:-}" ]]; then
Expand All @@ -19,16 +19,16 @@ else
fi

# Install needed packages
echo "Installing packages with apt: ${aptGetInstallPackages[*]}"
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[*]}"
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[*]}"
sudo apt-get -qy install "${aptGetInstallPackages[@]}"
fi

# Install yq
Expand Down
8 changes: 4 additions & 4 deletions .ci-scripts/parse-formulas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ set -euo pipefail
TAP_GEN_TMP_PATH=".parsed-formula"

if [[ -d "$TAP_GEN_TMP_PATH" ]]; then
echo "$TAP_GEN_TMP_PATH already exists, deleting! => Should happen only locally..."
echo "$TAP_GEN_TMP_PATH already exists, deleting!"
rm -rf "$TAP_GEN_TMP_PATH"
fi

mkdir "$TAP_GEN_TMP_PATH"

echo "Sort Formula:"
for formulaFile in Formula/*.rb; do
while read -r formulaFile; do
formulaFile=$(basename "$formulaFile")

if [[ "$formulaFile" =~ ^\. ]]; then
Expand Down Expand Up @@ -46,10 +46,10 @@ for formulaFile in Formula/*.rb; do
buildtag: '$fBuildtag'
filename: '$formulaFile'
EOF
done
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
ls -a1 ./*.yaml || echo "No config files written..."
) || true
2 changes: 1 addition & 1 deletion .ci-scripts/update-toc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function generateToc() {
formulaName=${file//.yaml/}
1>&2 echo " - $formulaName"
printf -- "* %s\n" "$formulaName"
done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -regex '.*\.yaml' -exec basename {} \; | sort)
done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -name '*.yaml' -exec basename {} \; | sort)
}

echo "Generating TOC in README.md"
Expand Down

0 comments on commit 3771f75

Please sign in to comment.