Skip to content

Commit

Permalink
feat: rework ci run on gitlab and github
Browse files Browse the repository at this point in the history
  • Loading branch information
aeimer committed Oct 25, 2023
1 parent b49873f commit b5c4971
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
4 changes: 1 addition & 3 deletions .ci-scripts/enforce-formula-policies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ yq --version >/dev/null || {
exit 1
}

tmpDir="/tmp/parsed-formula"

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

Expand Down
4 changes: 1 addition & 3 deletions .ci-scripts/generate-aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ yq --version >/dev/null || {
exit 1
}

tmpDir="/tmp/parsed-formula"

aliasesCountBefore=$( (ls -1 Aliases/*.rb 2>/dev/null || true) | wc -l | tr -d ' ')
echo "Found $aliasesCountBefore aliases beforehand"

Expand All @@ -40,7 +38,7 @@ echo "Delete symlinks in Aliases folder"
rm -f Aliases/*.rb

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

Expand Down
28 changes: 27 additions & 1 deletion .ci-scripts/install-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,35 @@ set -euo pipefail
# Enable debug - print commands
#set -x

aptGetInstallPackages=(wget)

# 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

# Install needed packages
echo "Installing packages with apt: ${aptGetInstallPackages[*]}"
# Install apt requirements
if [[ "$runnerType" == "gitlab" ]]; then
apt-get update
apt-get -qy install "${aptGetInstallPackages[*]}"
elif [[ "$runnerType" == "github" ]]; then
sudo apt-get -q update
sudo apt-get -qy install "${aptGetInstallPackages[*]}"
fi

# Install yq
# https://github.com/marketplace/actions/yq-portable-yaml-processor
wget -q -O yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
chmod +x yq
sudo mv yq /usr/bin/yq
test "$runnerType" = "gitlab" && mv yq /usr/bin/yq
test "$runnerType" = "github" && sudo mv yq /usr/bin/yq

16 changes: 7 additions & 9 deletions .ci-scripts/parse-formulas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ set -euo pipefail
# Enable debug - print commands
#set -x

tmpDir="/tmp/parsed-formula"

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

mkdir "$tmpDir"
mkdir "$TAP_GEN_TMP_PATH"

echo "Sort Formula:"
for formulaFile in Formula/*.rb; do
Expand Down Expand Up @@ -39,7 +37,7 @@ for formulaFile in Formula/*.rb; do

echo -e "- $formula\t| Found values: '$fName' '$fMajor' '$fMinor' '$fBugfix' '$fBuildtag'"

cat <<EOF >>"$tmpDir/$fName.yaml"
cat <<EOF >>"$TAP_GEN_TMP_PATH/$fName.yaml"
- major: '$fMajor'
minor: '$fMinor'
bugfix: '$fBugfix'
Expand All @@ -48,8 +46,8 @@ for formulaFile in Formula/*.rb; do
EOF
done

echo "Config files wrote to $tmpDir:"
echo "Config files wrote to $TAP_GEN_TMP_PATH:"
(
cd "$tmpDir"
cd "$TAP_GEN_TMP_PATH"
ls -a1 ./*.yaml
) || true
2 changes: 1 addition & 1 deletion .ci-scripts/update-toc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function generateToc() {
formulaName=${file//.yaml/}
1>&2 echo " - $formulaName"
printf -- "* %s\n" "$formulaName"
done < <(find /tmp/parsed-formula -maxdepth 1 -type f -regex '.*\.yaml' -exec basename {} \; | sort)
done < <(find "$TAP_GEN_TMP_PATH" -maxdepth 1 -type f -regex '.*\.yaml' -exec basename {} \; | sort)
}

echo "Generating TOC in README.md"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/create-aliases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:
jobs:
update-alises:
runs-on: ubuntu-latest
env:
TAP_GEN_TMP_PATH: /tmp/parsed-formula
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand Down

0 comments on commit b5c4971

Please sign in to comment.