-
-
Notifications
You must be signed in to change notification settings - Fork 113
164 lines (145 loc) · 6.43 KB
/
update_version_and_publish.yaml
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Update version and publish APK
on:
workflow_dispatch:
inputs:
version_name:
description: "Version number (must be in x.y.z format)"
required: true
version_code:
description: "Version code of the new build (must be a number only). Enter 0 to automatically increment one from the previous version code"
required: true
default: 0
release_type:
description: "Type of release (release or preview)"
required: true
default: "preview"
type: choice
options:
- release
- preview
release_notes:
description: "Release notes for the release type"
default: ""
jobs:
update_version_and_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get updated version name and version code
run: |
# Extract version name from github inputs
BASE_VERSION="${{ github.event.inputs.version_name }}"
BRANCH_NAME="release/v${BASE_VERSION}"
git fetch --all
if git rev-parse --verify origin/${BRANCH_NAME} >/dev/null 2>&1; then
echo "Branch ${BRANCH_NAME} exists, checking out..."
git checkout ${BRANCH_NAME}
else
echo "Branch ${BRANCH_NAME} does not exist, creating..."
git checkout -b ${BRANCH_NAME}
fi
CURRENT_RC=$(git tag -l "v${BASE_VERSION}-rc*" | sort | tail -n 1)
if [[ -z "$CURRENT_RC" ]]; then
RC_SUFFIX="-rc01"
else
SUFFIX_NUMBER=$(echo $CURRENT_RC | grep -oP '(?<=-rc)\d+')
NEXT_SUFFIX=$(printf "%02d" $((10#$SUFFIX_NUMBER + 1)))
RC_SUFFIX="-rc${NEXT_SUFFIX}"
fi
# Version name with rc suffix
if [[ "${{ github.event.inputs.release_type }}" == "preview" ]]; then
VERSION_NAME="${BASE_VERSION}${RC_SUFFIX}"
else
VERSION_NAME="${BASE_VERSION}"
fi
if [[ "${{ github.event.inputs.version_code }}" == "0" ]]; then
# Get existing version code from build.gradle
VERSION_CODE=$(grep "versionCode" app/build.gradle.kts | awk '{print $3}')
VERSION_CODE=$((VERSION_CODE + 1))
else
VERSION_CODE=${{ github.event.inputs.version_code }}
fi
# Set environment variable for later use
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV
- name: Update app/build.gradle.kts updated version name and version code
run: |
echo "Updating version code to ${{ env.VERSION_CODE }} and version name to ${{ env.VERSION_NAME }}"
sed -i "s/versionCode = [0-9]\+/versionCode = ${{ env.VERSION_CODE }}/g" app/build.gradle.kts
sed -i "s/versionName = \"[^\"]*\"/versionName = \"${{ env.VERSION_NAME }}\"/g" app/build.gradle.kts
- name: Create changelog file (if release notes provided)
if: ${{ github.event.inputs.release_notes != '' }}
run: |
echo "Creating changelog for version code ${{ env.VERSION_CODE }}"
echo "${{ github.event.inputs.release_notes }}" > fastlane/metadata/android/en-US/changelogs/${{ env.VERSION_CODE }}.txt
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.0
bundler-cache: true
- name: Set Up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
validate-wrappers: true
gradle-home-cache-cleanup: true
- name: Decode keystore file
uses: timheuer/base64-to-file@v1
id: keystore
with:
fileName: 'keystore.jks'
encodedString: ${{ secrets.KEYSTORE }}
- name: Decode Play API credentials file
uses: timheuer/base64-to-file@v1
id: play_api_credentials
with:
fileName: 'play-api-credentials.json'
encodedString: ${{ secrets.PLAY_API_CREDENTIALS }}
- name: Build app and publish
run: |
if [[ "${{ github.event.inputs.release_type }}" == "release" ]]; then
echo "Running fastlane publish"
bundle exec fastlane publish
else
echo "Running fastlane build"
bundle exec fastlane build
fi
if: ${{ github.event.inputs.release_type == 'release' }}
env:
KEYSTORE: ${{ steps.keystore.outputs.filePath }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
PLAY_API_CREDENTIALS: ${{ steps.play_api_credentials.outputs.filePath }}
- name: Rename Files
run: |
mv app/build/outputs/apk/release/app-arm64-v8a-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-arm64-v8a.apk
mv app/build/outputs/apk/release/app-armeabi-v7a-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-armeabi-v7a.apk
mv app/build/outputs/apk/release/app-universal-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-universal.apk
mv app/build/outputs/apk/release/app-x86-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-x86.apk
mv app/build/outputs/apk/release/app-x86_64-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-x86_64.apk
- name: Commit and Push Changes
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add .
git commit -m "Release version ${{ env.VERSION_NAME }}" || echo "No changes to commit"
git config push.autoSetupRemote true
git push --set-upstream origin ${BRANCH_NAME}
- name: Create Draft Release
id: create_draft_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: app/build/outputs/apk/release/nextplayer*
draft: true
name: v${{ env.VERSION_NAME }}
generate_release_notes: true
prerelease: ${{ github.event.inputs.release_type == 'preview' }}
tag_name: v${{ env.VERSION_NAME }}