From 7022899a974065a67648534748d2f07b0398bf1a Mon Sep 17 00:00:00 2001 From: malilex Date: Mon, 25 Mar 2024 11:00:51 +0300 Subject: [PATCH] build: Icon generation workflow was added. --- .github/scripts/extract_version.sh | 7 ++ .github/workflows/publish-icons.yml | 76 +++++++++++++++++++ .../kotlin/convention.auto-bump.gradle.kts | 13 ++++ .../src/main/kotlin/utils/AutoBump.kt | 43 +++++++++++ sdds-core/icons/build.gradle.kts | 1 + 5 files changed, 140 insertions(+) create mode 100644 .github/scripts/extract_version.sh create mode 100644 .github/workflows/publish-icons.yml create mode 100644 build-system/conventions/src/main/kotlin/convention.auto-bump.gradle.kts create mode 100644 build-system/conventions/src/main/kotlin/utils/AutoBump.kt diff --git a/.github/scripts/extract_version.sh b/.github/scripts/extract_version.sh new file mode 100644 index 00000000..6cf32637 --- /dev/null +++ b/.github/scripts/extract_version.sh @@ -0,0 +1,7 @@ + +MAJOR=`cat $1 | grep "versionMajor" | cut -d'=' -f2` +MINOR=`cat $1 | grep "versionMinor" | cut -d'=' -f2` +PATCH=`cat $1 | grep "versionPatch" | cut -d'=' -f2` +VER=$MAJOR.$MINOR.$PATCH +echo "release_name=$VER" >> $GITHUB_OUTPUT +echo "minor_version=$MINOR" >> $GITHUB_OUTPUT diff --git a/.github/workflows/publish-icons.yml b/.github/workflows/publish-icons.yml new file mode 100644 index 00000000..217b259e --- /dev/null +++ b/.github/workflows/publish-icons.yml @@ -0,0 +1,76 @@ +name: Update Icons Pack + +#on: +# repository_dispatch: +# types: [ plasma-released ] + +on: + pull_request: + branches: + - develop + +jobs: + icons: + runs-on: ubuntu-latest + + steps: + # делаем сheckout в текущем репозитория + - name: Checkout + uses: actions/checkout@v4 + with: + show-progress: false + path: current + + # делаем сheckout репозитория plasma + - name: Checkout to Plasma Web + uses: actions/checkout@v4 + with: + repository: salute-developers/plasma + ref: dev + show-progress: false + path: plasma + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version-file: 'plasma/.nvmrc' + + - name: Install plasma web project deps + run: | + cd plasma + npm ci + + - name: Generate android icons + run: | + cd plasma + npx lerna bootstrap --scope="@salutejs/plasma-icons" --ignore-scripts + npm run generate:android --prefix="packages/plasma-icons" + + - name: Extract current version + id: extract_version + working-directory: ./current + shell: bash + run: sh ./.github/scripts/extract_version.sh ./sdds-core/icons/gradle.properties + + - name: Create release branch + shell: bash + run: | + git checkout -b release/icons-${{steps.extract_branch.outputs.branch.release_name}} + + - name: Move generated icons to drawable folder + run: | + cp -r plasma/packages/plasma-icons/android-icons/. current/sdds-core/icons/src/main/res/drawable/ + ls current/android-icons + + - name: Create tag and release pull request + working-directory: ./current + shell: bash + run: | + TAG=icons-v${{steps.extract_branch.outputs.branch.release_name}} + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add ./sdds-core/icons/ + git commit -m "feat(sdds-acore/icons): New icons were added" + git tag -a $TAG -m "Release $TAG" + git push --set-upstream origin release/$TAG + git push origin $TAG diff --git a/build-system/conventions/src/main/kotlin/convention.auto-bump.gradle.kts b/build-system/conventions/src/main/kotlin/convention.auto-bump.gradle.kts new file mode 100644 index 00000000..379c50f8 --- /dev/null +++ b/build-system/conventions/src/main/kotlin/convention.auto-bump.gradle.kts @@ -0,0 +1,13 @@ +import utils.BumpScope +import utils.bumpVersion + +description = "Convention-плагин, который добавляет таску для автоинкремента версии" + +tasks.register("bump") { + val scope = when(properties["scope"]) { + "major" -> BumpScope.MAJOR + "patch" -> BumpScope.PATCH + else -> BumpScope.MINOR + } + project.bumpVersion(scope) +} \ No newline at end of file diff --git a/build-system/conventions/src/main/kotlin/utils/AutoBump.kt b/build-system/conventions/src/main/kotlin/utils/AutoBump.kt new file mode 100644 index 00000000..b10a275c --- /dev/null +++ b/build-system/conventions/src/main/kotlin/utils/AutoBump.kt @@ -0,0 +1,43 @@ +package utils + +import org.gradle.api.Project + +/** + * Область автоинкремента версии + * @author Малышев Александр on 22.03.2024 + */ +enum class BumpScope { + MAJOR, MINOR, PATCH +} + +/** + * Инкрементирует версию в указанном [scope]. + * Если [scope] == [BumpScope.MINOR], то versionMinor инкрементируется, + * а versionPatch становится равным 0. + * Если [scope] == [BumpScope.MAJOR], то versionMajor инкрементируется, + * * а versionMinor и versionPatch становятся равными 0. + */ +fun Project.bumpVersion(scope: BumpScope = BumpScope.MINOR) { + val major = properties.getOrDefault("versionMajor", 0).toString().toInt() + val minor = properties.getOrDefault("versionMinor", 0).toString().toInt() + val patch = properties.getOrDefault("versionPatch", 0).toString().toInt() + val updatedProps = file("gradle.properties") + val content = updatedProps.readText() + val newContent = when(scope) { + BumpScope.MAJOR -> { + content + .replace("versionMajor=\\d+".toRegex(), "versionMajor=${major + 1}") + .replace("versionMinor=\\d+".toRegex(), "versionMinor=0") + .replace("versionPatch=\\d+".toRegex(), "versionPatch=0") + } + BumpScope.MINOR -> { + content + .replace("versionMinor=\\d+".toRegex(), "versionMinor=${minor + 1}") + .replace("versionPatch=\\d+".toRegex(), "versionPatch=0") + } + BumpScope.PATCH -> content.replace("versionPatch=\\d+".toRegex(), "versionPatch=${patch + 1}") + } + updatedProps.writeText(newContent) +} + + diff --git a/sdds-core/icons/build.gradle.kts b/sdds-core/icons/build.gradle.kts index b098c517..998d1e4d 100644 --- a/sdds-core/icons/build.gradle.kts +++ b/sdds-core/icons/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("convention.android-lib") id("convention.maven-publish") + id("convention.auto-bump") } group = "sdds-core"