mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
action: better release action
This commit is contained in:
89
.github/workflows/build-release.yaml
vendored
89
.github/workflows/build-release.yaml
vendored
@@ -1,15 +1,11 @@
|
||||
name: Build Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*' #
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
auto-bump-version:
|
||||
description: 'Auto bump project version before building release'
|
||||
required: false
|
||||
type: boolean
|
||||
release-tag:
|
||||
description: 'Release Tag (v2.x.x)'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
BuildRelease:
|
||||
@@ -43,39 +39,40 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
# If auto-bump-version is chosen BEGIN
|
||||
- name: Configure Git
|
||||
if: ${{ inputs.auto-bump-version }}
|
||||
- name: Convert and set version env
|
||||
id: process-version
|
||||
run: |
|
||||
git config --global user.name 'GitHub Action'
|
||||
git config --global user.email 'action@github.com'
|
||||
VERSION_TAG=${{ inputs.release-tag }}
|
||||
VERSION_TAG=${VERSION_TAG#v} # remove the 'v' prefix
|
||||
IFS='.' read -ra VERSION_PARTS <<< "$VERSION_TAG" # split into array
|
||||
VERSION_CODE=$(printf "%1d%02d%03d" "${VERSION_PARTS[0]}" "${VERSION_PARTS[1]}" "${VERSION_PARTS[2]}")
|
||||
|
||||
echo "versonName=${{ inputs.release-tag }}" >> $GITHUB_OUTPUT
|
||||
echo "versonCode=$VERSION_CODE" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Auto bump project version
|
||||
if: ${{ inputs.auto-bump-version }}
|
||||
id: bump-version
|
||||
run: |
|
||||
versionCode=$(grep -oP 'versionCode = \K\d+' build.gradle.kts)
|
||||
versionName=$(grep -oP 'versionName = "\K[0-9.]+' build.gradle.kts)
|
||||
major=$(echo $versionName | cut -d. -f1)
|
||||
minor=$(echo $versionName | cut -d. -f2)
|
||||
patch=$(echo $versionName | cut -d. -f3)
|
||||
newPatch=$((patch + 1))
|
||||
newVersionName="$major.$minor.$newPatch"
|
||||
newVersionCode=$((versionCode + 1))
|
||||
sed -i "s/versionCode = $versionCode/versionCode = $newVersionCode/" build.gradle.kts
|
||||
sed -i "s/versionName = \"$versionName\"/versionName = \"$newVersionName\"/" build.gradle.kts
|
||||
echo "newVersionName=$newVersionName" >> $GITHUB_OUTPUT
|
||||
echo "newVersionCode=$newVersionCode" >> $GITHUB_OUTPUT
|
||||
# Re-write version in build.gradle.kts
|
||||
- name: Re-write version
|
||||
uses: Devofure/advance-android-version-actions@v1.4
|
||||
with:
|
||||
gradlePath: build.gradle.kts
|
||||
versionCode: ${{ steps.process-version.outputs.versonCode }}
|
||||
versionName: ${{ steps.process-version.outputs.versonName }}
|
||||
|
||||
- name: Commit modified version code and make new tag
|
||||
if: ${{ inputs.auto-bump-version }}
|
||||
# If any change found, commit it and push
|
||||
- name: Commit and push if changes
|
||||
run: |
|
||||
newVersionName=${{ steps.bump-version.outputs.newVersionName }}
|
||||
newVersionCode=${{ steps.bump-version.outputs.newVersionCode }}
|
||||
git commit -am "Bump version to $newVersionName ($newVersionCode)"
|
||||
git tag "v$newVersionName"
|
||||
git push --follow-tags
|
||||
# If auto-bump-version is chosen END
|
||||
changes=$(git diff --name-only origin/main | wc -l)
|
||||
if [ $changes -gt 0 ]
|
||||
then
|
||||
newVersionName=${{ steps.process-version.outputs.versonName }}
|
||||
newVersionCode=${{ steps.process-version.outputs.versonCode }}
|
||||
git config --global user.name 'GitHub Action'
|
||||
git config --global user.email 'action@github.com'
|
||||
git add build.gradle.kts
|
||||
git commit -am "Bump version to $newVersionName ($newVersionCode)"
|
||||
git tag "v$newVersionName"
|
||||
git push --follow-tags
|
||||
fi
|
||||
|
||||
- name: Signing properties
|
||||
env:
|
||||
@@ -96,20 +93,11 @@ jobs:
|
||||
uses: gradle/gradle-build-action@v2
|
||||
with:
|
||||
arguments: --no-daemon app:assembleMetaRelease
|
||||
|
||||
- name: Get real tag value (current or auto-bumped?)
|
||||
id: real_tag
|
||||
run: |
|
||||
if [[ "${{ inputs.auto-bump-version }}" == "true" ]]; then
|
||||
echo "tag=v${{ steps.bump-version.outputs.newVersionName }}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Tag Repo
|
||||
uses: richardsimko/update-tag@v1
|
||||
with:
|
||||
tag_name: ${{ steps.real_tag.outputs.tag }}
|
||||
tag_name: ${{ steps.process-version.outputs.versonName }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -117,9 +105,16 @@ jobs:
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: ${{ success() }}
|
||||
with:
|
||||
tag_name: ${{ steps.real_tag.outputs.tag }}
|
||||
tag_name: ${{ steps.process-version.outputs.versonName }}
|
||||
files: app/build/outputs/apk/meta/release/*
|
||||
generate_release_notes: true
|
||||
|
||||
- name: Release Changelog Builder
|
||||
uses: mikepenz/release-changelog-builder-action@v3.6.0
|
||||
with:
|
||||
configurationJson: |
|
||||
{
|
||||
"ignore_labels": [
|
||||
"Update"
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user