Skip to content

Commit

Permalink
feat: setup CI
Browse files Browse the repository at this point in the history
  • Loading branch information
aeimer committed Oct 23, 2023
1 parent 59d517b commit 985893f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .ci-scripts/generate-aliases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail

# Enable debug - print commands
#set -x

# Check if needed programms are installe
yq version >/dev/null || {
echo "yq needs to be installed"
exit 1
}

tmpDir="/tmp/parsed-formula"

# TODO: Use search for symlinks and delete instead of plain rm
echo "Delete symlinks in Alaises folder"
rm -f Alises/*.rb

echo "Generating Aliases from provided config:"
for formulaVersionsFile in $(ls -l1 "$tmpDir"/*.yaml); do
echo "- $(basename "$formulaVersionsFile") ($(yq 'length' "$formulaVersionsFile") versions found)"
echo "TODO: Do magic and create the Alias symlink files"
# ln -s foo bar
done
55 changes: 55 additions & 0 deletions .ci-scripts/parse-formulas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
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"
fi

mkdir "$tmpDir"

echo "Sort Formula:"
for formulaFile in $(ls -la1 Formula); do
if [[ "$formulaFile" =~ ^\. ]]; then
echo -e "- $formulaFile\t| Skipping file as it starts with a dot"
continue
elif [[ ! "$formulaFile" =~ .+\.rb$ ]]; then
echo -e "- $formulaFile\t| Skipping as files does not end with .rb"
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 <<EOF >> "$tmpDir/$fName.yaml"
- major: '$fMajor'
minor: '$fMinor'
bugfix: '$fBugfix'
builtag: '$fBuildtag'
EOF
done

echo "Config files wrote to $tmpDir:"
(
cd "$tmpDir"
ls -la1 *.yaml
) || true
14 changes: 14 additions & 0 deletions .github/workflows/check-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Run checks and tests
run-name: Run checks and tests ⚡️
on: [push]
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
scandir: './ci-scripts'
10 changes: 8 additions & 2 deletions .github/workflows/create-aliases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: debug - list files in Formula
- name: Install packages
run: |
ls -lah Formula
# https://github.com/marketplace/actions/yq-portable-yaml-processor
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq
- name: Parse Formula
run: .ci-scripts/parse-formulas.sh
- name: Generate Alias
run: .ci-scripts/generate-aliases.sh
Empty file added Formula/foo@1.2.3-rc.1.rb
Empty file.
Empty file added Formula/foo@1.2.3.rb
Empty file.

0 comments on commit 985893f

Please sign in to comment.