Skip to content

Commit dd07428

Browse files
committed
Introduce GitHub release automation
1 parent bf2c8e6 commit dd07428

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Make GitHub releases automatic source archives empty
2+
* export-ignore

.github/tag_and_upload_release.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: GPL-2.0-or-later WITH Classpath-exception-2.0
3+
4+
set -e
5+
6+
if [ $# -ne 4 ]; then
7+
echo "Usage: ${0} NAME VERSION REMOTE_NAME DIST_FILE" 1>&2
8+
exit 1
9+
fi
10+
NAME="${1}"
11+
VERSION="${2}"
12+
REMOTE_NAME="${3}"
13+
DIST_FILE="${4}"
14+
15+
# Tag the current version and push the tag
16+
if [ "$(git status --porcelain | wc -l)" -ne 0 ]; then
17+
echo "will not tag: the working tree must be clean" 1>&2
18+
exit 2
19+
fi
20+
release_name="${NAME} v${VERSION}"
21+
git tag -s "${VERSION}" -m "${release_name}"
22+
git push "${REMOTE_NAME}" tag "${VERSION}"
23+
24+
# Obtain GitHub data required to use the REST API
25+
gh_token="$(echo -e 'protocol=https\nhost=github.com' |
26+
/usr/libexec/git-core/git-credential-libsecret get |
27+
sed -n s/password=//p)"
28+
if [ -z "${gh_token}" ]; then
29+
echo "could not get the GitHub token" 1>&2
30+
exit 3
31+
fi
32+
33+
remote_url="$(git remote get-url "${REMOTE_NAME}")"
34+
if [ -z "${remote_url}" ]; then
35+
echo "could not get the git remote url for ${REMOTE_NAME}" 1>&2
36+
exit 4
37+
fi
38+
owner="$(echo "${remote_url%*.git}" | tr / '\n' | tail -2 | head -1)"
39+
repo="$(echo "${remote_url%*.git}" | tr / '\n' | tail -1)"
40+
41+
# Publish GitHub release
42+
COMMON_HEADERS=(
43+
-L -X POST -H "Authorization: Bearer ${gh_token}"
44+
-H "Accept: application/vnd.github+json"
45+
-H "X-GitHub-Api-Version: 2022-11-28"
46+
)
47+
body="Note: \`${DIST_FILE}\` is the official release source, \`*.zip\`"
48+
body="${body} and \`*.tar.gz\` files are empty on purpose, since GitHub"
49+
body="${body} doesn't allow deleting them."
50+
data="$(
51+
cat <<-EOF
52+
{
53+
"tag_name": "${VERSION}",
54+
"name": "${release_name}",
55+
"body": "${body}"
56+
}
57+
EOF
58+
)"
59+
url="https://api.github.com/repos/${owner}/${repo}/releases"
60+
resp="$(curl "${COMMON_HEADERS[@]}" "${url}" --data "${data}")"
61+
echo "${resp}"
62+
63+
# Upload dist file
64+
upload_url="$(python3 '-BIScimport json, sys
65+
print(json.load(sys.stdin)["upload_url"].split("{")[0])' <<<"${resp}")"
66+
curl "${COMMON_HEADERS[@]}" -H "Content-Type: application/octet-stream" \
67+
"${upload_url}?name=${DIST_FILE}" --data-binary "@${DIST_FILE}"

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ test-data: -test
159159
test:
160160
@bash $(TST_DIR)/containerized_test.sh $(CENTOS_VERSION) $(JDK_VERSION)
161161

162+
.PHONY: github-release ## Create a release tag for the current VERSION and publish it to GitHub, parameters: [REMOTE_NAME]
163+
ifndef REMOTE_NAME
164+
REMOTE_NAME = origin
165+
endif
166+
github-release: $(DIST_FILE)
167+
@bash .github/tag_and_upload_release.sh \
168+
"$(NAME)" "$(VERSION)" "$(REMOTE_NAME)" "$(DIST_FILE)"
169+
162170
.PHONY: help ## Display this message
163171
help:
164172
@echo '$(shell tput bold)Available make targets:$(shell tput sgr0)'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The Makefile has support for:
3333
* This test suite ensures the system is in FIPS mode, and is known to work
3434
with _Temurin_ builds of _OpenJDK_ 8, 11, 17, 21 and 25
3535
* Building a source tarball
36+
* Creating a GitHub release
3637

3738
To see a help message with all the `make` targets and a brief description invoke
3839
`make help`.

0 commit comments

Comments
 (0)