1
1
#! /bin/bash
2
2
set -e
3
3
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
5
12
if [ " $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 "
9
14
exit 0
10
15
fi
11
16
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 number of arguments are valid
18
+ if [ $# -gt 2 ]; then
19
+ echo " Error: Invalid arguments provided"
20
+ echo " $help "
15
21
exit 1
16
22
fi
17
23
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
+
18
57
# If we're publishing the codeml-automodel release then we will checkout the sha specified in the release.
19
58
# So we need to check that there are no uncommitted changes in the local branch.
20
59
# And, if we're publishing the current HEAD, it's cleaner to ensure that there are no uncommitted changes.
@@ -28,10 +67,6 @@ if [ -z "${GITHUB_TOKEN}" ]; then
28
67
echo " Error: GITHUB_TOKEN environment variable not set. Please set this to a token with package:write permissions to codeql."
29
68
exit 1
30
69
fi
31
- if [ -z " ${CODEQL_DIST} " ]; then
32
- echo " Error: CODEQL_DIST environment variable not set. Please set this to the path of a codeql distribution."
33
- exit 1
34
- fi
35
70
if [ -z " ${GH_TOKEN} " ]; then
36
71
echo " Error: GH_TOKEN environment variable not set. Please set this to a token with repo permissions to github/codeml-automodel."
37
72
exit 1
49
84
CURRENT_BRANCH=$( git rev-parse --abbrev-ref HEAD)
50
85
CURRENT_SHA=$( git rev-parse HEAD)
51
86
52
- if [ -z " ${1:- } " ]; then
53
- # If the first argument is empty, use the latest release of codeml-automodel
87
+ if [ $OVERRIDE_RELEASE = 1 ]; then
88
+ # Check that the current HEAD is downstream from PREVIOUS_RELEASE_SHA
89
+ if ! git merge-base --is-ancestor " $PREVIOUS_RELEASE_SHA " " $CURRENT_SHA " ; then
90
+ echo " Error: The current HEAD is not downstream from the previous release"
91
+ exit 1
92
+ fi
93
+ else
94
+ # Get the latest release of codeml-automodel
54
95
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)
55
96
# Check TAG_NAME is not empty
56
97
if [ -z " $TAG_NAME " ]; then
@@ -73,12 +114,6 @@ if [ -z "${1:-}" ]; then
73
114
fi
74
115
# Get the version of the codeql code specified by the codeml-automodel release
75
116
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
82
117
fi
83
118
84
119
# Get the absolute path of the automodel repo
@@ -88,21 +123,28 @@ WORKSPACE_ROOT="$AUTOMODEL_ROOT/../../.."
88
123
# Specify the groups of queries to test and publish
89
124
GRPS=" automodel,-test"
90
125
126
+ # Install the codeql gh extension
127
+ gh extensions install github/gh-codeql
128
+
91
129
pushd " $AUTOMODEL_ROOT "
92
130
echo Testing automodel queries
93
- " ${CODEQL_DIST} / codeql" test run test
131
+ gh codeql test run test
94
132
popd
95
133
96
134
pushd " $WORKSPACE_ROOT "
97
135
echo " Preparing the release"
98
- " ${CODEQL_DIST} / codeql" pack release --groups $GRPS -v
136
+ gh codeql pack release --groups $GRPS -v
99
137
100
- echo " Publishing the release"
101
- # Add --dry-run to test publishing
102
- " ${CODEQL_DIST} /codeql" pack publish --groups $GRPS -v
138
+ if [ $DRY_RUN = 1 ]; then
139
+ echo " Dry run: not publishing the query pack"
140
+ gh codeql pack publish --groups $GRPS --dry-run -v
141
+ else
142
+ echo " Not a dry run! Publishing the query pack"
143
+ gh codeql pack publish --groups $GRPS -v
144
+ fi
103
145
104
146
echo " Bumping versions"
105
- " ${CODEQL_DIST} / codeql" pack post-release --groups $GRPS -v
147
+ gh codeql pack post-release --groups $GRPS -v
106
148
popd
107
149
108
150
# The above commands update
@@ -112,18 +154,44 @@ popd
112
154
# and add a new file
113
155
# ./src/change-notes/released/<version>.md
114
156
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 "
157
+ # Get the filename of the most recently created file in ./src/change-notes/released/*.md
158
+ # This will be the file for the new release
159
+ NEW_CHANGE_NOTES_FILE=$( ls -t ./src/change-notes/released/* .md | head -n 1)
160
+
161
+ # Make a copy of the modified files
162
+ mv ./src/CHANGELOG.md ./src/CHANGELOG.md.dry-run
163
+ mv ./src/codeql-pack.release.yml ./src/codeql-pack.release.yml.dry-run
164
+ mv ./src/qlpack.yml ./src/qlpack.yml.dry-run
165
+ mv " $NEW_CHANGE_NOTES_FILE " ./src/change-notes/released.md.dry-run
166
+
167
+ if [ $OVERRIDE_RELEASE = 1 ]; then
168
+ # Restore the original files
169
+ git checkout ./src/CHANGELOG.md
170
+ git checkout ./src/codeql-pack.release.yml
171
+ git checkout ./src/qlpack.yml
172
+ else
173
+ # Restore the original files
174
+ git checkout " $CURRENT_BRANCH " --force
118
175
fi
119
176
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
127
-
128
- echo " Automodel packs successfully published. Local files have been modified. Please commit and push the version changes and then merge into main."
177
+ if [ $DRY_RUN = 1 ]; then
178
+ echo " Inspect the updated dry-run version files:"
179
+ ls -l ./src/* .dry-run
180
+ ls -l ./src/change-notes/* .dry-run
181
+ else
182
+ # Add the updated files to the current branch
183
+ echo " Adding the version changes"
184
+ mv -f ./src/CHANGELOG.md.dry-run ./src/CHANGELOG.md
185
+ mv -f ./src/codeql-pack.release.yml.dry-run ./src/codeql-pack.release.yml
186
+ mv -f ./src/qlpack.yml.dry-run ./src/qlpack.yml
187
+ mv -f ./src/change-notes/released.md.dry-run " $NEW_CHANGE_NOTES_FILE "
188
+ git add ./src/CHANGELOG.md
189
+ git add ./src/codeql-pack.release.yml
190
+ git add ./src/qlpack.yml
191
+ git add " $NEW_CHANGE_NOTES_FILE "
192
+ echo " Added the following updated version files to the current branch:"
193
+ git status -s
194
+ echo " To complete the release, please commit these files and merge to the main branch"
195
+ fi
129
196
197
+ echo " Done"
0 commit comments