mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
better processing of args
This commit is contained in:
@@ -14,13 +14,46 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check the arguments are valid
|
# Check the number of arguments are valid
|
||||||
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
|
if [ $# -gt 2 ]; then
|
||||||
echo "Error: Invalid arguments provided"
|
echo "Error: Invalid arguments provided"
|
||||||
echo "$help"
|
echo "$help"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
OVERRIDE_RELEASE=0
|
||||||
|
DRY_RUN=0
|
||||||
|
for arg in "$@"
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
--override-release)
|
||||||
|
OVERRIDE_RELEASE=1
|
||||||
|
shift # Remove --override-release from processing
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DRY_RUN=1
|
||||||
|
shift # Remove --dry-run from processing
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: Invalid argument provided: $arg"
|
||||||
|
echo "$help"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Describe what we're about to do based on the command-line arguments
|
||||||
|
if [ $OVERRIDE_RELEASE = 1 ]; then
|
||||||
|
echo "Publishing the current HEAD of the automodel repo"
|
||||||
|
else
|
||||||
|
echo "Publishing the version of the automodel repo specified by the latest official release of the codeml-automodel repo"
|
||||||
|
fi
|
||||||
|
if [ $DRY_RUN = 1 ]; then
|
||||||
|
echo "Dry run: we will step through the process but we won't publish the query pack"
|
||||||
|
else
|
||||||
|
echo "Not a dry run! Publishing the query pack"
|
||||||
|
fi
|
||||||
|
|
||||||
# If we're publishing the codeml-automodel release then we will checkout the sha specified in the release.
|
# If we're publishing the codeml-automodel release then we will checkout the sha specified in the release.
|
||||||
# So we need to check that there are no uncommitted changes in the local branch.
|
# So we need to check that there are no uncommitted changes in the local branch.
|
||||||
# And, if we're publishing the current HEAD, it's cleaner to ensure that there are no uncommitted changes.
|
# And, if we're publishing the current HEAD, it's cleaner to ensure that there are no uncommitted changes.
|
||||||
@@ -55,7 +88,7 @@ fi
|
|||||||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||||
CURRENT_SHA=$(git rev-parse HEAD)
|
CURRENT_SHA=$(git rev-parse HEAD)
|
||||||
|
|
||||||
if [ "$1" = "--override-release" ] || [ "$2" = "--override-release" ]; then
|
if [ $OVERRIDE_RELEASE = 1 ]; then
|
||||||
# Check that the current HEAD is downstream from PREVIOUS_RELEASE_SHA
|
# Check that the current HEAD is downstream from PREVIOUS_RELEASE_SHA
|
||||||
if ! git merge-base --is-ancestor "$PREVIOUS_RELEASE_SHA" "$CURRENT_SHA"; then
|
if ! git merge-base --is-ancestor "$PREVIOUS_RELEASE_SHA" "$CURRENT_SHA"; then
|
||||||
echo "Error: The current HEAD is not downstream from the previous release"
|
echo "Error: The current HEAD is not downstream from the previous release"
|
||||||
@@ -103,7 +136,7 @@ pushd "$WORKSPACE_ROOT"
|
|||||||
echo "Preparing the release"
|
echo "Preparing the release"
|
||||||
"${CODEQL_DIST}/codeql" pack release --groups $GRPS -v
|
"${CODEQL_DIST}/codeql" pack release --groups $GRPS -v
|
||||||
|
|
||||||
if [ "$1" = "--dry-run" ] || [ "$2" = "--dry-run" ]; then
|
if [ $DRY_RUN = 1 ]; then
|
||||||
echo "Dry run: not publishing the query pack"
|
echo "Dry run: not publishing the query pack"
|
||||||
"${CODEQL_DIST}/codeql" pack publish --groups $GRPS --dry-run -v
|
"${CODEQL_DIST}/codeql" pack publish --groups $GRPS --dry-run -v
|
||||||
else
|
else
|
||||||
@@ -132,12 +165,12 @@ mv ./src/qlpack.yml ./src/qlpack.yml.dry-run
|
|||||||
mv "$NEW_CHANGE_NOTES_FILE" ./src/change-notes/released.md.dry-run
|
mv "$NEW_CHANGE_NOTES_FILE" ./src/change-notes/released.md.dry-run
|
||||||
|
|
||||||
# If --override-release was not specified, then we need to checkout the original branch
|
# If --override-release was not specified, then we need to checkout the original branch
|
||||||
if [ "$1" != "--override-release" ] && [ "$2" != "--override-release" ]; then
|
if [ $OVERRIDE_RELEASE != 1 ]; then
|
||||||
echo "Checking out the original branch"
|
echo "Checking out the original branch"
|
||||||
git checkout "$CURRENT_BRANCH" --force
|
git checkout "$CURRENT_BRANCH" --force
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "--dry-run" ] || [ "$2" = "--dry-run" ]; then
|
if [ $DRY_RUN = 1 ]; then
|
||||||
echo "Inspect the updated dry-run version files:"
|
echo "Inspect the updated dry-run version files:"
|
||||||
ls -l ./src/*.dry-run
|
ls -l ./src/*.dry-run
|
||||||
ls -l ./src/change-notes/*.dry-run
|
ls -l ./src/change-notes/*.dry-run
|
||||||
|
|||||||
Reference in New Issue
Block a user