-
Notifications
You must be signed in to change notification settings - Fork 1
140 lines (118 loc) · 5.02 KB
/
build-android.yml
File metadata and controls
140 lines (118 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Build Android APK
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Optional version to use (e.g. 1.2.3). If provided, this overrides tag-based version.'
required: false
default: ''
release_notes:
description: 'Release notes to include in the GitHub Release'
required: false
default: ''
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Release Notes from Commit History
id: release_notes
run: |
echo "Recent tags:"
git tag --sort=-v:refname | head -n 5
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
CURRENT_REF="${{ github.ref_name }}"
# Find the previous tag relative to the current tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "${CURRENT_REF}^" 2>/dev/null || echo "")
else
CURRENT_REF="HEAD"
# Find the latest tag reachable from HEAD
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
fi
echo "Generating notes from '$PREVIOUS_TAG' to '$CURRENT_REF'"
if [[ -z "$PREVIOUS_TAG" ]]; then
echo "No previous tag found. Getting last 20 commits."
COMMITS=$(git log -n 20 --pretty=format:"- %s (%h)" "$CURRENT_REF")
else
COMMITS=$(git log "$PREVIOUS_TAG..$CURRENT_REF" --pretty=format:"- %s (%h)")
fi
# Filter out merge commits if desired, or keep them.
# Here we keep them but maybe format them nicely?
# Let's just use the raw log for now as requested.
# Multiline output to GITHUB_OUTPUT
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "LOG<<$EOF" >> $GITHUB_OUTPUT
echo "$COMMITS" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- name: Determine version
id: version
run: |
# Prefer manual input when provided
if [[ -n "${{ github.event.inputs.version || '' }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
echo "Using manual input version: $VERSION"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
echo "Using tag-based version: $VERSION"
else
VERSION=1.0.0
echo "Using default version: $VERSION"
fi
# Strip 'v' prefix if user typed it manually
VERSION=${VERSION#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
- name: Install dependencies
run: npm install
- name: Update app.json version
run: |
node -e "
const fs = require('fs');
const appJson = JSON.parse(fs.readFileSync('app.json', 'utf8'));
appJson.expo.version = '${{ steps.version.outputs.version }}';
fs.writeFileSync('app.json', JSON.stringify(appJson, null, 2) + '\n');
console.log('✅ Updated app.json version to: ${{ steps.version.outputs.version }}');
"
echo "📄 Verifying app.json update:"
cat app.json | grep -A 1 '"version"'
- name: Update build.gradle version
run: |
VERSION="${{ steps.version.outputs.version }}"
VERSION_CODE=$(echo "$VERSION" | sed 's/\.//g')
echo "📝 Updating build.gradle with version: $VERSION (versionCode: $VERSION_CODE)"
sed -i "s/versionCode [0-9]*/versionCode $VERSION_CODE/" android/app/build.gradle
sed -i "s/versionName \"[^\"]*\"/versionName \"$VERSION\"/" android/app/build.gradle
echo "✅ Updated build.gradle:"
grep -A 2 "versionCode\|versionName" android/app/build.gradle
- name: Decode Keystore
run: echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app/release.keystore
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
- name: Build Release APK
run: cd android && ./gradlew assembleRelease
env:
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
- name: Rename APK
run: |
mv android/app/build/outputs/apk/release/app-release.apk android/app/build/outputs/apk/release/cbv-vpn-v${{ steps.version.outputs.version }}.apk
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: cbv-vpn-v${{ steps.version.outputs.version }}.apk
path: android/app/build/outputs/apk/release/cbv-vpn-v${{ steps.version.outputs.version }}.apk
retention-days: 30