-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathandroid-sample-build-release.yml
More file actions
139 lines (119 loc) · 5.02 KB
/
android-sample-build-release.yml
File metadata and controls
139 lines (119 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
name: Android Sample App Build & Release
on:
workflow_dispatch:
inputs:
version_bump_type:
description: 'Version bump type'
required: true
default: 'patch'
type: 'choice'
options:
- patch
- minor
- major
permissions:
contents: write
env:
SAMPLE_APP_SIGNING_STORE_PASSWORD: ${{ secrets.SAMPLE_APP_SIGNING_STORE_PASSWORD }}
SAMPLE_APP_SIGNING_KEY_ALIAS: ${{ secrets.SAMPLE_APP_SIGNING_KEY_ALIAS }}
SAMPLE_APP_SIGNING_KEY_PASSWORD: ${{ secrets.SAMPLE_APP_SIGNING_KEY_PASSWORD }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: 'dev'
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
cache: gradle
- name: Setup Android SDK
uses: android-actions/setup-android@v2
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
# Extract current version from build.gradle
- name: Extract current version information
id: current_version
run: |
VERSION_NAME=$(grep "versionName" app/build.gradle.kts | sed 's/.*versionName\s*=\s*\"\(.*\)\".*/\1/')
VERSION_CODE=$(grep "versionCode" app/build.gradle.kts | sed 's/.*versionCode\s*=\s*\([0-9]*\).*/\1/')
echo "CURRENT_VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "CURRENT_VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV
echo "Current version: $VERSION_NAME (code: $VERSION_CODE)"
# Bump version based on selected type
- name: Bump version
id: bump_version
run: |
# Parse current version
IFS='.' read -r -a version_parts <<< "${{ env.CURRENT_VERSION_NAME }}"
MAJOR=${version_parts[0]}
MINOR=${version_parts[1]}
PATCH=${version_parts[2]}
# Bump version based on type
if [ "${{ github.event.inputs.version_bump_type }}" == "major" ]; then
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
elif [ "${{ github.event.inputs.version_bump_type }}" == "minor" ]; then
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
else
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
fi
# Calculate new version
NEW_VERSION_NAME="$NEW_MAJOR.$NEW_MINOR.$NEW_PATCH"
NEW_VERSION_CODE=$((${{ env.CURRENT_VERSION_CODE }} + 1))
echo "NEW_VERSION_NAME=$NEW_VERSION_NAME" >> $GITHUB_ENV
echo "NEW_VERSION_CODE=$NEW_VERSION_CODE" >> $GITHUB_ENV
echo "Version bumped to: $NEW_VERSION_NAME (code: $NEW_VERSION_CODE)"
# Update version in build.gradle
- name: Update version in build.gradle
run: |
# Replace version name
sed -i "s/versionName = \"${{ env.CURRENT_VERSION_NAME }}\"/versionName = \"${{ env.NEW_VERSION_NAME }}\"/g" app/build.gradle.kts
# Replace version code
sed -i "s/versionCode = ${{ env.CURRENT_VERSION_CODE }}/versionCode = ${{ env.NEW_VERSION_CODE }}/g" app/build.gradle.kts
echo "Updated version in build.gradle to ${{ env.NEW_VERSION_NAME }} (code: ${{ env.NEW_VERSION_CODE }})"
- name: Create keystore file
run: |
echo "${{ secrets.SAMPLE_APP_KEYSTORE_BASE64 }}" | base64 -d > app/keystore.jks
# Build the release APK and App Bundle
- name: Build release APK and AAB
run: |
./gradlew assembleRelease bundleRelease
- name: Configure Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Commit version bump to main
run: |
git add app/build.gradle.kts
git commit -m "Bump sample app version to ${{ env.NEW_VERSION_NAME }} (code: ${{ env.NEW_VERSION_CODE }})"
git push origin HEAD:main
- name: Create Git Tag
run: |
git tag v${{ env.NEW_VERSION_NAME }}
git push origin v${{ env.NEW_VERSION_NAME }}
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install gh -y
- name: Authenticate GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Create GitHub Release and Upload Assets
run: |
gh release create "v${{ env.NEW_VERSION_NAME }}" \
--title "Release v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" \
--notes "Release version ${{ env.NEW_VERSION_NAME }} (code ${{ env.NEW_VERSION_CODE }})\n\n### Assets\n- APK for direct installation\n- AAB for Google Play Store submission" \
app/build/outputs/apk/release/app-release.apk \
app/build/outputs/bundle/release/app-release.aab
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}