Skip to content

Commit

Permalink
Update watermark checking logic (cocos#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed May 26, 2023
1 parent 99f0090 commit 1462892
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/native-renderservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ jobs:
echo "RENDER_SERVICE_VERSION=${new_version}" >> $GITHUB_ENV
echo "######### old version: ${old_version} --> new version: ${new_version}"
- name: Check BUILD_BRANCH against PR base branch
- name: Check SHOW_WATERMARK against PR base branch
if: github.event_name != 'release'
shell: bash
run: |
cd $GITHUB_WORKSPACE/native/render-service
# Read BUILD_BRANCH value from gradle.properties
BUILD_BRANCH=$(grep "BUILD_BRANCH" gradle.properties | cut -d'=' -f2)
# Read SHOW_WATERMARK value from gradle.properties
SHOW_WATERMARK=$(grep "SHOW_WATERMARK" gradle.properties | cut -d'=' -f2)
# Extract the base branch name from GITHUB_REF (refs/pull/:prNumber/merge -> baseBranchName)
# BASE_BRANCH_NAME=$(echo $GITHUB_REF | cut -d'/' -f3)
if [ -n "${{github.base_ref}}" ]; then
Expand All @@ -84,9 +84,15 @@ jobs:
BASE_BRANCH_NAME=$(echo $GITHUB_REF | cut -d'/' -f3)
fi
echo "${GITHUB_HEAD_REF} -> ${GITHUB_REF} -> ${{github.base_ref}} => ${BASE_BRANCH_NAME}"
if [[ "$BUILD_BRANCH" != "$BASE_BRANCH_NAME" ]]; then
echo "$BUILD_BRANCH / $BASE_BRANCH_NAME"
echo "Error: BUILD_BRANCH in gradle.properties does not match the base branch of the Pull Request"
if [[ "$BASE_BRANCH_NAME" == "main"* && "$SHOW_WATERMARK" != "false" ]]; then
echo "$SHOW_WATERMARK / $BASE_BRANCH_NAME"
echo "Error: SHOW_WATERMARK in gradle.properties should be false in main branch"
exit 1
fi
if [[ "$BASE_BRANCH_NAME" != "main"* && "$SHOW_WATERMARK" == "false" ]]; then
echo "$SHOW_WATERMARK / $BASE_BRANCH_NAME"
echo "Error: SHOW_WATERMARK in gradle.properties should be true in dev branch"
exit 1
fi
Expand Down
4 changes: 4 additions & 0 deletions native/render-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.8.18

- [refine] 修改水印显示与校验的逻辑 #52

# 0.8.17

- [break] 重构 CocosRemoteRenderClient.configureRenderService 的第一个参数,由 serviceName 调整为 serviceFullClassName,直接指定服务类的完整路径 #30
Expand Down
2 changes: 1 addition & 1 deletion native/render-service/client-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ android {

buildTypes.each {
it.buildConfigField "String", 'VERSION', "\"${VERSION}\""
it.buildConfigField 'String', 'BUILD_BRANCH', "\"${BUILD_BRANCH}\""
it.buildConfigField "String", 'SHOW_WATERMARK', "\"${SHOW_WATERMARK}\""
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TextureRenderer implements Renderer
private final AtomicBoolean mIsHardwareBufferUpdated= new AtomicBoolean(false);

private boolean mIsAlphaEnabled = false;
private Boolean mIsReleaseBuild;

private Map<Integer, Integer> mTextureFilterMap;

Expand Down Expand Up @@ -133,7 +134,7 @@ public void setup()

createTexture();

if(notReleaseBuild()) {
if (notReleaseBuild()) {
createWatermark();
}

Expand Down Expand Up @@ -277,12 +278,14 @@ private void destroyTexture() {
}

private boolean notReleaseBuild() {
return !BuildConfig.BUILD_BRANCH.equals("main");
if (mIsReleaseBuild == null) {
mIsReleaseBuild = BuildConfig.SHOW_WATERMARK.equals("false");
}
return !mIsReleaseBuild;
}

private void createWatermark() {

String text = "Branch: " + BuildConfig.BUILD_BRANCH + ", Version: "+ BuildConfig.VERSION;
String text = "[Dev] Version: "+ BuildConfig.VERSION;
Paint paint = new Paint();
paint.setTextSize(30);
paint.setStyle(Paint.Style.STROKE);
Expand Down
4 changes: 2 additions & 2 deletions native/render-service/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ android.injected.testOnly=false

android.native.buildOutput=verbose

VERSION=0.8.17
VERSION=0.8.18

BUILD_BRANCH=dev
SHOW_WATERMARK=true

NDK_VERSION=21.4.7075529

Expand Down

0 comments on commit 1462892

Please sign in to comment.