Skip to content

update-versions #109074

update-versions

update-versions #109074

name: update-versions
on:
workflow_dispatch:
schedule:
- cron: '*/15 * * * *'
repository_dispatch:
types: [update-versions-webhook]
jobs:
do-work:
runs-on: ubuntu-latest
steps:
- name: Git Config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Do Work
env:
REPOSITORY_OWNER: ${{ github.repository_owner }}
GH_ACTOR: ${{ github.actor }}
GH_TOKEN: ${{ github.token }}
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
REPOSITORY_FILTER: ${{ github.event.client_payload.repo }}
BRANCH_FILTER: ${{ github.event.client_payload.branch }}
run: |
while read REPOSITORY; do
while IFS= read -r BRANCH; do
git clone -b "${BRANCH}" "https://${PERSONAL_TOKEN}@github.com/${REPOSITORY_OWNER}/${REPOSITORY}.git"
cd "${REPOSITORY}" || exit 1
###########################################
old_version="$(jq -r '.version' < VERSION.json)"
[[ -f update-versions.sh ]] && GITHUB_ACTOR=${GH_ACTOR} GITHUB_TOKEN=${GH_TOKEN} bash ./update-versions.sh || continue
if new_version="$(jq -re '.version' < VERSION.json)"; then
commit_message="Version update: ${old_version} => ${new_version}"
discord_message="Version changes detected: \`${old_version}\` => \`${new_version}\`"
else
commit_message="Version update"
discord_message="Version changes detected."
fi
git add .
if git commit -m "${commit_message}"; then
git push
GIT_SHA=$(git log -n 1 --pretty=format:"%H")
json=$(jq -nc --arg title "${REPOSITORY_OWNER}/${REPOSITORY}:${BRANCH}" \
--arg url "https://github.com/${REPOSITORY_OWNER}/${REPOSITORY}/commit/${GIT_SHA}" \
--arg description "${discord_message}" \
--argjson color "4886754" \
--arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")" \
'{"embeds": [
{
"title": $title,
"url": $url,
"description": $description,
"color": $color,
"footer": {"text": "Powered by GitHub Actions"},
"timestamp": $timestamp
}
]}')
jq <<< "${json}"
curl -fsSL -X POST -H "Content-Type: application/json" -d "${json}" "${DISCORD_WEBHOOK}"
fi
###########################################
cd .. || exit 1
rm -rf "${REPOSITORY}"
done < <(curl -u "${GH_ACTOR}:${GH_TOKEN}" -fsSL "https://api.github.com/repos/${REPOSITORY_OWNER}/${REPOSITORY}/branches" | jq -re --arg branch_filter "${BRANCH_FILTER}" '.[] | select(.name!="master") | select(.name|test("\($branch_filter)")) | .name')
done < <(curl -u "${GH_ACTOR}:${GH_TOKEN}" -fsSL "https://api.github.com/users/${REPOSITORY_OWNER}/repos?per_page=1000" | jq -re --arg repository_filter "${REPOSITORY_FILTER}" '.[] | select(.topics[]=="docker-image") | select(.name|test("\($repository_filter)")) | .name')