Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 065234d

Browse files
authored
Refactor auto-update scripts. (#894)
1 parent 5e1a92f commit 065234d

2 files changed

Lines changed: 71 additions & 30 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
# Usage:
4+
# $0 PACKAGE_NAME VERSION
5+
#
6+
# Before calling this script, run the commands to update the dependency. If
7+
# there dependency shouldn't update then the script must not modify the repo.
8+
#
9+
# When the repo is in the updated state, run this script. It will commit
10+
# everything and create a PR.
11+
#
12+
# The PR title is `Update ${PACKAGE_NAME} to ${VERSION}` the script checks for
13+
# this string and only creates a new PR if the string isn't the title of an
14+
# existing PR.
15+
#
16+
# PACKAGE_NAME is an identifier of the package, no spaces. Doesn't need to be
17+
# the exact name of the dependency.
18+
#
19+
# VERSION an identifier of the next version of the package, no spaces. This
20+
# variable must be the same if the version if the same and different if
21+
# the version is different. However, it doesn't have to be a `x.y.z` it
22+
# could be a Git SHA, or something else.
23+
24+
set -eu
25+
26+
PACKAGE_NAME=$1
27+
VERSION=$2
28+
BRANCH=update-${PACKAGE_NAME}-${VERSION}
29+
COMMIT_MESSAGE="Update ${PACKAGE_NAME} to ${VERSION}"
30+
31+
if [[ -z "${PACKAGE_NAME}" ]]
32+
then
33+
echo "Empty PACKAGE_NAME."
34+
exit -1
35+
fi
36+
37+
if [[ -z "${VERSION}" ]]
38+
then
39+
echo "Empty VERSION."
40+
exit -1
41+
fi
42+
43+
44+
# NOTE: In a later runs of CI we will search for PR with this exact
45+
# title. Only if no such PR exists will the script create a
46+
# new PR.
47+
PR_TITLE="Update ${PACKAGE_NAME} to ${VERSION}"
48+
49+
if [[ -z "$(git status --porcelain)" ]]
50+
then
51+
echo "No differences detected: ${PACKAGE_NAME} is up-to-date."
52+
exit 0
53+
fi
54+
55+
if [[ -z "$(gh pr list --state all --search "${PR_TITLE}")" ]]
56+
then
57+
58+
git checkout -b $BRANCH
59+
git config user.name github-actions
60+
git config user.email github-actions@github.com
61+
git commit -a -m "${COMMIT_MESSAGE}"
62+
63+
git push -u origin ${BRANCH}
64+
gh pr create \
65+
--title "${PR_TITLE}" \
66+
--body "This PR was generated by a Github Actions workflow."
67+
68+
else
69+
echo "Old PR detected: didn't create a new one."
70+
fi

.github/workflows/check_doxygen_awesome_version.yml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,4 @@ jobs:
1717
run: |
1818
1919
VERSION=$(doc/doxygen-awesome-css/update_doxygen_awesome.sh "$(mktemp -d)")
20-
BRANCH=update-doxygen-awesome-${VERSION}
21-
COMMIT_MESSAGE="Update doxygen-awesome to ${VERSION}"
22-
23-
# NOTE: In a later runs of CI we will search for PR with this exact
24-
# title. Only if no such PR exists will the script create a
25-
# new PR.
26-
PR_TITLE="[docs] Update doxygen-awesome to ${VERSION}"
27-
28-
if [[ -z "$(git status --porcelain)" ]]
29-
then
30-
echo "No differences detected: doxygen-awesome is up-to-date."
31-
exit 0
32-
fi
33-
34-
if [[ -z "$(gh pr list --state all --search "${PR_TITLE}")" ]]
35-
then
36-
37-
git checkout -b $BRANCH
38-
git config user.name github-actions
39-
git config user.email github-actions@github.com
40-
git commit -a -m "${COMMIT_MESSAGE}"
41-
42-
git push -u origin ${BRANCH}
43-
gh pr create \
44-
--title "${PR_TITLE}" \
45-
--body "This PR was generated by a Github Actions workflow."
46-
47-
else
48-
echo "Old PR detected: didn't create a new one."
49-
fi
20+
.github/create_submodule_update_pr.sh doxygen-awesome ${VERSION}

0 commit comments

Comments
 (0)