Browse Source

action: better release action

Steve Johnson 2 years ago
parent
commit
80037c2d23
2 changed files with 50 additions and 53 deletions
  1. 42 47
      .github/workflows/build-release.yaml
  2. 8 6
      README.md

+ 42 - 47
.github/workflows/build-release.yaml

@@ -1,15 +1,11 @@
 name: Build Release
 name: Build Release
 
 
 on:
 on:
-  push:
-    tags:
-      - '*' #
   workflow_dispatch:
   workflow_dispatch:
     inputs:
     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:
 jobs:
   BuildRelease:
   BuildRelease:
@@ -43,39 +39,40 @@ jobs:
           restore-keys: |
           restore-keys: |
             ${{ runner.os }}-go-
             ${{ 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: |
         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: |
         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
       - name: Signing properties
         env:
         env:
@@ -96,20 +93,11 @@ jobs:
         uses: gradle/gradle-build-action@v2
         uses: gradle/gradle-build-action@v2
         with:
         with:
           arguments: --no-daemon app:assembleMetaRelease
           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
       - name: Tag Repo
         uses: richardsimko/update-tag@v1
         uses: richardsimko/update-tag@v1
         with:
         with:
-          tag_name: ${{ steps.real_tag.outputs.tag }}
+          tag_name: ${{ steps.process-version.outputs.versonName }}
         env:
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
 
@@ -117,9 +105,16 @@ jobs:
         uses: softprops/action-gh-release@v1
         uses: softprops/action-gh-release@v1
         if: ${{ success() }}
         if: ${{ success() }}
         with:
         with:
-          tag_name: ${{ steps.real_tag.outputs.tag }}
+          tag_name: ${{ steps.process-version.outputs.versonName }}
           files: app/build/outputs/apk/meta/release/*
           files: app/build/outputs/apk/meta/release/*
           generate_release_notes: true
           generate_release_notes: true
 
 
       - name: Release Changelog Builder
       - name: Release Changelog Builder
         uses: mikepenz/release-changelog-builder-action@v3.6.0
         uses: mikepenz/release-changelog-builder-action@v3.6.0
+        with:
+          configurationJson: |
+            {
+              "ignore_labels": [
+                "Update"
+              ],
+            }

+ 8 - 6
README.md

@@ -60,18 +60,20 @@ APP package name is `com.github.metacubex.clash.meta`
 - Import a profile
 - Import a profile
   - URL Scheme `clash://install-config?url=<encoded URI>` or `clashmeta://install-config?url=<encoded URI>`
   - URL Scheme `clash://install-config?url=<encoded URI>` or `clashmeta://install-config?url=<encoded URI>`
 
 
-### Kernel Contribution
+### Contribution and Project Maintainance
+
+#### Meta Kernel
 
 
 - CMFA uses the kernel from `android-real` branch under `MetaCubeX/Clash.Meta`, which is a merge of the main `Alpha` branch and `android-open`.
 - CMFA uses the kernel from `android-real` branch under `MetaCubeX/Clash.Meta`, which is a merge of the main `Alpha` branch and `android-open`.
   - If you want to contribute to the kernel, make PRs to `Alpha` branch of the Meta kernel repository.
   - If you want to contribute to the kernel, make PRs to `Alpha` branch of the Meta kernel repository.
   - If you want to contribute Android-specific patches to the kernel, make PRs to  `android-open` branch of the Meta kernel repository.
   - If you want to contribute Android-specific patches to the kernel, make PRs to  `android-open` branch of the Meta kernel repository.
 
 
-### Project Maintainance
+#### Maintainance
 
 
 - When `MetaCubeX/Clash.Meta` kernel is updated to a new version, the `Update Dependencies` actions in this repo will be triggered automatically.
 - When `MetaCubeX/Clash.Meta` kernel is updated to a new version, the `Update Dependencies` actions in this repo will be triggered automatically.
   - It will pull the new version of the meta kernel, update all the golang dependencies, and create a PR without manual intervention.
   - It will pull the new version of the meta kernel, update all the golang dependencies, and create a PR without manual intervention.
   - If there is any compile error in PR, you need to fix it before merging. Alternatively, you may merge the PR directly.
   - If there is any compile error in PR, you need to fix it before merging. Alternatively, you may merge the PR directly.
-- Manually triggering `Build Pre-Release` actions will automatically compile and publish a `PreRelease` version.
-- Manually triggering `Build Release` actions will automatically compile, tag and publish a `Release` version.
-  - 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.
-  - This option is intended for quickly update and release a new version online, without pulling the repository locally and work around by manual.
+- Manually triggering `Build Pre-Release` actions will compile and publish a `PreRelease` version.
+- Manually triggering `Build Release` actions will compile, tag and publish a `Release` version.
+  - You must fill the blank `Release Tag` with the tag you want to release in the format of `v1.2.3`.
+  - `versionName` and `versionCode` in `build.gradle.kts` will be automatically bumped to the tag you filled above.