Skip to content

Commit 23113ab

Browse files
committed
Add releasing pipeline for Android
1 parent bef1165 commit 23113ab

File tree

8 files changed

+349
-3
lines changed

8 files changed

+349
-3
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '**.md'
9+
- '.github/**'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
if: github.repository == 'duckduckgo/url_predictor' && github.ref == 'refs/heads/main'
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Configure JDK
25+
uses: actions/setup-java@v3
26+
with:
27+
distribution: 'zulu'
28+
java-version: 17
29+
30+
- name: Setup Android SDK
31+
uses: android-actions/setup-android@v3
32+
33+
- name: Install CMake 3.18.1
34+
run: yes | sdkmanager "cmake;3.18.1"
35+
36+
# 🔧 Install a specific NDK and expose it for cargo-ndk
37+
- name: Install Android NDK
38+
run: |
39+
yes | sdkmanager "ndk;25.2.9519653"
40+
echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/25.2.9519653" >> $GITHUB_ENV
41+
echo "ANDROID_NDK_ROOT=$ANDROID_HOME/ndk/25.2.9519653" >> $GITHUB_ENV
42+
echo "NDK_HOME=$ANDROID_HOME/ndk/25.2.9519653" >> $GITHUB_ENV
43+
44+
# 🔧 Install Rust + Android targets that match ABIs (arm64-v8a, armeabi-v7a, x86_64, x86)
45+
- name: Install Rust toolchain + Android targets
46+
uses: dtolnay/rust-toolchain@stable
47+
with:
48+
targets: aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android,i686-linux-android
49+
50+
- name: Setup Gradle
51+
uses: gradle/actions/setup-gradle@v4
52+
53+
- name: verify signing secrets
54+
run: |
55+
test -n "${{ secrets.CENTRAL_PORTAL_USERNAME }}" || { echo "❌ Missing CENTRAL_PORTAL_USERNAME"; exit 1; }
56+
test -n "${{ secrets.CENTRAL_PORTAL_PASSWORD }}" || { echo "❌ Missing CENTRAL_PORTAL_PASSWORD"; exit 1; }
57+
test -n "${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }}" || { echo "❌ Missing ARTIFACT_SIGNING_PRIVATE_KEY"; exit 1; }
58+
test -n "${{ secrets.ARTIFACT_SIGNING_KEY_PASSWORD }}" || { echo "❌ Missing ARTIFACT_SIGNING_KEY_PASSWORD"; exit 1; }
59+
# test -n "${{ secrets.ARTIFACT_SIGNING_KEY_ID }}" || { echo "❌ Missing ARTIFACT_SIGNING_KEY_ID"; exit 1; }
60+
shell: bash
61+
62+
- name: Build and Upload Artifacts
63+
run: bash ./scripts/build_android.sh --publish
64+
env:
65+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.CENTRAL_PORTAL_USERNAME }}
66+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.CENTRAL_PORTAL_PASSWORD }}
67+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }}
68+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ARTIFACT_SIGNING_KEY_PASSWORD }}
69+
# ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.ARTIFACT_SIGNING_KEY_ID }}
70+
71+
# Also export alternative Gradle property names for compatibility
72+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }}
73+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ARTIFACT_SIGNING_KEY_PASSWORD }}
74+
# ORG_GRADLE_PROJECT_signing.keyId: ${{ secrets.ARTIFACT_SIGNING_KEY_ID }}
75+
ORG_GRADLE_PROJECT_signing.password: ${{ secrets.ARTIFACT_SIGNING_KEY_PASSWORD }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ android/local.properties
2626
# Android Studio / IntelliJ
2727
# =========================
2828
android/.idea/
29+
/.idea
2930
*.iml
3031

3132
# =========================

LICENSE

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Copyright (c) 2021 Duck Duck Go, Inc.
2+
3+
## Apache License
4+
### Version 2.0, January 2004
5+
###### http://www.apache.org/licenses/
6+
7+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8+
9+
**1. Definitions.**
10+
11+
"**License**" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12+
13+
"**Licensor**" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14+
15+
"**Legal Entity**" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "**control**" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16+
17+
"**You**" (or "**Your**") shall mean an individual or Legal Entity exercising permissions granted by this License.
18+
19+
"**Source**" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20+
21+
"**Object**" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22+
23+
"**Work**" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24+
25+
"**Derivative Works**" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26+
27+
"**Contribution**" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "**submitted**" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "**Not a Contribution.**"
28+
29+
"**Contributor**" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30+
31+
**2. Grant of Copyright License**. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32+
33+
**3. Grant of Patent License**. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34+
35+
**4. Redistribution**. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36+
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
37+
1. You must cause any modified files to carry prominent notices stating that You changed the files; and
38+
1. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
39+
1. If the Work includes a "**NOTICE**" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
40+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
41+
42+
**5. Submission of Contributions**. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
43+
44+
**6. Trademarks**. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
45+
46+
**7. Disclaimer of Warranty**. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
47+
48+
**8. Limitation of Liability**. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
49+
50+
**9. Accepting Warranty or Additional Liability**. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
51+
52+
END OF TERMS AND CONDITIONS

android/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Netguard Android
2+
===============
3+
Android wrapper for url-predictor native library. Published as an AAR file into maven.
4+
5+
Download
6+
--------
7+
8+
```groovy
9+
implementation 'com.duckduckgo.urlpredictor:url-predictor-android:<latest-version>'
10+
```
11+
12+
Snapshots of the development version are available in [Sonatype's `snapshots` repository](https://s01.oss.sonatype.org/content/repositories/snapshots/com/duckduckgo/urlpredictor/url-predictor-android).
13+
14+
Release versions are available in [Sonatype's `releases` repository](https://s01.oss.sonatype.org/content/repositories/releases/com/duckduckgo/urlpredictor/url-predictor-android).
15+
16+
License
17+
-------
18+
See [LICENSE](https://github.com/duckduckgo/url_predictor/blob/main/LICENSE)

android/RELEASING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Releasing
2+
========
3+
4+
1. Change the version in `version.properties` to a non-SNAPSHOT version.
5+
2. `git commit -am "Release X.Y.Z"` (where X.Y.Z is the new version)
6+
3. `git tag -a X.Y.X -m "X.Y.Z"` (where X.Y.Z is the new version)
7+
4. `git push && git push --tags`
8+
5. Update the `version.properties` to the next SNAPSHOT version.
9+
6. `git commit -am "Prepare next development version."`
10+
7. `git push`
11+
12+
Alternatively, you can use `release_android.sh` script

android/ddg-url-predictor/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mavenPublishing {
2929
pom {
3030
name = "DDG URL Predictor"
3131
description = "DuckDuckGo URL Predictor Library."
32-
inceptionYear = "2023"
32+
inceptionYear = "2025"
3333
url = "https://github.com/duckduckgo/url_predictor"
3434
licenses {
3535
license {
@@ -54,7 +54,7 @@ mavenPublishing {
5454
}
5555

5656
android {
57-
compileSdk 35
57+
compileSdk 36
5858

5959
namespace "com.duckduckgo.urlpredictor"
6060

android/release_android.sh

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Automates:
5+
# 1) Set version.properties to a non-SNAPSHOT
6+
# 2) Commit "Release X.Y.Z"
7+
# 3) Tag "X.Y.Z" (annotated)
8+
# 4) Push + push --tags
9+
# 5) Bump to next -SNAPSHOT (defaults to patch+1)
10+
# 6) Commit "Prepare next development version."
11+
# 7) Push
12+
#
13+
# Usage examples:
14+
# ./release_android.sh --new-version 1.2.3
15+
# ./release_android.sh --new-version 1.2.3 --bump minor
16+
# ./release_android.sh --new-version 1.2.3 --next-snapshot 1.3.0-SNAPSHOT
17+
#
18+
# Optional:
19+
# --version-file <path> default: version.properties
20+
# --no-push do everything except pushing
21+
# --dry-run print what would happen, don’t change anything
22+
# --tag-prefix "" default: "" (set to "v" if you want tags like v1.2.3)
23+
24+
NEW_VERSION=""
25+
NEXT_SNAPSHOT=""
26+
VERSION_FILE="${VERSION_FILE:-version.properties}"
27+
BUMP_KIND="patch" # patch|minor|major
28+
PUSH="true"
29+
DRY_RUN="false"
30+
TAG_PREFIX="${TAG_PREFIX:-}"
31+
32+
die() { echo "Error: $*" >&2; exit 1; }
33+
run() { if [[ "$DRY_RUN" == "true" ]]; then echo "[dry-run] $*"; else eval "$@"; fi; }
34+
35+
usage() {
36+
cat <<EOF
37+
Usage: $(basename "$0") --new-version X.Y.Z [options]
38+
39+
Required:
40+
--new-version X.Y.Z Release version (must NOT contain -SNAPSHOT)
41+
42+
Options:
43+
--next-snapshot A.B.C-SNAPSHOT
44+
If omitted, computed by bumping --bump (default: patch)
45+
--bump patch|minor|major How to compute next snapshot (default: patch)
46+
--version-file <path> Path to version.properties
47+
(default: ${VERSION_FILE})
48+
--tag-prefix <prefix> Prefix for git tag (default: "${TAG_PREFIX}")
49+
--no-push Do everything except pushing
50+
--dry-run Show actions without changing anything
51+
-h | --help Show this help
52+
EOF
53+
}
54+
55+
# --- Parse args ---
56+
while [[ $# -gt 0 ]]; do
57+
case "$1" in
58+
--new-version) NEW_VERSION="${2-}"; shift 2;;
59+
--next-snapshot) NEXT_SNAPSHOT="${2-}"; shift 2;;
60+
--bump) BUMP_KIND="${2-}"; shift 2;;
61+
--version-file) VERSION_FILE="${2-}"; shift 2;;
62+
--tag-prefix) TAG_PREFIX="${2-}"; shift 2;;
63+
--no-push) PUSH="false"; shift;;
64+
--dry-run) DRY_RUN="true"; shift;;
65+
-h|--help) usage; exit 0;;
66+
*) die "Unknown option: $1";;
67+
esac
68+
done
69+
70+
[[ -n "$NEW_VERSION" ]] || { usage; die "--new-version is required"; }
71+
[[ "$NEW_VERSION" =~ -SNAPSHOT$ ]] && die "--new-version must NOT include -SNAPSHOT"
72+
73+
# --- Helpers for version.properties (expects a line like VERSION_NAME=1.2.3) ---
74+
get_version() {
75+
[[ -f "$VERSION_FILE" ]] || die "version file not found: $VERSION_FILE"
76+
grep -E '^VERSION_NAME=' "$VERSION_FILE" | head -n1 | cut -d'=' -f2- || true
77+
}
78+
79+
set_version() {
80+
local v="$1"
81+
[[ -f "$VERSION_FILE" ]] || die "version file not found: $VERSION_FILE"
82+
if [[ "$DRY_RUN" == "true" ]]; then
83+
echo "[dry-run] set VERSION_NAME=$v in $VERSION_FILE"
84+
else
85+
if grep -qE '^VERSION_NAME=' "$VERSION_FILE"; then
86+
sed -i.bak -E "s/^VERSION_NAME=.*/VERSION_NAME=${v}/" "$VERSION_FILE"
87+
rm -f "${VERSION_FILE}.bak"
88+
else
89+
echo "VERSION_NAME=${v}" >> "$VERSION_FILE"
90+
fi
91+
fi
92+
}
93+
94+
bump_semver() {
95+
local base="$1" kind="$2"
96+
# base must be X.Y.Z (no -SNAPSHOT)
97+
[[ "$base" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] || die "Invalid semver: $base"
98+
local major="${BASH_REMATCH[1]}"
99+
local minor="${BASH_REMATCH[2]}"
100+
local patch="${BASH_REMATCH[3]}"
101+
102+
case "$kind" in
103+
patch) patch=$((patch+1));;
104+
minor) minor=$((minor+1)); patch=0;;
105+
major) major=$((major+1)); minor=0; patch=0;;
106+
*) die "Unknown bump kind: $kind";;
107+
esac
108+
109+
echo "${major}.${minor}.${patch}-SNAPSHOT"
110+
}
111+
112+
# --- Sanity checks ---
113+
CURRENT_VERSION="$(get_version)"
114+
[[ -n "$CURRENT_VERSION" ]] || die "Could not read VERSION_NAME from $VERSION_FILE"
115+
116+
if [[ -z "$NEXT_SNAPSHOT" ]]; then
117+
NEXT_SNAPSHOT="$(bump_semver "$NEW_VERSION" "$BUMP_KIND")"
118+
fi
119+
[[ "$NEXT_SNAPSHOT" =~ -SNAPSHOT$ ]] || die "--next-snapshot must end with -SNAPSHOT (got: $NEXT_SNAPSHOT)"
120+
121+
# Ensure clean working tree
122+
if [[ "$DRY_RUN" != "true" ]]; then
123+
if [[ -n "$(git status --porcelain)" ]]; then
124+
die "Working tree is dirty. Commit or stash changes before releasing."
125+
fi
126+
fi
127+
128+
# Ensure tag doesn't already exist
129+
TAG_NAME="${TAG_PREFIX}${NEW_VERSION}"
130+
run "git fetch --tags"
131+
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
132+
die "Tag already exists: $TAG_NAME"
133+
fi
134+
135+
echo "Current VERSION_NAME: ${CURRENT_VERSION}"
136+
echo "Release version : ${NEW_VERSION}"
137+
echo "Next snapshot : ${NEXT_SNAPSHOT}"
138+
echo "Version file : ${VERSION_FILE}"
139+
echo "Tag name : ${TAG_NAME}"
140+
echo "Push to remote : ${PUSH}"
141+
echo "Dry run : ${DRY_RUN}"
142+
echo
143+
144+
# --- Step 1: set release version ---
145+
set_version "$NEW_VERSION"
146+
147+
# --- Step 2: commit release ---
148+
run "git add '$VERSION_FILE'"
149+
run "git commit -m 'Release ${NEW_VERSION}'"
150+
151+
# --- Step 3: tag release (annotated) ---
152+
run "git tag -a '${TAG_NAME}' -m '${NEW_VERSION}'"
153+
154+
# --- Step 4: push commit + tags ---
155+
if [[ "$PUSH" == "true" ]]; then
156+
run "git push"
157+
run "git push --tags"
158+
else
159+
echo "[info] Skipping push (--no-push)"
160+
fi
161+
162+
# --- Step 5: bump to next snapshot ---
163+
set_version "$NEXT_SNAPSHOT"
164+
165+
# --- Step 6: commit snapshot ---
166+
run "git add '$VERSION_FILE'"
167+
run "git commit -m 'Prepare next development version.'"
168+
169+
# --- Step 7: push snapshot commit ---
170+
if [[ "$PUSH" == 'true' ]]; then
171+
run "git push"
172+
else
173+
echo "[info] Skipping push (--no-push)"
174+
fi
175+
176+
echo "✅ Release ${NEW_VERSION} completed. Next development version: ${NEXT_SNAPSHOT}"

0 commit comments

Comments
 (0)