From bd64da87382de03434c1e72dd9e9fb5e7c3ec173 Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 16:42:36 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20AppVeresionPlugin=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app-version.json | 6 +++ app/build.gradle.kts | 5 +- build-logic/build.gradle.kts | 4 ++ .../pomonyang/mohanyang/AppVersionPlugin.kt | 53 +++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 app-version.json create mode 100644 build-logic/src/main/java/com/pomonyang/mohanyang/AppVersionPlugin.kt diff --git a/app-version.json b/app-version.json new file mode 100644 index 00000000..7242b7d7 --- /dev/null +++ b/app-version.json @@ -0,0 +1,6 @@ +{ + "major": 0, + "minor": 1, + "patch": 3, + "code": 6 +} \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bc51836b..911930ff 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,6 +6,7 @@ plugins { id("mohanyang.android.hilt") id("mohanyang.android.application.compose") id("mohanyang.android.application.firebase") + id("mohanyang.appversion") } android { @@ -13,8 +14,8 @@ android { defaultConfig { applicationId = "com.pomonyang.mohanyang" - versionCode = 6 - versionName = "0.1.3" + versionCode = appVersion.code + versionName = appVersion.name } signingConfigs { diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 73211302..e9643e09 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -46,5 +46,9 @@ gradlePlugin { id = "mohanyang.android.hilt" implementationClass = "AndroidHiltConventionPlugin" } + register("appVersion") { + id = "mohanyang.appversion" + implementationClass = "com.pomonyang.mohanyang.AppVersionPlugin" + } } } diff --git a/build-logic/src/main/java/com/pomonyang/mohanyang/AppVersionPlugin.kt b/build-logic/src/main/java/com/pomonyang/mohanyang/AppVersionPlugin.kt new file mode 100644 index 00000000..23f1bf29 --- /dev/null +++ b/build-logic/src/main/java/com/pomonyang/mohanyang/AppVersionPlugin.kt @@ -0,0 +1,53 @@ +package com.pomonyang.mohanyang + +import groovy.json.JsonSlurper +import java.io.File +import org.gradle.api.Plugin +import org.gradle.api.Project + +open class AppVersionExtension(val name: String, val code: Int) + +data class AppVersion( + val major: Int, + val minor: Int, + val patch: Int, + val code: Int +) { + fun getName() = "$major.$minor.$patch" + fun getVersionCode() = code +} + +class AppVersionPlugin : Plugin { + override fun apply(project: Project) { + val versionFile = getAppVersionFile(project) + val appVersion = getAppVersion(versionFile) + setupAppVersionExtension(project, appVersion) + } + + private fun getAppVersionFile(project: Project): File { + val file = File(project.rootDir, "app-version.json") + if (!file.exists()) { + throw IllegalStateException("app-version.json file not found") + } + return file + } + + private fun getAppVersion(versionFile: File): AppVersion { + val appVersionJson = JsonSlurper().parseText(versionFile.readText()) as Map<*, *> + return AppVersion( + (appVersionJson["major"] as Number).toInt(), + (appVersionJson["minor"] as Number).toInt(), + (appVersionJson["patch"] as Number).toInt(), + (appVersionJson["code"] as Number).toInt() + ) + } + + private fun setupAppVersionExtension(project: Project, appVersion: AppVersion) { + project.extensions.create( + "appVersion", + AppVersionExtension::class.java, + appVersion.getName(), + appVersion.getVersionCode() + ) + } +} From a929e6784b790760af594849ca847ae13312cad4 Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 16:43:51 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20App=20version=20update=20flow=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/RELEASE_PR_TEMPLATE.md | 15 +++ .github/actions/get-app-version/action.yml | 39 ++++++++ .github/actions/update-app-version/action.yml | 44 +++++++++ .github/workflows/deploy-new-version.yml | 97 +++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 .github/RELEASE_PR_TEMPLATE.md create mode 100644 .github/actions/get-app-version/action.yml create mode 100644 .github/actions/update-app-version/action.yml create mode 100644 .github/workflows/deploy-new-version.yml diff --git a/.github/RELEASE_PR_TEMPLATE.md b/.github/RELEASE_PR_TEMPLATE.md new file mode 100644 index 00000000..6753a6e2 --- /dev/null +++ b/.github/RELEASE_PR_TEMPLATE.md @@ -0,0 +1,15 @@ +## RELEASE 모하냥 + +> 해당하는 업데이트 사항을 선택해주세요: + +- [ ] Major +- [ ] Minor +- [ ] Patch + +## 설명 + +이 PR에 포함된 변경 사항을 간략히 설명해주세요. + +## 체크리스트 + +- [ ] 체크 해야 하는 내용 \ No newline at end of file diff --git a/.github/actions/get-app-version/action.yml b/.github/actions/get-app-version/action.yml new file mode 100644 index 00000000..b3d9db7a --- /dev/null +++ b/.github/actions/get-app-version/action.yml @@ -0,0 +1,39 @@ +name: 'Get App Version' +description: 'Get App Version' + +outputs: + major: + description: "앱 버전 중 major" + value: ${{ steps.get-app-version.outputs.major }} + minor: + description: "앱 버전 중 minor" + value: ${{ steps.get-app-version.outputs.minor }} + patch: + description: "앱 버전 중 patch" + value: ${{ steps.get-app-version.outputs.patch }} + code: + description: "앱 버전 코드" + value: ${{ steps.get-app-version.outputs.code }} + version_name: + description: "앱 버전 이름" + value: ${{ steps.get-app-version.outputs.version_name }} + +runs: + using: "composite" + steps: + - name: Get App Version + id: get-app-version + shell: bash + run: | + major=$(jq .major app-version.json) + minor=$(jq .minor app-version.json) + patch=$(jq .patch app-version.json) + code=$(jq .code app-version.json) + + { + echo "major=$major" + echo "minor=$minor" + echo "patch=$patch" + echo "code=$code" + echo "version_name=$major.$minor.$patch" + } >> $GITHUB_OUTPUT \ No newline at end of file diff --git a/.github/actions/update-app-version/action.yml b/.github/actions/update-app-version/action.yml new file mode 100644 index 00000000..c1080735 --- /dev/null +++ b/.github/actions/update-app-version/action.yml @@ -0,0 +1,44 @@ +name: "Update App Version" + +inputs: + major: + description: "업데이트 할 앱 major" + required: true + minor: + description: "업데이트 할 앱 버전 minor" + required: true + patch: + description: "업데이트 할 앱 버전 patch" + required: true + code: + description: "업데이트 할 앱 버전 code" + required: true + file: + description: "업데이트 할 파일 경로" + required: true + +runs: + using: "composite" + steps: + - name: Update app version + shell: bash + run: | + VERSION_FILE="${{ inputs.file }}" + if command -v jq &> /dev/null; then + # jq가 설치되어 있는 경우 + jq '.major = $major | .minor = $minor | .patch = $patch | .code = $code' \ + --argjson major "${{ inputs.major }}" \ + --argjson minor "${{ inputs.minor }}" \ + --argjson patch "${{ inputs.patch }}" \ + --argjson code "${{ inputs.code }}" \ + $VERSION_FILE > tmp.$$.json && mv tmp.$$.json $VERSION_FILE + else + # jq가 설치되어 있지 않은 경우 + sed -i "s/\"major\": [0-9]\+/\"major\": ${{ inputs.major }}/" $VERSION_FILE + sed -i "s/\"minor\": [0-9]\+/\"minor\": ${{ inputs.minor }}/" $VERSION_FILE + sed -i "s/\"patch\": [0-9]\+/\"patch\": ${{ inputs.patch }}/" $VERSION_FILE + sed -i "s/\"code\": [0-9]\+/\"code\": ${{ inputs.code }}/" $VERSION_FILE + fi + git add $VERSION_FILE + git commit -m "Update app version to ${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }} [${{ inputs.code }}]" + git push origin HEAD \ No newline at end of file diff --git a/.github/workflows/deploy-new-version.yml b/.github/workflows/deploy-new-version.yml new file mode 100644 index 00000000..8d8dea45 --- /dev/null +++ b/.github/workflows/deploy-new-version.yml @@ -0,0 +1,97 @@ +name: Deploy New Version + +on: + pull_request: + types: [ closed ] + branches: + - test + push: + branches: + - test +jobs: + versioning: + if: github.event.pull_request.merged == true && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '14' + + - name: Install jq + run: sudo apt-get install jq -y + + - name: Determine Version Release Type + id: version_type + run: | + pr_body=$(echo "${{ github.event.pull_request.body }}" | tr '[:upper:]' '[:lower:]') + if [[ "$pr_body" =~ "major" ]]; then + echo "release_type=major" >> $GITHUB_ENV + elif [[ "$pr_body" =~ "minor" ]]; then + echo "release_type=minor" >> $GITHUB_ENV + else + echo "release_type=patch" >> $GITHUB_ENV + fi + + - name: Get App Version + uses: ./.github/actions/get-app-version + id: get-version + + - name: Echo Current App Version + run: | + echo "App Version: ${{ steps.get-version.outputs.version_name }}" + echo "Major Version: ${{ steps.get-version.outputs.major }}" + echo "Minor Version: ${{ steps.get-version.outputs.minor }}" + echo "Patch Version: ${{ steps.get-version.outputs.patch }}" + echo "Code: ${{ steps.get-version.outputs.code }}" + + + - name: Calculate New Version + id: calculate_version + run: | + major=${{ steps.get-version.outputs.major }} + minor=${{ steps.get-version.outputs.minor }} + patch=${{ steps.get-version.outputs.patch }} + code=${{ steps.get-version.outputs.code }} + + if [ "$release_type" = "major" ]; then + major=$((major + 1)) + minor=0 + patch=0 + elif [ "$release_type" = "minor" ]; then + minor=$((minor + 1)) + patch=0 + else + patch=$((patch + 1)) + fi + + code=$((code + 1)) + + echo "major=${major}" >> $GITHUB_OUTPUT + echo "minor=${minor}" >> $GITHUB_OUTPUT + echo "patch=${patch}" >> $GITHUB_OUTPUT + echo "code=${code}" >> $GITHUB_OUTPUT + echo "version_name=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT + + - name: Update App Version + uses: ./github/actions/update-app-version + with: + major: ${{ steps.calculate_version.outputs.major }} + minor: ${{ steps.calculate_version.outputs.minor }} + patch: ${{ steps.calculate_version.outputs.patch }} + code: ${{ steps.calculate_version.outputs.code }} + file: "app-version.json" + + - name: Get Updated App Version + id: get-updated-version + uses: ./github/actions/get-app-version + + - name: Create Git Tag + run: | + version_name=${{ steps.get-updated-version.outputs.version_name }} + git tag -a "v$version_name" -m "Version $version_name" + git push origin "v$version_name" \ No newline at end of file From 6adaee6aeb37bcb3b371d466d27b625e5662dbfc Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 16:48:25 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20RELEASE=20PR=20TEMPLATE=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BASIC_PR_TEMPLATE.md} | 0 .github/{ => PULL_REQUEST_TEMPLATE}/RELEASE_PR_TEMPLATE.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/{PULL_REQUEST_TEMPLATE.md => PULL_REQUEST_TEMPLATE/BASIC_PR_TEMPLATE.md} (100%) rename .github/{ => PULL_REQUEST_TEMPLATE}/RELEASE_PR_TEMPLATE.md (100%) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE/BASIC_PR_TEMPLATE.md similarity index 100% rename from .github/PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE/BASIC_PR_TEMPLATE.md diff --git a/.github/RELEASE_PR_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE/RELEASE_PR_TEMPLATE.md similarity index 100% rename from .github/RELEASE_PR_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE/RELEASE_PR_TEMPLATE.md From 57487a6369b20cd17ca567e3b5c26bbc40e07f39 Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 16:59:28 +0900 Subject: [PATCH 4/8] =?UTF-8?q?test:=20Test=20=EC=9A=A9=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=9E=84=EC=9D=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-new-version.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-new-version.yml b/.github/workflows/deploy-new-version.yml index 8d8dea45..58ad24b9 100644 --- a/.github/workflows/deploy-new-version.yml +++ b/.github/workflows/deploy-new-version.yml @@ -3,14 +3,13 @@ name: Deploy New Version on: pull_request: types: [ closed ] - branches: - - test + push: branches: - - test + - test/app-version jobs: versioning: - if: github.event.pull_request.merged == true && github.ref == 'refs/heads/main' + if: github.event.pull_request.merged == true && github.ref == 'refs/heads/test/app-version' runs-on: ubuntu-latest steps: From 5cedffed59e1e1e545547430142acaa42cc713a3 Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 17:35:22 +0900 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20commit=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/update-app-version/action.yml | 4 +++- .github/workflows/deploy-new-version.yml | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/actions/update-app-version/action.yml b/.github/actions/update-app-version/action.yml index c1080735..d3306504 100644 --- a/.github/actions/update-app-version/action.yml +++ b/.github/actions/update-app-version/action.yml @@ -39,6 +39,8 @@ runs: sed -i "s/\"patch\": [0-9]\+/\"patch\": ${{ inputs.patch }}/" $VERSION_FILE sed -i "s/\"code\": [0-9]\+/\"code\": ${{ inputs.code }}/" $VERSION_FILE fi + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" git add $VERSION_FILE git commit -m "Update app version to ${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }} [${{ inputs.code }}]" - git push origin HEAD \ No newline at end of file + git push \ No newline at end of file diff --git a/.github/workflows/deploy-new-version.yml b/.github/workflows/deploy-new-version.yml index 58ad24b9..d034aa6b 100644 --- a/.github/workflows/deploy-new-version.yml +++ b/.github/workflows/deploy-new-version.yml @@ -3,13 +3,12 @@ name: Deploy New Version on: pull_request: types: [ closed ] - - push: branches: - test/app-version + jobs: versioning: - if: github.event.pull_request.merged == true && github.ref == 'refs/heads/test/app-version' + if: github.ref == 'refs/heads/test/app-version' runs-on: ubuntu-latest steps: @@ -77,7 +76,7 @@ jobs: echo "version_name=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT - name: Update App Version - uses: ./github/actions/update-app-version + uses: ./.github/actions/update-app-version with: major: ${{ steps.calculate_version.outputs.major }} minor: ${{ steps.calculate_version.outputs.minor }} From a69e495f9ef8bf5c2aa232f9ad4de2859ff1f0ac Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 17:40:52 +0900 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20Test=20Branch=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-new-version.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-new-version.yml b/.github/workflows/deploy-new-version.yml index d034aa6b..bb9c02f4 100644 --- a/.github/workflows/deploy-new-version.yml +++ b/.github/workflows/deploy-new-version.yml @@ -1,10 +1,10 @@ name: Deploy New Version on: - pull_request: - types: [ closed ] + push: branches: - test/app-version + - cat/309 jobs: versioning: From 287284eaf51ab23d1f3d37bcaac404dddc485491 Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 17:46:52 +0900 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20push=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=EC=8B=9C=20commit=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/update-app-version/action.yml | 1 + .github/workflows/deploy-new-version.yml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/update-app-version/action.yml b/.github/actions/update-app-version/action.yml index d3306504..1046ac4f 100644 --- a/.github/actions/update-app-version/action.yml +++ b/.github/actions/update-app-version/action.yml @@ -22,6 +22,7 @@ runs: steps: - name: Update app version shell: bash + if: success() run: | VERSION_FILE="${{ inputs.file }}" if command -v jq &> /dev/null; then diff --git a/.github/workflows/deploy-new-version.yml b/.github/workflows/deploy-new-version.yml index bb9c02f4..74e62c79 100644 --- a/.github/workflows/deploy-new-version.yml +++ b/.github/workflows/deploy-new-version.yml @@ -4,7 +4,6 @@ on: push: branches: - test/app-version - - cat/309 jobs: versioning: From 719cd6b5439dee8c8e8eee3c0c0a9ba2d1444b16 Mon Sep 17 00:00:00 2001 From: Hyomk Date: Fri, 30 Aug 2024 17:53:06 +0900 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-new-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-new-version.yml b/.github/workflows/deploy-new-version.yml index 74e62c79..cd764327 100644 --- a/.github/workflows/deploy-new-version.yml +++ b/.github/workflows/deploy-new-version.yml @@ -85,7 +85,7 @@ jobs: - name: Get Updated App Version id: get-updated-version - uses: ./github/actions/get-app-version + uses: ./.github/actions/get-app-version - name: Create Git Tag run: |