Skip to content

Commit 8301338

Browse files
refactor(scripts): improve version handling in build scripts (#1280)
* refactor(scripts): improve version handling in build scripts - Replace hardcoded VERSION="0.1.0" in build_app_tauri.sh with dynamic getversion.sh call - Refactor getversion.sh to support multiple CI environments (GitHub Actions, Travis, AppVeyor) and add --strip-v flag - Use SCRIPT_DIR for robust relative path resolution in package scripts - Replace manual sed-based v-prefix stripping with --strip-v flag - Add verbose version logging in CI workflows for easier debugging Salvaged from #1271 by @caoweiping. * fix(scripts): address greptile review nits - getversion.sh: tighten GITHUB_REF guard to refs/tags/v* to avoid matching v-prefixed branch names - package-deb.sh: call getversion.sh once, derive VERSION_NUM with sed (avoids double git-describe) - build.yml, build-tauri.yml: use VERSION_WITH_V env var in Package dmg step (wires up existing export, removes redundant getversion.sh call) * fix(ci): deduplicate getversion.sh calls and drop unused VERSION_NO_V env export VERSION_NO_V was computed via a second getversion.sh invocation but never used by any subsequent step — only echoed to build log. Switch to shell parameter expansion (${VERSION_WITH_V#v}) for zero-cost stripping, and drop the dead GITHUB_ENV export. Addresses Greptile P2 nits on #1280. * ci: retrigger CI (transient npm network failure) --------- Co-authored-by: caoweiping <[email protected]>
1 parent 8877798 commit 8301338

6 files changed

Lines changed: 141 additions & 28 deletions

File tree

.github/workflows/build-tauri.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ jobs:
5555
run: |
5656
echo "VERSION_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV
5757
58+
- name: Determine and output version
59+
run: |
60+
VERSION_WITH_V=$(bash scripts/package/getversion.sh)
61+
VERSION_NO_V="${VERSION_WITH_V#v}"
62+
echo "VERSION_WITH_V=${VERSION_WITH_V}" >> $GITHUB_ENV
63+
echo "========================================"
64+
echo "Build Version Information (Tauri)"
65+
echo "========================================"
66+
echo "GitHub ref: ${{ github.ref }}"
67+
echo "GitHub ref_name: ${{ github.ref_name }}"
68+
echo "Version (with v): ${VERSION_WITH_V}"
69+
echo "Version (no v): ${VERSION_NO_V}"
70+
echo "========================================"
71+
5872
- name: Set up Python
5973
uses: actions/setup-python@v6
6074
with:
@@ -164,7 +178,7 @@ jobs:
164178
165179
make dist/notarize
166180
fi
167-
mv dist/ActivityWatch.dmg dist/activitywatch-tauri-${VERSION_TAG:-$(scripts/package/getversion.sh)}-macos-$(uname -m).dmg
181+
mv dist/ActivityWatch.dmg dist/activitywatch-tauri-${VERSION_WITH_V}-macos-$(uname -m).dmg
168182
env:
169183
APPLE_EMAIL: ${{ secrets.APPLE_EMAIL }}
170184
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}

.github/workflows/build.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ jobs:
5757
run: |
5858
echo "VERSION_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV
5959
60+
- name: Determine and output version
61+
run: |
62+
VERSION_WITH_V=$(bash scripts/package/getversion.sh)
63+
VERSION_NO_V="${VERSION_WITH_V#v}"
64+
echo "VERSION_WITH_V=${VERSION_WITH_V}" >> $GITHUB_ENV
65+
echo "========================================"
66+
echo "Build Version Information"
67+
echo "========================================"
68+
echo "GitHub ref: ${{ github.ref }}"
69+
echo "GitHub ref_name: ${{ github.ref_name }}"
70+
echo "Version (with v): ${VERSION_WITH_V}"
71+
echo "Version (no v): ${VERSION_NO_V}"
72+
echo "========================================"
73+
6074
- name: Set up Python
6175
uses: actions/setup-python@v6
6276
with:
@@ -178,7 +192,7 @@ jobs:
178192
# Notarize
179193
make dist/notarize
180194
fi
181-
mv dist/ActivityWatch.dmg dist/activitywatch-${VERSION_TAG:-$(scripts/package/getversion.sh)}-macos-$(uname -m).dmg
195+
mv dist/ActivityWatch.dmg dist/activitywatch-${VERSION_WITH_V}-macos-$(uname -m).dmg
182196
env:
183197
APPLE_EMAIL: ${{ secrets.APPLE_EMAIL }}
184198
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}

scripts/package/build_app_tauri.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ set -e
66

77
APP_NAME="ActivityWatch"
88
BUNDLE_ID="net.activitywatch.ActivityWatch"
9-
VERSION="0.1.0"
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
VERSION="$("$SCRIPT_DIR/getversion.sh" --strip-v)"
1011
ICON_PATH="aw-tauri/src-tauri/icons/icon.icns"
1112

1213
if [[ "$(uname)" != "Darwin" ]]; then

scripts/package/getversion.sh

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,89 @@
11
#!/bin/bash
2+
set -e
23

3-
# TODO: Merge with scripts/package/getversion.sh
4-
# set -e
5-
6-
if [[ $TRAVIS_TAG ]]; then
7-
_version=$TRAVIS_TAG;
8-
elif [[ $APPVEYOR_REPO_TAG_NAME ]]; then
9-
_version=$APPVEYOR_REPO_TAG_NAME;
10-
else
11-
# Exact
12-
_version=$(git describe --tags --abbrev=0 --exact-match 2>/dev/null)
13-
if [[ -z $_version ]]; then
14-
# Latest tag + commit ID
15-
_version="$(git describe --tags --abbrev=0).dev-$(git rev-parse --short HEAD)"
4+
SCRIPT_NAME="$(basename "$0")"
5+
STRIP_V=false
6+
7+
show_usage() {
8+
cat << EOF
9+
Usage: $SCRIPT_NAME [OPTIONS]
10+
11+
Get the version of ActivityWatch from git tags or CI environment variables.
12+
13+
Options:
14+
--strip-v, --no-v Remove the 'v' prefix from the version (if present)
15+
--help, -h Show this help message
16+
17+
Environment Variables (used in CI, checked in priority order):
18+
GITHUB_REF_NAME GitHub Actions tag/ref (e.g., "v0.14.0")
19+
TRAVIS_TAG Travis CI tag
20+
APPVEYOR_REPO_TAG_NAME AppVeyor CI tag
21+
22+
Version Format:
23+
- Release tag: v0.14.0
24+
- Dev version: v0.14.0.dev-abc1234
25+
- Beta/RC: v0.14.0b1, v0.14.0rc1
26+
27+
Examples:
28+
$SCRIPT_NAME # v0.14.0 or v0.14.0.dev-abc1234
29+
$SCRIPT_NAME --strip-v # 0.14.0 or 0.14.0.dev-abc1234
30+
EOF
31+
}
32+
33+
parse_args() {
34+
while [[ $# -gt 0 ]]; do
35+
case "$1" in
36+
--strip-v|--no-v)
37+
STRIP_V=true
38+
shift
39+
;;
40+
--help|-h)
41+
show_usage
42+
exit 0
43+
;;
44+
*)
45+
echo "ERROR: Unknown argument: $1" >&2
46+
show_usage >&2
47+
exit 1
48+
;;
49+
esac
50+
done
51+
}
52+
53+
get_version_internal() {
54+
local _version=""
55+
56+
if [[ -n "$GITHUB_REF" && "$GITHUB_REF" == refs/tags/v* ]]; then
57+
_version="$GITHUB_REF_NAME"
58+
elif [[ -n "$TRAVIS_TAG" ]]; then
59+
_version="$TRAVIS_TAG"
60+
elif [[ -n "$APPVEYOR_REPO_TAG_NAME" ]]; then
61+
_version="$APPVEYOR_REPO_TAG_NAME"
62+
else
63+
_version="$(git describe --tags --abbrev=0 --exact-match 2>/dev/null || true)"
64+
if [[ -z "$_version" ]]; then
65+
local _latest_tag
66+
_latest_tag="$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")"
67+
local _commit_hash
68+
_commit_hash="$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")"
69+
_version="${_latest_tag}.dev-${_commit_hash}"
70+
fi
71+
fi
72+
73+
echo "$_version"
74+
}
75+
76+
main() {
77+
parse_args "$@"
78+
79+
local version
80+
version="$(get_version_internal)"
81+
82+
if $STRIP_V; then
83+
version="$(echo "$version" | sed -e 's/^v//')"
1684
fi
17-
fi
85+
86+
echo "$version"
87+
}
1888

19-
echo $_version;
89+
main "$@"

scripts/package/package-all.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ function get_platform() {
2929
echo $_platform;
3030
}
3131

32+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33+
3234
function get_version() {
33-
$(dirname "$0")/getversion.sh;
35+
"$SCRIPT_DIR/getversion.sh";
36+
}
37+
38+
function get_version_no_prefix() {
39+
"$SCRIPT_DIR/getversion.sh" --strip-v;
3440
}
3541

3642
function get_arch() {
@@ -40,13 +46,23 @@ function get_arch() {
4046

4147
platform=$(get_platform)
4248
version=$(get_version)
49+
version_no_prefix=$(get_version_no_prefix)
4350
arch=$(get_arch)
44-
# Suffix to distinguish Tauri builds from aw-qt builds in release assets
4551
build_suffix=""
4652
if [[ $TAURI_BUILD == "true" ]]; then
4753
build_suffix="-tauri"
4854
fi
49-
echo "Platform: $platform, arch: $arch, version: $version, tauri: ${TAURI_BUILD:-false}"
55+
56+
echo "========================================"
57+
echo "Build Version Information"
58+
echo "========================================"
59+
echo "Platform: $platform"
60+
echo "Arch: $arch"
61+
echo "Version (with v): $version"
62+
echo "Version (no v): $version_no_prefix"
63+
echo "Tauri build: ${TAURI_BUILD:-false}"
64+
echo "========================================"
65+
echo
5066

5167
# For Tauri Linux builds, include helper scripts and README
5268
if [[ $platform == "linux" && $TAURI_BUILD == "true" ]]; then
@@ -78,8 +94,6 @@ function build_setup() {
7894
exit 1
7995
fi
8096

81-
# Windows installer version should not include 'v' prefix, see: https://github.com/microsoft/winget-pkgs/pull/17564
82-
version_no_prefix="$(echo $version | sed -e 's/^v//')"
8397
if [[ $TAURI_BUILD == "true" ]]; then
8498
env AW_VERSION=$version_no_prefix "$innosetupdir/iscc.exe" scripts/package/aw-tauri.iss
8599
else

scripts/package/package-deb.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/bash
2-
# Setting the shell is required, as `sh` doesn't support slicing.
32

43
# Fail fast
54
set -e
65
# Verbose commands for CI verification
76
set -x
87

9-
VERSION=$(scripts/package/getversion.sh)
10-
# Slice off the "v" from the tag, which is probably guaranteed
11-
VERSION_NUM=${VERSION:1}
12-
echo $VERSION_NUM
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
VERSION="$("$SCRIPT_DIR/getversion.sh")"
10+
VERSION_NUM="$(echo "$VERSION" | sed -e 's/^v//')"
11+
echo "Version (with v): $VERSION"
12+
echo "Version (without v): $VERSION_NUM"
1313
PKGDIR="activitywatch_$VERSION_NUM"
1414

1515
# Package tools

0 commit comments

Comments
 (0)