1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ function printUsage() {
5+ echo " usage: $( basename " $0 " ) [options] tag"
6+ echo
7+ echo " Pushes ObjectBox Generator binaries to a GitHub release (draft)"
8+ echo " tag: the release version (e.g. 1.2.3); no 'v' prefix is required"
9+ echo
10+ echo " Options:"
11+ echo " --force-release-upload: upload to an existing release (non-draft) if it exists"
12+ echo " --linux-x64: upload only the Linux artifact (useful for testing)"
13+ echo " --dry-run: do not upload any artifacts"
14+
15+ exit 1
16+ }
17+
18+ # Default values
19+ force_release_upload=false
20+ linux_x64_only=false
21+ dry_run=false
22+
23+ # Parse command line arguments; e.g. override defaults
24+ while test $# -gt 0; do
25+ case " $1 " in
26+ -h|help|--help|usage)
27+ printUsage
28+ ;;
29+ --force-release-upload)
30+ force_release_upload=true
31+ shift
32+ ;;
33+ --linux-x64) # partial artifact upload: this is useful to test the script locally
34+ linux_x64_only=true
35+ shift
36+ ;;
37+ --dryrun|--dry-run)
38+ dry_run=true
39+ shift
40+ ;;
41+ " " ) # ignore any empty parameters ("artifacts" that can happen depending on how the caller constructs the parameters)
42+ shift
43+ ;;
44+ * )
45+ break
46+ ;;
47+ esac
48+ done
49+
50+ if [[ " $# " -ne " 1" ]]; then
51+ echo " $# arguments provided ('$* '), expected 1 "
52+ printUsage
53+ fi
54+
55+ echo " Options: linux_x64_only=$linux_x64_only , dry_run=$dry_run "
56+
57+ # start in the repo root directory
58+ cd " $( dirname " $0 " ) /.."
59+
60+ github_tag=$1
61+ github_repo=" https://github.com/objectbox/objectbox-generator"
62+
63+ if ! [[ $github_tag == v* ]]; then
64+ github_tag=" v$github_tag "
65+ fi
66+
67+ echo " Checking GitHub authentication status..."
68+ gh auth status
69+
70+ echo " Checking if release ${github_tag} exists..."
71+ # https://cli.github.com/manual/gh_release_view
72+ if gh release view --repo " ${github_repo} " " ${github_tag} " ; then
73+ echo " " # gh may have not ended with a new line
74+ is_draft_json=$( gh release view --repo " ${github_repo} " " ${github_tag} " --json isDraft)
75+ echo " Existing release \" ${github_tag} \" found; draft status: $is_draft_json "
76+ if [[ $is_draft_json == * " \" isDraft\" :true" * ]]; then
77+ echo " Existing release draft identified: will try to upload artifacts."
78+ echo " Note: existing artifact will not be overwritten; delete them manually beforehand if required."
79+ elif [[ $is_draft_json == * " \" isDraft\" :false" * ]]; then
80+ echo " WARN: Existing release is not a draft"
81+ if [ " $force_release_upload " = true ]; then
82+ echo " WARN: Upload to existing release is forced; continuing..."
83+ else
84+ echo " WARN: Aborting upload to avoid messing up existing releases."
85+ echo " WARN: Situation must be resolved manually, or force the upload via argument."
86+ exit 1
87+ fi
88+ else
89+ echo " ERROR: Must this script be updated? Found unknown draft status: $is_draft_json "
90+ exit 1
91+ fi
92+ else
93+ echo " No release found for '${github_tag} '; creating a new release draft..."
94+ gh release create --draft --repo " ${github_repo} " " ${github_tag} " \
95+ --title " ObjectBox Generator ${github_tag} " \
96+ --notes " See CHANGELOG.md for details."
97+ echo " Uploading artifacts to new release draft..."
98+ fi
99+
100+ if [ " $dry_run " = true ]; then
101+ echo " Dry run: skipping artifact preparation & upload"
102+ exit 0
103+ fi
104+
105+ # Explicitly specify all files instead of using a wildcard glob to avoid unintended uploads (and catch missing files).
106+ # These artifacts are built by the build jobs in GitLab CI. See .gitlab-ci.yml for details on how to build.
107+ candidate_files=(
108+ objectbox-generator-Linux.zip
109+ objectbox-generator-macOS.zip
110+ objectbox-generator-Windows.zip
111+ )
112+ files_upload=()
113+ for f in " ${candidate_files[@]} " ; do
114+ if [ -f " ${f} " ]; then
115+ files_upload+=(" ${f} " )
116+ elif [ -f " artifacts/${f} " ]; then
117+ files_upload+=(" artifacts/${f} " )
118+ else
119+ echo " ERROR: File not found: ${f} (also not in artifacts/${f} )"
120+ exit 1
121+ fi
122+ if [ " $linux_x64_only " = true ]; then break ; fi # Linux is the first array item
123+ done
124+
125+ echo " ${# files_upload[@]} files to upload:"
126+ for file_upload in " ${files_upload[@]} " ; do
127+ ls -lh " $file_upload "
128+ done
129+
130+ # https://cli.github.com/manual/gh_release_upload
131+ gh release upload --repo " ${github_repo} " " ${github_tag} " " ${files_upload[@]} "
132+
133+ echo " Done."
0 commit comments