Skip to content

Commit 2a06897

Browse files
committed
Edit Workflows for custom Version details
1 parent 289b720 commit 2a06897

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,51 @@ jobs:
1212
steps:
1313
- name: Checkout repository
1414
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Important: get all tags!
17+
18+
- name: Get Latest Tag
19+
run: |
20+
latest_tag=$(git describe --tags --abbrev=0)
21+
echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV
22+
23+
- name: Count Commits Since Latest Tag
24+
run: |
25+
# Get the number of commits since the latest tag
26+
commits_since_tag=$(git rev-list ${LATEST_TAG}..HEAD --count)
27+
echo "COMMITS_SINCE_TAG=${commits_since_tag}" >> $GITHUB_ENV
28+
29+
- name: Generate Version
30+
run: |
31+
# Extract version components
32+
version_base="${LATEST_TAG#v}"
33+
major=$(echo $version_base | cut -d. -f1)
34+
minor=$(echo $version_base | cut -d. -f2)
35+
patch=$(echo $version_base | cut -d. -f3)
36+
37+
# Increment patch by the number of commits since the last tag
38+
new_patch=$((patch + $COMMITS_SINCE_TAG))
39+
40+
# Construct the new version string
41+
new_version="$major.$minor.$new_patch"
42+
43+
# Calculate the version code (e.g., 1.0.5 -> 10005)
44+
version_code=$((major * 10000 + minor * 100 + new_patch))
45+
46+
# Set environment variables
47+
echo "NEW_VERSION_NAME=${new_version}" >> $GITHUB_ENV
48+
echo "NEW_VERSION_CODE=${version_code}" >> $GITHUB_ENV
49+
50+
- name: Update build.gradle with new version code and version name
51+
run: |
52+
# Update versionCode and versionName in build.gradle
53+
sed -i "s/versionCode [0-9]\+/versionCode ${NEW_VERSION_CODE}/" app/build.gradle
54+
sed -i "s/versionName \"[^\"]*\"/versionName \"${NEW_VERSION_NAME}\"/" app/build.gradle
55+
56+
- name: Print Version
57+
run: |
58+
echo "Version Name: $NEW_VERSION_NAME"
59+
echo "Version Code: $NEW_VERSION_CODE"
1560
1661
- name: Set up JDK 21
1762
uses: actions/setup-java@v4

.github/workflows/publish.yml

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ permissions:
44
on:
55
workflow_dispatch:
66
inputs:
7+
increment_major:
8+
description: 'Increment Major Version by?'
9+
required: true
10+
default: 0
11+
type: number
12+
increment_minor:
13+
description: 'Increment Minor Version by?'
14+
required: true
15+
default: 0
16+
type: number
17+
increment_patch:
18+
description: 'Increment Patch Version by?'
19+
required: true
20+
default: 0
21+
type: number
722
changes_in_release:
823
description: 'Changes in release'
924
required: true
@@ -17,6 +32,47 @@ jobs:
1732
steps:
1833
- name: Checkout repository
1934
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0 # Important: get all tags!
37+
38+
- name: Get Latest Tag
39+
run: |
40+
latest_tag=$(git describe --tags --abbrev=0)
41+
echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV
42+
43+
- name: Generate Version
44+
run: |
45+
# Extract version components
46+
version_base="${LATEST_TAG#v}"
47+
major=$(echo $version_base | cut -d. -f1)
48+
minor=$(echo $version_base | cut -d. -f2)
49+
patch=$(echo $version_base | cut -d. -f3)
50+
51+
# Increment versions by the specified input values
52+
new_major=$((major + ${{ github.event.inputs.increment_major }}))
53+
new_minor=$((minor + ${{ github.event.inputs.increment_minor }}))
54+
new_patch=$((patch + ${{ github.event.inputs.increment_patch }}))
55+
56+
# Construct the new version string
57+
new_version="$major.$minor.$new_patch"
58+
59+
# Calculate the version code (e.g., 1.0.5 -> 10005)
60+
version_code=$((major * 10000 + minor * 100 + new_patch))
61+
62+
# Set environment variables
63+
echo "NEW_VERSION_NAME=${new_version}" >> $GITHUB_ENV
64+
echo "NEW_VERSION_CODE=${version_code}" >> $GITHUB_ENV
65+
66+
- name: Update build.gradle with new version code and version name
67+
run: |
68+
# Update versionCode and versionName in build.gradle
69+
sed -i "s/versionCode [0-9]\+/versionCode ${NEW_VERSION_CODE}/" app/build.gradle
70+
sed -i "s/versionName \"[^\"]*\"/versionName \"${NEW_VERSION_NAME}\"/" app/build.gradle
71+
72+
- name: Print Version
73+
run: |
74+
echo "Version Name: $NEW_VERSION_NAME"
75+
echo "Version Code: $NEW_VERSION_CODE"
2076
2177
- name: Set up JDK 21
2278
uses: actions/setup-java@v4
@@ -63,8 +119,8 @@ jobs:
63119
allowUpdates: true
64120
removeArtifacts: true
65121
draft: true
66-
name: "1.${{ github.run_number }}.0"
67-
tag: "v1.${{ github.run_number }}.0"
122+
name: ${{ env.NEW_VERSION_NAME }}
123+
tag: "v${{ env.NEW_VERSION_NAME }}"
68124
body: |
69125
Note: KernelFlasher + allow-errors
70126

0 commit comments

Comments
 (0)