Skip to content

Commit

Permalink
build: Icon generation workflow was added.
Browse files Browse the repository at this point in the history
  • Loading branch information
malilex committed Mar 25, 2024
1 parent ec5d743 commit d7ae89e
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/scripts/extract_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

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 $VER
echo "release_name=$VER" >> $GITHUB_OUTPUT
echo "minor_version=$MINOR" >> $GITHUB_OUTPUT
88 changes: 88 additions & 0 deletions .github/workflows/publish-icons.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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
fetch-depth: 0
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: |
PROPS=./sdds-core/icons/gradle.properties
MAJOR=`cat $PROPS | grep "versionMajor" | cut -d'=' -f2`
MINOR=`cat $PROPS | grep "versionMinor" | cut -d'=' -f2`
PATCH=`cat $PROPS | grep "versionPatch" | cut -d'=' -f2`
VER=$MAJOR.$MINOR.$PATCH
echo $VER
echo "release_name=$VER" >> $GITHUB_OUTPUT
echo "minor_version=$MINOR" >> $GITHUB_OUTPUT
- name: Create release branch
working-directory: ./current
shell: bash
run: |
git branch release/icons-v${{steps.extract_version.outputs.release_name}} develop
git checkout release/icons-v${{steps.extract_version.outputs.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_version.outputs.release_name}}
git config --local user.email "[email protected]"
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
gh pr create --base develop --head release/$TAG
Original file line number Diff line number Diff line change
@@ -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)
}
43 changes: 43 additions & 0 deletions build-system/conventions/src/main/kotlin/utils/AutoBump.kt
Original file line number Diff line number Diff line change
@@ -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)
}


1 change: 1 addition & 0 deletions sdds-core/icons/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("convention.android-lib")
id("convention.maven-publish")
id("convention.auto-bump")
}

group = "sdds-core"
Expand Down

0 comments on commit d7ae89e

Please sign in to comment.