Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
add workflow to delete older runs
Browse files Browse the repository at this point in the history
  • Loading branch information
bodsch committed Oct 16, 2023
1 parent 5b78107 commit d63ca64
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 5 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/clean-workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

name: delete workflow runs

on:
schedule:
- cron: "10 4 * * 0"
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug

jobs:
delete-workflow-runs:
runs-on: ubuntu-latest
name: delete old workflow runs
steps:
- name: Delete workflow runs
uses: MajorScruffy/delete-old-workflow-runs@v0.3.0
with:
repository: bodsch/ansible-container
older-than-seconds: 2592000 # remove all workflow runs older than 30 day
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 65 additions & 0 deletions hooks/molecule.rc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,68 @@ then
fi

TOX_OPTS="-e ${TOX_ANSIBLE}"

vercomp() {

[[ $1 == $2 ]] && return 0
v1=$(echo "$1" | sed -e 's|-|.|g')
v2=$(echo "$2" | sed -e 's|-|.|g')

local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done

for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}

install_collection() {
local collection="${1}"

echo "Install the required collection '${collection}'"
ansible-galaxy collection install ${collection}
}

remove_collection() {

local collection="${1}"

namespace="$(echo "${collection}" | cut -d '.' -f1)"
name="$(echo "${collection}" | cut -d '.' -f2)"

collection="${HOME}/.ansible/collections/ansible_collections/${namespace}/${name}"

rm \
--recursive \
--force \
"${collection}"
}

publish() {

TOKEN="${HOME}/.ansible/galaxy_token"

if [ -e "${TOKEN}" ]
then
ansible-galaxy import --token=$(cat "${TOKEN}") bodsch # "???"
fi
}
33 changes: 28 additions & 5 deletions hooks/tox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,41 @@ then
for collection in $(grep -v "#" collections.yml | grep "^ - name: " | awk -F ': ' '{print $2}')
do
collections_installed="$(ansible-galaxy collection list | grep ${collection} 2> /dev/null)"
#version=$(yq -r \
# ".collections[] | select(.name == \"${collection}\") | .version" collections.yml)

if [ -z "${collections_installed}" ]
then
echo "Install the required collection '${collection}'"

ansible-galaxy collection install ${collection}
install_collection ${collection}
else
collection_version=$(echo "${collections_installed}" | awk -F ' ' '{print $2}')
version="$(grep -v "#" collections.yml | grep -A1 "^ - name: ${collection}" | grep "version: " 2> /dev/null | awk -F ': ' '{print $2}' | sed -e 's|=||' -e 's|>||' -e 's|"||g')"

echo "The required collection '${collection}' is installed in version ${collection_version}."

if [ ! -z "${version}" ]
then

vercomp "${version}" "${collection_version}"

case $? in
0) op='=' ;;
1) op='>' ;;
2) op='<' ;;
esac

if [[ $op = "=" ]] || [[ $op = ">" ]]
then
# echo "FAIL: Expected '$3', Actual '$op', Arg1 '$1', Arg2 '$2'"
echo "re-install for version ${version}"

remove_collection ${collection}
install_collection ${collection}
else
:
# echo "Pass: '$1 $op $2'"
fi
else
:
fi
fi
done
echo ""
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ deps =
ansible_6.1: ansible>=6.1,<6.2
ansible_6.7: ansible>=6.7,<6.8
ansible_7.0: ansible>=7.0,<7.1
ansible_7.5: ansible>=7.5,<7.6
ansible_8.0: ansible>=8.0,<8.1
ansible_8.5: ansible>=8.5,<8.6

#commands_pre =
# /usr/bin/find {toxinidir} -type f -not -path '{toxworkdir}/*' -path '*/__pycache__/*' -name '*.py[c|o]' -delete
Expand Down

0 comments on commit d63ca64

Please sign in to comment.