Skip to content

Commit 0f76fba

Browse files
committed
better processing of args
1 parent 749f8b9 commit 0f76fba

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

java/ql/automodel/publish.sh

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,46 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
1414
exit 0
1515
fi
1616

17-
# Check the arguments are valid
18-
if [ $# -gt 2 ] || ([ $# -eq 1 ] && [ "$1" != "--override-release" ] && [ "$1" != "--dry-run" ]) || ([ $# -eq 2 ] && [ "$1" != "--override-release" ] && [ "$1" != "--dry-run" ] && [ "$2" != "--override-release" ] && [ "$2" != "--dry-run" ]); then
17+
# Check the number of arguments are valid
18+
if [ $# -gt 2 ]; then
1919
echo "Error: Invalid arguments provided"
2020
echo "$help"
2121
exit 1
2222
fi
2323

24+
OVERRIDE_RELEASE=0
25+
DRY_RUN=0
26+
for arg in "$@"
27+
do
28+
case $arg in
29+
--override-release)
30+
OVERRIDE_RELEASE=1
31+
shift # Remove --override-release from processing
32+
;;
33+
--dry-run)
34+
DRY_RUN=1
35+
shift # Remove --dry-run from processing
36+
;;
37+
*)
38+
echo "Error: Invalid argument provided: $arg"
39+
echo "$help"
40+
exit 1
41+
;;
42+
esac
43+
done
44+
45+
# Describe what we're about to do based on the command-line arguments
46+
if [ $OVERRIDE_RELEASE = 1 ]; then
47+
echo "Publishing the current HEAD of the automodel repo"
48+
else
49+
echo "Publishing the version of the automodel repo specified by the latest official release of the codeml-automodel repo"
50+
fi
51+
if [ $DRY_RUN = 1 ]; then
52+
echo "Dry run: we will step through the process but we won't publish the query pack"
53+
else
54+
echo "Not a dry run! Publishing the query pack"
55+
fi
56+
2457
# If we're publishing the codeml-automodel release then we will checkout the sha specified in the release.
2558
# So we need to check that there are no uncommitted changes in the local branch.
2659
# And, if we're publishing the current HEAD, it's cleaner to ensure that there are no uncommitted changes.
@@ -55,7 +88,7 @@ fi
5588
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
5689
CURRENT_SHA=$(git rev-parse HEAD)
5790

58-
if [ "$1" = "--override-release" ] || [ "$2" = "--override-release" ]; then
91+
if [ $OVERRIDE_RELEASE = 1 ]; then
5992
# Check that the current HEAD is downstream from PREVIOUS_RELEASE_SHA
6093
if ! git merge-base --is-ancestor "$PREVIOUS_RELEASE_SHA" "$CURRENT_SHA"; then
6194
echo "Error: The current HEAD is not downstream from the previous release"
@@ -103,7 +136,7 @@ pushd "$WORKSPACE_ROOT"
103136
echo "Preparing the release"
104137
"${CODEQL_DIST}/codeql" pack release --groups $GRPS -v
105138

106-
if [ "$1" = "--dry-run" ] || [ "$2" = "--dry-run" ]; then
139+
if [ $DRY_RUN = 1 ]; then
107140
echo "Dry run: not publishing the query pack"
108141
"${CODEQL_DIST}/codeql" pack publish --groups $GRPS --dry-run -v
109142
else
@@ -132,12 +165,12 @@ mv ./src/qlpack.yml ./src/qlpack.yml.dry-run
132165
mv "$NEW_CHANGE_NOTES_FILE" ./src/change-notes/released.md.dry-run
133166

134167
# If --override-release was not specified, then we need to checkout the original branch
135-
if [ "$1" != "--override-release" ] && [ "$2" != "--override-release" ]; then
168+
if [ $OVERRIDE_RELEASE != 1 ]; then
136169
echo "Checking out the original branch"
137170
git checkout "$CURRENT_BRANCH" --force
138171
fi
139172

140-
if [ "$1" = "--dry-run" ] || [ "$2" = "--dry-run" ]; then
173+
if [ $DRY_RUN = 1 ]; then
141174
echo "Inspect the updated dry-run version files:"
142175
ls -l ./src/*.dry-run
143176
ls -l ./src/change-notes/*.dry-run

0 commit comments

Comments
 (0)