11#! /bin/bash
22set -e
33
4- # Add help message
4+ help=" Usage: ./publish --[override-release] --[dry-run]
5+ Publish the automodel query pack.
6+
7+ If no arguments are provided, publish the version of the codeql repo specified by the latest official release of the codeml-automodel repo.
8+ If the --override-release argument is provided, your current local HEAD is used (for unofficial releases or patching).
9+ If the --dry-run argument is provided, the release is not published (for testing purposes)."
10+
11+ # Echo the help message
512if [ " $1 " = " -h" ] || [ " $1 " = " --help" ]; then
6- echo " Usage: ./publish [override-release]"
7- echo " By default we publish the version of the codeql repo specified by the latest official release defined by the codeml-automodel repo."
8- echo " Otherwise, the optional argument override-release forces your current HEAD to be published."
13+ echo " $help "
914 exit 0
1015fi
1116
12- # Check that either there are 0 or 1 arguments, and if 1 argument then check that it is "override-release"
13- if [ $# -gt 1 ] || [ $# -eq 1 ] && [ " $1 " != " override-release" ]; then
14- echo " Error: Invalid arguments. Please run './publish --help' for usage information."
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
19+ echo " Error: Invalid arguments provided"
20+ echo " $help "
1521 exit 1
1622fi
1723
4955CURRENT_BRANCH=$( git rev-parse --abbrev-ref HEAD)
5056CURRENT_SHA=$( git rev-parse HEAD)
5157
52- if [ -z " ${1:- } " ]; then
53- # If the first argument is empty, use the latest release of codeml-automodel
58+ if [ " $1 " = " --override-release" ] || [ " $2 " = " --override-release" ]; then
59+ # Check that the current HEAD is downstream from PREVIOUS_RELEASE_SHA
60+ if ! git merge-base --is-ancestor " $PREVIOUS_RELEASE_SHA " " $CURRENT_SHA " ; then
61+ echo " Error: The current HEAD is not downstream from the previous release"
62+ exit 1
63+ fi
64+ else
65+ # Get the latest release of codeml-automodel
5466 TAG_NAME=$( gh api -H ' Accept: application/vnd.github+json' -H ' X-GitHub-Api-Version: 2022-11-28' /repos/github/codeml-automodel/releases/latest | jq -r .tag_name)
5567 # Check TAG_NAME is not empty
5668 if [ -z " $TAG_NAME " ]; then
@@ -73,12 +85,6 @@ if [ -z "${1:-}" ]; then
7385 fi
7486 # Get the version of the codeql code specified by the codeml-automodel release
7587 git checkout " $REVISION "
76- else
77- # Check that the current HEAD is downstream from PREVIOUS_RELEASE_SHA
78- if ! git merge-base --is-ancestor " $PREVIOUS_RELEASE_SHA " " $CURRENT_SHA " ; then
79- echo " Error: The current HEAD is not downstream from the previous release"
80- exit 1
81- fi
8288fi
8389
8490# Get the absolute path of the automodel repo
@@ -97,9 +103,13 @@ pushd "$WORKSPACE_ROOT"
97103echo " Preparing the release"
98104" ${CODEQL_DIST} /codeql" pack release --groups $GRPS -v
99105
100- echo " Publishing the release"
101- # Add --dry-run to test publishing
102- " ${CODEQL_DIST} /codeql" pack publish --groups $GRPS -v
106+ if [ " $1 " = " --dry-run" ] || [ " $2 " = " --dry-run" ]; then
107+ echo " Dry run: not publishing the query pack"
108+ " ${CODEQL_DIST} /codeql" pack publish --groups $GRPS --dry-run -v
109+ else
110+ echo " Not a dry run! Publishing the query pack"
111+ " ${CODEQL_DIST} /codeql" pack publish --groups $GRPS -v
112+ fi
103113
104114echo " Bumping versions"
105115" ${CODEQL_DIST} /codeql" pack post-release --groups $GRPS -v
@@ -112,18 +122,39 @@ popd
112122# and add a new file
113123# ./src/change-notes/released/<version>.md
114124
115- if [ -z " ${1:- } " ]; then
116- # If we used the latest release of codeml-automodel, then we need to return to the current branch
117- git checkout " $CURRENT_BRANCH "
118- fi
125+ # Get the filename of the most recently created file in ./src/change-notes/released/*.md
126+ # This will be the file for the new release
127+ NEW_CHANGE_NOTES_FILE=$( ls -t ./src/change-notes/released/* .md | head -n 1)
128+
129+ mv ./src/CHANGELOG.md ./src/CHANGELOG.md.dry-run
130+ mv ./src/codeql-pack.release.yml ./src/codeql-pack.release.yml.dry-run
131+ mv ./src/qlpack.yml ./src/qlpack.yml.dry-run
132+ mv " $NEW_CHANGE_NOTES_FILE " ./src/change-notes/released.md.dry-run
119133
120- # Add the updated files to the current branch
121- git add ./src/CHANGELOG.md
122- git add ./src/codeql-pack.release.yml
123- git add ./src/qlpack.yml
124- git add ./src/change-notes/released/*
125- echo " Added the following updated version files to the current branch:"
126- git status -s
134+ # If --override-release was not specified, then we need to checkout the original branch
135+ if [ " $1 " != " --override-release" ] && [ " $2 " != " --override-release" ]; then
136+ echo " Checking out the original branch"
137+ git checkout " $CURRENT_BRANCH " --force
138+ fi
127139
128- echo " Automodel packs successfully published. Local files have been modified. Please commit and push the version changes and then merge into main."
140+ if [ " $1 " = " --dry-run" ] || [ " $2 " = " --dry-run" ]; then
141+ echo " Inspect the updated dry-run version files:"
142+ ls -l ./src/* .dry-run
143+ ls -l ./src/change-notes/* .dry-run
144+ else
145+ # Add the updated files to the current branch
146+ echo " Adding the version changes"
147+ mv -f ./src/CHANGELOG.md.dry-run ./src/CHANGELOG.md
148+ mv -f ./src/codeql-pack.release.yml.dry-run ./src/codeql-pack.release.yml
149+ mv -f ./src/qlpack.yml.dry-run ./src/qlpack.yml
150+ mv -f ./src/change-notes/released.md.dry-run " $NEW_CHANGE_NOTES_FILE "
151+ git add ./src/CHANGELOG.md
152+ git add ./src/codeql-pack.release.yml
153+ git add ./src/qlpack.yml
154+ git add " $NEW_CHANGE_NOTES_FILE "
155+ echo " Added the following updated version files to the current branch:"
156+ git status -s
157+ echo " To complete the release, please commit these files and merge to the main branch"
158+ fi
129159
160+ echo " Done"
0 commit comments