From 0b23b8597dc6041391a33980fa8740f112c9b6bc Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 15 Dec 2023 10:09:13 +0100 Subject: [PATCH 1/2] Refactor auto-update scripts. --- .github/create_submodule_update_pr.sh | 70 +++++++++++++++++++ .../check_doxygen_awesome_version.yml | 31 +------- 2 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 .github/create_submodule_update_pr.sh diff --git a/.github/create_submodule_update_pr.sh b/.github/create_submodule_update_pr.sh new file mode 100644 index 000000000..f4c2de427 --- /dev/null +++ b/.github/create_submodule_update_pr.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# Usage: +# $0 PACKAGE_NAME VERSION +# +# Before calling this script, run the commands to update the dependency. If +# there dependency shouldn't update then the script must not modify the repo. +# +# When the repo is in the updated state, run this script. It will commit +# everything and create a PR. +# +# The PR title is `Update ${PACKAGE_NAME} to ${VERSION}` the script checks for +# this string and only creates a new PR if the string isn't the title of an +# existing PR. +# +# PACKAGE_NAME is an identifier of the package, no spaces. Doesn't need to be +# the exact name of the dependency. +# +# VERSION an identifier of the next version of the package, no spaces. This +# variable must be the same if the version if the same and different if +# the version is different. However, it doesn't have to be a `x.y.z` it +# could be a Git SHA, or something else. + +set -e + +PACKAGE_NAME=$1 +VERSION=$2 +BRANCH=update-${PACKAGE_NAME}-${VERSION} +COMMIT_MESSAGE="Update ${PACKAGE_NAME} to ${VERSION}" + +if [[ -z "${PACKAGE_NAME}" ]] +then + echo "Empty PACKAGE_NAME." + exit -1 +fi + +if [[ -z "${VERSION}" ]] +then + echo "Empty VERSION." + exit -1 +fi + + +# NOTE: In a later runs of CI we will search for PR with this exact +# title. Only if no such PR exists will the script create a +# new PR. +PR_TITLE="Update ${PACKAGE_NAME} to ${VERSION}" + +if [[ -z "$(git status --porcelain)" ]] +then + echo "No differences detected: ${PACKAGE_NAME} is up-to-date." + exit 0 +fi + +if [[ -z "$(gh pr list --state all --search "${PR_TITLE}")" ]] +then + + git checkout -b $BRANCH + git config user.name github-actions + git config user.email github-actions@github.com + git commit -a -m "${COMMIT_MESSAGE}" + + git push -u origin ${BRANCH} + gh pr create \ + --title "${PR_TITLE}" \ + --body "This PR was generated by a Github Actions workflow." + +else + echo "Old PR detected: didn't create a new one." +fi diff --git a/.github/workflows/check_doxygen_awesome_version.yml b/.github/workflows/check_doxygen_awesome_version.yml index 233577ef8..2e4df2833 100644 --- a/.github/workflows/check_doxygen_awesome_version.yml +++ b/.github/workflows/check_doxygen_awesome_version.yml @@ -17,33 +17,4 @@ jobs: run: | VERSION=$(doc/doxygen-awesome-css/update_doxygen_awesome.sh "$(mktemp -d)") - BRANCH=update-doxygen-awesome-${VERSION} - COMMIT_MESSAGE="Update doxygen-awesome to ${VERSION}" - - # NOTE: In a later runs of CI we will search for PR with this exact - # title. Only if no such PR exists will the script create a - # new PR. - PR_TITLE="[docs] Update doxygen-awesome to ${VERSION}" - - if [[ -z "$(git status --porcelain)" ]] - then - echo "No differences detected: doxygen-awesome is up-to-date." - exit 0 - fi - - if [[ -z "$(gh pr list --state all --search "${PR_TITLE}")" ]] - then - - git checkout -b $BRANCH - git config user.name github-actions - git config user.email github-actions@github.com - git commit -a -m "${COMMIT_MESSAGE}" - - git push -u origin ${BRANCH} - gh pr create \ - --title "${PR_TITLE}" \ - --body "This PR was generated by a Github Actions workflow." - - else - echo "Old PR detected: didn't create a new one." - fi + .github/create_submodule_update_pr.sh doxygen-awesome ${VERSION} From 7e41a3bd36550708df3c7214a2183e75cff7b315 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Tue, 19 Dec 2023 13:10:18 +0100 Subject: [PATCH 2/2] set -u --- .github/create_submodule_update_pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/create_submodule_update_pr.sh b/.github/create_submodule_update_pr.sh index f4c2de427..d43dc1d77 100644 --- a/.github/create_submodule_update_pr.sh +++ b/.github/create_submodule_update_pr.sh @@ -21,7 +21,7 @@ # the version is different. However, it doesn't have to be a `x.y.z` it # could be a Git SHA, or something else. -set -e +set -eu PACKAGE_NAME=$1 VERSION=$2