Skip to content

Commit 80037c2

Browse files
committed
action: better release action
1 parent cbbcc2a commit 80037c2

2 files changed

Lines changed: 50 additions & 53 deletions

File tree

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
name: Build Release
22

33
on:
4-
push:
5-
tags:
6-
- '*' #
74
workflow_dispatch:
85
inputs:
9-
auto-bump-version:
10-
description: 'Auto bump project version before building release'
11-
required: false
12-
type: boolean
6+
release-tag:
7+
description: 'Release Tag (v2.x.x)'
8+
required: true
139

1410
jobs:
1511
BuildRelease:
@@ -43,39 +39,40 @@ jobs:
4339
restore-keys: |
4440
${{ runner.os }}-go-
4541
46-
# If auto-bump-version is chosen BEGIN
47-
- name: Configure Git
48-
if: ${{ inputs.auto-bump-version }}
42+
- name: Convert and set version env
43+
id: process-version
4944
run: |
50-
git config --global user.name 'GitHub Action'
51-
git config --global user.email 'action@github.com'
45+
VERSION_TAG=${{ inputs.release-tag }}
46+
VERSION_TAG=${VERSION_TAG#v} # remove the 'v' prefix
47+
IFS='.' read -ra VERSION_PARTS <<< "$VERSION_TAG" # split into array
48+
VERSION_CODE=$(printf "%1d%02d%03d" "${VERSION_PARTS[0]}" "${VERSION_PARTS[1]}" "${VERSION_PARTS[2]}")
49+
50+
echo "versonName=${{ inputs.release-tag }}" >> $GITHUB_OUTPUT
51+
echo "versonCode=$VERSION_CODE" >> $GITHUB_OUTPUT
5252
53-
- name: Auto bump project version
54-
if: ${{ inputs.auto-bump-version }}
55-
id: bump-version
56-
run: |
57-
versionCode=$(grep -oP 'versionCode = \K\d+' build.gradle.kts)
58-
versionName=$(grep -oP 'versionName = "\K[0-9.]+' build.gradle.kts)
59-
major=$(echo $versionName | cut -d. -f1)
60-
minor=$(echo $versionName | cut -d. -f2)
61-
patch=$(echo $versionName | cut -d. -f3)
62-
newPatch=$((patch + 1))
63-
newVersionName="$major.$minor.$newPatch"
64-
newVersionCode=$((versionCode + 1))
65-
sed -i "s/versionCode = $versionCode/versionCode = $newVersionCode/" build.gradle.kts
66-
sed -i "s/versionName = \"$versionName\"/versionName = \"$newVersionName\"/" build.gradle.kts
67-
echo "newVersionName=$newVersionName" >> $GITHUB_OUTPUT
68-
echo "newVersionCode=$newVersionCode" >> $GITHUB_OUTPUT
53+
# Re-write version in build.gradle.kts
54+
- name: Re-write version
55+
uses: Devofure/advance-android-version-actions@v1.4
56+
with:
57+
gradlePath: build.gradle.kts
58+
versionCode: ${{ steps.process-version.outputs.versonCode }}
59+
versionName: ${{ steps.process-version.outputs.versonName }}
6960

70-
- name: Commit modified version code and make new tag
71-
if: ${{ inputs.auto-bump-version }}
61+
# If any change found, commit it and push
62+
- name: Commit and push if changes
7263
run: |
73-
newVersionName=${{ steps.bump-version.outputs.newVersionName }}
74-
newVersionCode=${{ steps.bump-version.outputs.newVersionCode }}
75-
git commit -am "Bump version to $newVersionName ($newVersionCode)"
76-
git tag "v$newVersionName"
77-
git push --follow-tags
78-
# If auto-bump-version is chosen END
64+
changes=$(git diff --name-only origin/main | wc -l)
65+
if [ $changes -gt 0 ]
66+
then
67+
newVersionName=${{ steps.process-version.outputs.versonName }}
68+
newVersionCode=${{ steps.process-version.outputs.versonCode }}
69+
git config --global user.name 'GitHub Action'
70+
git config --global user.email 'action@github.com'
71+
git add build.gradle.kts
72+
git commit -am "Bump version to $newVersionName ($newVersionCode)"
73+
git tag "v$newVersionName"
74+
git push --follow-tags
75+
fi
7976
8077
- name: Signing properties
8178
env:
@@ -96,30 +93,28 @@ jobs:
9693
uses: gradle/gradle-build-action@v2
9794
with:
9895
arguments: --no-daemon app:assembleMetaRelease
99-
100-
- name: Get real tag value (current or auto-bumped?)
101-
id: real_tag
102-
run: |
103-
if [[ "${{ inputs.auto-bump-version }}" == "true" ]]; then
104-
echo "tag=v${{ steps.bump-version.outputs.newVersionName }}" >> $GITHUB_OUTPUT
105-
else
106-
echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
107-
fi
10896

10997
- name: Tag Repo
11098
uses: richardsimko/update-tag@v1
11199
with:
112-
tag_name: ${{ steps.real_tag.outputs.tag }}
100+
tag_name: ${{ steps.process-version.outputs.versonName }}
113101
env:
114102
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115103

116104
- name: Upload Release
117105
uses: softprops/action-gh-release@v1
118106
if: ${{ success() }}
119107
with:
120-
tag_name: ${{ steps.real_tag.outputs.tag }}
108+
tag_name: ${{ steps.process-version.outputs.versonName }}
121109
files: app/build/outputs/apk/meta/release/*
122110
generate_release_notes: true
123111

124112
- name: Release Changelog Builder
125113
uses: mikepenz/release-changelog-builder-action@v3.6.0
114+
with:
115+
configurationJson: |
116+
{
117+
"ignore_labels": [
118+
"Update"
119+
],
120+
}

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,20 @@ APP package name is `com.github.metacubex.clash.meta`
6060
- Import a profile
6161
- URL Scheme `clash://install-config?url=<encoded URI>` or `clashmeta://install-config?url=<encoded URI>`
6262

63-
### Kernel Contribution
63+
### Contribution and Project Maintainance
64+
65+
#### Meta Kernel
6466

6567
- CMFA uses the kernel from `android-real` branch under `MetaCubeX/Clash.Meta`, which is a merge of the main `Alpha` branch and `android-open`.
6668
- If you want to contribute to the kernel, make PRs to `Alpha` branch of the Meta kernel repository.
6769
- If you want to contribute Android-specific patches to the kernel, make PRs to `android-open` branch of the Meta kernel repository.
6870

69-
### Project Maintainance
71+
#### Maintainance
7072

7173
- When `MetaCubeX/Clash.Meta` kernel is updated to a new version, the `Update Dependencies` actions in this repo will be triggered automatically.
7274
- It will pull the new version of the meta kernel, update all the golang dependencies, and create a PR without manual intervention.
7375
- If there is any compile error in PR, you need to fix it before merging. Alternatively, you may merge the PR directly.
74-
- Manually triggering `Build Pre-Release` actions will automatically compile and publish a `PreRelease` version.
75-
- Manually triggering `Build Release` actions will automatically compile, tag and publish a `Release` version.
76-
- There is an option `Auto bump project version` in trigger widget. If this option is checked and triggered, the `versionName` and `versionCode` in `build.gradle.kts` will be bumped first, then do the common build release process.
77-
- This option is intended for quickly update and release a new version online, without pulling the repository locally and work around by manual.
76+
- Manually triggering `Build Pre-Release` actions will compile and publish a `PreRelease` version.
77+
- Manually triggering `Build Release` actions will compile, tag and publish a `Release` version.
78+
- You must fill the blank `Release Tag` with the tag you want to release in the format of `v1.2.3`.
79+
- `versionName` and `versionCode` in `build.gradle.kts` will be automatically bumped to the tag you filled above.

0 commit comments

Comments
 (0)