Skip to content

Commit ec68702

Browse files
authored
Add release CI code and bump lib version (#75)
1 parent f6d3218 commit ec68702

File tree

5 files changed

+185
-63
lines changed

5 files changed

+185
-63
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: 'Build Android App'
2+
description: 'Build Android APK and AAB'
3+
inputs:
4+
version_name:
5+
description: 'Version name for the build'
6+
required: true
7+
version_code:
8+
description: 'Version code for the build'
9+
required: false
10+
default: ''
11+
build_type:
12+
description: 'Build type: debug or release'
13+
required: true
14+
outputs:
15+
apk_path:
16+
description: 'Path to the built APK'
17+
value: ${{ steps.build-info.outputs.apk_path }}
18+
bundle_path:
19+
description: 'Path to the built AAB bundle'
20+
value: ${{ steps.build-info.outputs.bundle_path }}
21+
22+
runs:
23+
using: 'composite'
24+
steps:
25+
- name: Print inputs
26+
shell: bash
27+
run: |
28+
echo "Version Name: ${{ inputs.version_name }}"
29+
echo "Version Code: ${{ inputs.version_code }}"
30+
echo "Build Type: ${{ inputs.build_type }}"
31+
32+
- name: Fetch tags for submodule
33+
shell: bash
34+
run: |
35+
cd netbird
36+
git fetch --tags
37+
38+
- name: Setup Java
39+
uses: actions/setup-java@v4
40+
with:
41+
java-version: "17"
42+
distribution: "adopt"
43+
cache: "gradle"
44+
45+
- name: Install Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: "1.23.3"
49+
50+
- name: Setup NDK
51+
shell: bash
52+
run: ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --install "ndk;23.1.7779620"
53+
54+
- name: Set ANDROID_NDK_HOME
55+
shell: bash
56+
run: echo "ANDROID_NDK_HOME=${ANDROID_HOME}/ndk/23.1.7779620" >> $GITHUB_ENV
57+
58+
- name: Install gomobile
59+
shell: bash
60+
run: go install golang.org/x/mobile/cmd/[email protected]
61+
62+
- name: Build NetBird Go library
63+
shell: bash
64+
run: PATH=$PATH:$(go env GOPATH)/bin bash -x build-android-lib.sh
65+
66+
- name: Build APK and Bundle
67+
shell: bash
68+
run: |
69+
BUILD_TYPE=${{ inputs.build_type == 'release' && 'Release' || 'Debug' }}
70+
./gradlew --no-daemon assemble${BUILD_TYPE} bundle${BUILD_TYPE} -PversionName="${{ inputs.version_name }}" -PversionCode="${{ inputs.version_code }}"
71+
72+
- name: Rename artifacts
73+
shell: bash
74+
run: |
75+
set -e
76+
BUILD_TYPE_FOLDER="${{ inputs.build_type }}"
77+
mv app/build/outputs/apk/${BUILD_TYPE_FOLDER}/app-${BUILD_TYPE_FOLDER}.apk app/build/outputs/apk/${BUILD_TYPE_FOLDER}/netbird-${{ inputs.version_name }}.apk
78+
mv app/build/outputs/bundle/${BUILD_TYPE_FOLDER}/app-${BUILD_TYPE_FOLDER}.aab app/build/outputs/bundle/${BUILD_TYPE_FOLDER}/netbird-${{ inputs.version_name }}.aab
79+
80+
- name: Set build info
81+
id: build-info
82+
shell: bash
83+
run: |
84+
BUILD_TYPE="${{ inputs.build_type }}"
85+
echo "apk_path=app/build/outputs/apk/${BUILD_TYPE}/netbird-${{ inputs.version_name }}.apk" >> $GITHUB_OUTPUT
86+
echo "bundle_path=app/build/outputs/bundle/${BUILD_TYPE}/netbird-${{ inputs.version_name }}.aab" >> $GITHUB_OUTPUT

.github/workflows/build-debug.yml

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,38 @@
11
name: build debug
22

33
on:
4-
push:
5-
branches:
6-
- main
74
pull_request:
85

96
jobs:
10-
build:
7+
build-debug:
118
runs-on: ubuntu-latest
9+
outputs:
10+
apk_path: ${{ steps.build.outputs.apk_path }}
11+
bundle_path: ${{ steps.build.outputs.bundle_path }}
1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
submodules: recursive
17-
- name: Setup Java
18-
uses: actions/setup-java@v3
19-
with:
20-
java-version: "17"
21-
distribution: "adopt"
22-
cache: "gradle"
23-
- name: Install Go
24-
uses: actions/setup-go@v4
25-
with:
26-
go-version: "1.23.3"
27-
- name: Setup Android SDK
28-
uses: android-actions/setup-android@v3
29-
with:
30-
cmdline-tools-version: 12266719
31-
- name: NDK Cache
32-
id: ndk-cache
33-
uses: actions/cache@v3
34-
with:
35-
path: /usr/local/lib/android/sdk/ndk
36-
key: ndk-cache-23.1.7779620
37-
- name: Setup NDK
38-
run: /usr/local/lib/android/sdk/cmdline-tools/16.0/bin/sdkmanager --install "ndk;23.1.7779620"
39-
- name: Install gomobile
40-
run: go install golang.org/x/mobile/cmd/[email protected]
41-
- name: Build NetBird Go library
42-
run: PATH=$PATH:$(go env GOPATH)/bin bash -x build-android-lib.sh
43-
env:
44-
ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/23.1.7779620
17+
4518
- name: Get short Git hash
46-
run: echo "SHORT_GIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
47-
- name: Build debug apk
48-
run: ./gradlew --no-daemon assembleDebug -PversionName="ci-${SHORT_GIT_SHA}"
49-
- name: Upload non tags for debug purposes
19+
id: version
20+
run: |
21+
SHORT_GIT_SHA=$(git rev-parse --short HEAD)
22+
echo "version_name=ci-${SHORT_GIT_SHA}" >> $GITHUB_OUTPUT
23+
24+
- name: Build Android
25+
id: build
26+
uses: ./.github/actions/build-android
27+
with:
28+
version_name: ${{ steps.version.outputs.version_name }}
29+
build_type: debug
30+
31+
- name: Upload build artifacts
5032
uses: actions/upload-artifact@v4
5133
with:
52-
name: debug-apk
53-
path: app/build/outputs/apk/debug/app-debug.apk
54-
retention-days: 1
34+
name: debug-artifacts-${{ steps.version.outputs.version_name }}
35+
path: |
36+
${{ steps.build.outputs.apk_path }}
37+
${{ steps.build.outputs.bundle_path }}
38+
retention-days: 3
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: build release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-release:
9+
runs-on: ubuntu-latest
10+
environment: android-release
11+
env:
12+
NETBIRD_UPLOAD_KEY_ALIAS: ${{ secrets.NETBIRD_UPLOAD_KEY_ALIAS }}
13+
NETBIRD_UPLOAD_KEY_PASSWORD: ${{ secrets.NETBIRD_UPLOAD_KEY_PASSWORD }}
14+
NETBIRD_UPLOAD_STORE_PASSWORD: ${{ secrets.NETBIRD_UPLOAD_STORE_PASSWORD }}
15+
outputs:
16+
apk_path: ${{ steps.build.outputs.apk_path }}
17+
bundle_path: ${{ steps.build.outputs.bundle_path }}
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
24+
- name: Get version
25+
id: version
26+
run: |
27+
TAG_NAME=${{ github.event.release.tag_name }}
28+
echo "version_name=$TAG_NAME" >> $GITHUB_OUTPUT
29+
30+
- name: Write google-services.json
31+
run: |
32+
echo "${{ secrets.GOOGLE_JSON }}" | base64 -d > app/google-services.json
33+
34+
- name: Write keystore file
35+
run: |
36+
echo "${{ secrets.GPLAY_KEYSTORE }}" | base64 -d > gplay.keystore
37+
echo "NETBIRD_UPLOAD_STORE_FILE=$GITHUB_WORKSPACE/gplay.keystore" >> $GITHUB_ENV
38+
39+
- name: Compute version code
40+
id: version_code
41+
run: |
42+
adjusted=$(( ${{ github.run_number }} + 40 ))
43+
echo "adjusted=$adjusted" >> $GITHUB_OUTPUT
44+
45+
- name: Build Android
46+
id: build
47+
uses: ./.github/actions/build-android
48+
with:
49+
version_name: ${{ steps.version.outputs.version_name }}
50+
version_code: ${{ steps.version_code.outputs.adjusted }}
51+
build_type: release
52+
53+
- name: Upload files to existing release
54+
uses: softprops/action-gh-release@v1
55+
with:
56+
files: |
57+
${{ steps.build.outputs.apk_path }}
58+
${{ steps.build.outputs.bundle_path }}
59+
tag_name: ${{ github.event.release.tag_name }}

build-android-lib.sh

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22
# Script to build NetBird mobile bindings using gomobile
33
# Usage: ./script.sh [version]
4-
# If no version is provided, "development" is used as default
4+
# - If a version is provided, it will be used.
5+
# - If no version is provided:
6+
# * Uses the latest Git tag if available.
7+
# * Otherwise, defaults to "dev-<short-hash>".
8+
# - When running in GitHub Actions, uses "ci-<short-hash>" instead of "dev-<short-hash>".
9+
510
set -e
611

712
app_path=$(pwd)
@@ -13,45 +18,33 @@ get_version() {
1318
return
1419
fi
1520

16-
cd netbird
17-
1821
# Try to get an exact tag
1922
local tag=$(git describe --tags --exact-match 2>/dev/null || true)
2023

2124
if [ -n "$tag" ]; then
22-
cd - > /dev/null
2325
echo "$tag"
2426
return
2527
fi
2628

27-
# Get the last tag
28-
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
29-
30-
# Parse and increment patch version
31-
if [[ $last_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
32-
local major=${BASH_REMATCH[1]}
33-
local minor=${BASH_REMATCH[2]}
34-
local patch=${BASH_REMATCH[3]}
35-
local new_patch=$((patch + 1))
36-
local short_hash=$(git rev-parse --short HEAD)
37-
local new_version="v$major.$minor.$new_patch-$short_hash"
29+
# Fallback to "<prefix>-<short-hash>"
30+
local short_hash=$(git rev-parse --short HEAD)
31+
32+
if [ "$GITHUB_ACTIONS" == "true" ]; then
33+
local new_version="ci-$short_hash"
3834
else
39-
# Fallback if tag format is not vX.Y.Z
40-
local short_hash=$(git rev-parse --short HEAD)
41-
local new_version="development-$short_hash"
35+
local new_version="dev-$short_hash"
4236
fi
4337

44-
cd - > /dev/null
4538
echo "$new_version"
4639
}
4740

41+
42+
cd netbird
43+
4844
# Get version using the function
4945
version=$(get_version "$1")
50-
5146
echo "Using version: $version"
5247

53-
54-
cd netbird
5548
gomobile init
5649

5750
CGO_ENABLED=0 gomobile bind \

netbird

Submodule netbird updated 111 files

0 commit comments

Comments
 (0)