Skip to content

Instantly share code, notes, and snippets.

@mgoellnitz
Last active January 9, 2024 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgoellnitz/d1ad62b99c98528fbbec648dd27f34cc to your computer and use it in GitHub Desktop.
Save mgoellnitz/d1ad62b99c98528fbbec648dd27f34cc to your computer and use it in GitHub Desktop.
Find GitHub/Forgejo/Gitea actions files and check for latest versions
#!/bin/bash
#
# Copyright 2023-2024 Martin Goellnitz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
NOW=$(date +%s)
VERSIONS=~/.actions.cache.txt
touch $VERSIONS
for folder in $(find -type d -name "workflows"|grep "^..\.") ; do
forge=$(echo $folder|cut -d '/' -f 2)
if [ "$forge" = ".forgejo" ] ; then
BASE_URI="https://code.forgejo.org/api/v1/repos"
TOKEN=
fi
if [ "$forge" = ".gitea" ] ; then
BASE_URI="https://gitea.com/api/v1/repos"
TOKEN=
fi
if [ "$forge" = ".github" ] ; then
BASE_URI="https://api.github.com/repos"
TOKEN=$GITHUB_COM_TOKEN
fi
for workflow in $(find $folder -type f -name "*.yml") ; do
for usage in $(grep "uses:.*@v[0-9][0-9]*$" $workflow|cut -d ':' -f 2-200|sed -e 's/\ //g') ; do
# echo "usage ($forge / $BASE_URI): $usage"
action=$(echo $usage|cut -d '@' -f 1)
version=$(echo $usage|cut -d '@' -f 2)
latest=
# echo $action - $version
CACHED=$(grep "^$forge@$action@" $VERSIONS)
if [ ! -z "$CACHED" ] ; then
latest="$(echo "$CACHED"|cut -d '@' -f 4-200)"
ACTUALITY=$(echo "$CACHED"|cut -d '@' -f 3)
if [ $[ $NOW - $ACTUALITY ] -gt 108000 ] ; then
grep "^$forge@$action@" -v $VERSIONS > ${VERSIONS}.tmp
mv ${VERSIONS}.tmp $VERSIONS
latest=
fi
fi
if [ -z "$latest" ] ; then
if [ -z "$(echo $action|grep ^https:)" ] ; then
URL="$BASE_URI/$action/tags"
else
URL="$(echo $action|sed -e 's/github.com/api.github.com\/repos/g')/tags"
fi
# echo $URL
AUTH=""
if [ ! -z "$TOKEN" ] ; then
AUTH="-H 'Authorization: token '$TOKEN"
fi
latest=$(curl $AUTH $URL 2> /dev/null|jq '.[]|.name'|grep -v '\.'|head -1|sed -e 's/"//g')
echo "$forge@$action@$NOW@$latest" >> $VERSIONS
fi
if [ "$version" != "$latest" ] ; then
echo "$workflow: $usage -> $latest"
fi
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment