Skip to content

Commit

Permalink
更新Gradle CI脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
kosaka-bun committed Jun 4, 2024
1 parent d0938e8 commit 4577eef
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 45 deletions.
53 changes: 10 additions & 43 deletions .github/workflows/gradle_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Gradle CI

on:
push:
branches: [ master ]
branches: [ dev ]
pull_request:
branches: [ master ]
branches: [ dev ]

jobs:
build:
Expand All @@ -21,30 +21,10 @@ jobs:
# 通过预定义的包管理器之一管理的依赖项的快速设置缓存
# 它可以是maven、gradle或sbt之一
cache: 'gradle'
- name: Check project version
- name: Build with Gradle
run: |
chmod +x gradlew
# 读取当前gradle项目根模块的版本信息,检查版本号是否符合要求
check_version_out=$(./gradlew checkVersion)
echo -e "check_version_out:\n\n$check_version_out"
# 若版本号检测不通过,则阻止发布
if [ "$(echo "$check_version_out" | grep -i "results.passed=true")" == '' ]; then
echo 'Cannot publish development version!'
exit 10
fi
- name: Clone remote maven repository
run: |
# 将kosaka-bun/maven-repo的git仓库clone到项目根目录下
git clone ${{ secrets.REMOTE_MAVEN_REPO_URL }}
- id: gradle_build
name: Build with Gradle
run: |
# 打包,并发布到远程maven仓库在本地的一个拷贝当中
./gradlew -PremoteMavenRepositoryUrl=$(pwd)/maven-repo/repository publish
# 将maven-repo/repository目录打包,然后将tar移动到另一个单独的目录中
tar -zcf maven-repo.tar.gz maven-repo/repository
mkdir remote-maven-repo-copy
mv maven-repo.tar.gz remote-maven-repo-copy/
chmod +x ./scripts/*.sh
./scripts/build.sh ${{ secrets.REMOTE_MAVEN_REPO_URL }}
- name: Upload remote maven repository as artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -56,30 +36,17 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Download temporary maven repository
uses: actions/download-artifact@v4
with:
# 指定在之前的job当中,上传到Actions运行实例的Artifacts当中的目录所使用的名字
name: remote-maven-repo-copy
# 指定要将这一目录下的所有内容(即不包含目录本身)下载到哪个位置(以项目根目录为相对路径起始点)
path: remote-maven-repo-copy
- name: Clone remote maven repository
run: |
# 将kosaka-bun/maven-repo的git仓库clone到项目根目录下
git clone ${{ secrets.REMOTE_MAVEN_REPO_URL }}
- name: Merge maven repository and publish
run: |
# 解压maven-repo.tar.gz
cd remote-maven-repo-copy
tar -zxf maven-repo.tar.gz
cd ..
# 将[项目根目录]/remote-maven-repo-copy/maven-repo/repository下所有内容,复制到[项目根目录]/maven-repo/repository下
# 并替换已存在的内容
cp -rf remote-maven-repo-copy/maven-repo/repository/* maven-repo/repository/
# 进入名为maven-repo的git仓库,设置提交者信息,然后提交并推送
cd maven-repo/repository
git config --global user.name 'Kosaka Bun'
git config --global user.email '[email protected]'
git add .
git commit -m 'Update honoka-android-utils'
git push
chmod +x ./scripts/*.sh
./scripts/publish.sh ${{ secrets.REMOTE_MAVEN_REPO_URL }}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
alias(libs.plugins.kotlin) apply false
}

version = libs.versions.root.get()

allprojects {
group = "de.honoka.sdk"
}
Expand Down
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# project modules version
root = "1.1.0-dev"
aar = "1.1.0-dev"
java-patch = "1.0.0-dev"

# dependencies version
android-gradle-plugin = "8.0.0"
Expand All @@ -11,7 +10,7 @@ android-sdk-min = "26"
kotlin = "1.8.0"
kotlin-coroutines = "1.6.1"
ktor = "2.2.3"
honoka-kotlin-utils = "1.0.0-dev"
honoka-kotlin-utils = "1.0.1-dev"
honoka-framework-utils = "1.0.4"
lombok = "1.18.26"

Expand Down
32 changes: 32 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -e

cd $(dirname "$0")/..
PROJECT_PATH="$(pwd)"

chmod +x gradlew

# 读取当前gradle项目根模块的版本信息,检查版本号是否符合要求
check_version_of_projects_out=$(./gradlew checkVersionOfProjects)
echo -e "check_version_of_projects_out:\n\n$check_version_of_projects_out"
# 若版本号检测不通过,则添加开发版标记
if [ "$(echo "$check_version_of_projects_out" | grep -i "results.passed=true")" == '' ]; then
touch dev_flag.txt
fi

# 将kosaka-bun/maven-repo的git仓库clone到项目根目录下
git clone $1

# 打包,并发布到远程maven仓库在本地的一个拷贝当中
if [ -f dev_flag.txt ]; then
./gradlew -PremoteMavenRepositoryUrl=$PROJECT_PATH/maven-repo/repository/development \
-PisDevelopmentRepository=true \
publish
else
./gradlew -PremoteMavenRepositoryUrl=$PROJECT_PATH/maven-repo/repository/release publish
fi
# 将maven-repo/repository目录打包,然后将tar移动到另一个单独的目录中
tar -zcf maven-repo.tar.gz maven-repo/repository
mkdir remote-maven-repo-copy
mv maven-repo.tar.gz remote-maven-repo-copy/
24 changes: 24 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

cd $(dirname "$0")/..
PROJECT_PATH="$(pwd)"

# 将kosaka-bun/maven-repo的git仓库clone到项目根目录下
git clone $1

# 解压maven-repo.tar.gz
cd remote-maven-repo-copy
tar -zxf maven-repo.tar.gz
cd ..
# 将[项目根目录]/remote-maven-repo-copy/maven-repo/repository下所有内容,复制到[项目根目录]/maven-repo/repository下
# 并替换已存在的内容
cp -rf remote-maven-repo-copy/maven-repo/repository/* maven-repo/repository/
# 进入名为maven-repo的git仓库,设置提交者信息,然后提交并推送
cd maven-repo/repository
git config --global user.name 'Kosaka Bun'
git config --global user.email '[email protected]'
git add .
git commit -m 'Update honoka-android-utils'
git push

0 comments on commit 4577eef

Please sign in to comment.