Improve versioning in CI workflow and update versionCode #128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build & Release UnicodeFontSet Module | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - '[vV]*' | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| id-token: write | |
| env: | |
| MODULE_DIR: module | |
| MODULE_PROP: module/module.prop | |
| MODULE_BIN_DIR: module/bin | |
| FONT_DIR: module/system/fonts | |
| UPDATE_BIN: module/META-INF/com/google/android/update-binary | |
| BUILD_DIR: build | |
| CLEANER_DIR: tools/font-cmap-cleaner | |
| UPX_VERSION: 5.1.0 | |
| NDK_VERSION: 29.0.14206865 | |
| jobs: | |
| build: | |
| name: Build ZIP Artifact — ${{ matrix.variant.suffix }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| variant: | |
| - name: "colrv1" | |
| emoji_url: "https://github.com/googlefonts/noto-emoji/raw/main/fonts/Noto-COLRv1.ttf" | |
| zip_name: "UnicodeFontSet-COLRv1-module.zip" | |
| suffix: "COLRv1 (Android 12L+)" | |
| description: "COLRv1 vector emoji" | |
| update_json: "https://github.com/Losketch/UnicodeFontSet-magisk-module/raw/main/update-colrv1.json" | |
| update_json_nightly: "https://github.com/Losketch/UnicodeFontSet-magisk-module/releases/download/nightly/update-nightly-colrv1.json" | |
| - name: "cbdt" | |
| emoji_url: "https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf" | |
| zip_name: "UnicodeFontSet-CBDT-module.zip" | |
| suffix: "CBDT (Android 5.0+)" | |
| description: "CBDT bitmap emoji" | |
| update_json: "https://github.com/Losketch/UnicodeFontSet-magisk-module/raw/main/update-cbdt.json" | |
| update_json_nightly: "https://github.com/Losketch/UnicodeFontSet-magisk-module/releases/download/nightly/update-nightly-cbdt.json" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Reset module.prop (avoid matrix pollution) | |
| run: | | |
| git checkout -- ${{ env.MODULE_PROP }} | |
| - name: Create directories | |
| run: | | |
| mkdir -p "${{ env.FONT_DIR }}" "${{ env.BUILD_DIR }}" "$(dirname "${{ env.UPDATE_BIN }}")" | |
| - name: Download fonts & scripts | |
| run: | | |
| set -e | |
| TMP_DIR=$(mktemp -d) | |
| echo "Using temp dir: $TMP_DIR" | |
| CSS_FILE="$TMP_DIR/fonts.css" | |
| FONT_FILE="$TMP_DIR/NotoEmoji-Regular.ttf" | |
| curl -fsSL \ | |
| -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \ | |
| "https://fonts.googleapis.com/css2?family=Noto+Emoji" \ | |
| -o "$CSS_FILE" | |
| FONT_URL=$(grep -o 'https://[^)]*\.ttf' "$CSS_FILE" | head -n 1) | |
| if [ -z "$FONT_URL" ]; then | |
| echo "Failed to extract TTF URL from Google Fonts CSS" >&2 | |
| exit 1 | |
| fi | |
| curl -fsSL "$FONT_URL" -o "$FONT_FILE" | |
| cp "$FONT_FILE" "${{ env.FONT_DIR }}/NotoEmoji-Regular.ttf" | |
| rm -rf "$TMP_DIR" | |
| declare -A files=( | |
| [NotoColorEmoji.ttf]=${{ matrix.variant.emoji_url }} | |
| [SourceHanSansSC-Regular.otf]=https://github.com/adobe-fonts/source-han-sans/raw/release/OTF/SimplifiedChinese/SourceHanSansSC-Regular.otf | |
| [NotoUnicode.otf]=https://github.com/MY1L/Unicode/releases/download/NotoUni7/NotoUnicode-7.3.otf | |
| [NewGardiner.ttf]=https://github.com/Mercury13/unicodia/raw/main/Fonts/NewGardiner.ttf | |
| [UnicodiaDaarage.otf]=https://github.com/Mercury13/unicodia/raw/main/Fonts/UnicodiaDaarage.otf | |
| [UnicodiaSesh.ttf]=https://github.com/Mercury13/unicodia/raw/main/Fonts/UnicodiaSesh.ttf | |
| [PlangothicP1-Regular.otf]=https://github.com/Fitzgerald-Porthmouth-Koenigsegg/Plangothic_Project/raw/build/fonts/otf/PlangothicP1-Regular.otf | |
| [PlangothicP2-Regular.otf]=https://github.com/Fitzgerald-Porthmouth-Koenigsegg/Plangothic_Project/raw/build/fonts/otf/PlangothicP2-Regular.otf | |
| [KreativeSquare.ttf]=https://github.com/kreativekorp/open-relay/raw/master/KreativeSquare/KreativeSquare.ttf | |
| [LastResort-Regular.ttf]=https://github.com/unicode-org/last-resort-font/releases/latest/download/LastResort-Regular.ttf | |
| ) | |
| for name in "${!files[@]}"; do | |
| wget --tries=5 -q "${files[$name]}" -O "${{ env.FONT_DIR }}/$name" | |
| done | |
| wget --tries=5 -q https://github.com/topjohnwu/Magisk/raw/master/scripts/module_installer.sh \ | |
| -O "${{ env.UPDATE_BIN }}" | |
| - name: Update module.prop for variant | |
| run: | | |
| sed -i "s|^updateJson=.*|updateJson=${{ matrix.variant.update_json }}|" ${{ env.MODULE_PROP }} | |
| - name: Update versionCode for Nightly Builds | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| VERSION_DATE=$(date +%Y%m%d) | |
| BUILD_NUM=${{ github.run_number }} | |
| VERSION_CODE="${VERSION_DATE}${BUILD_NUM}" | |
| awk -v date="$VERSION_DATE" -v num="$BUILD_NUM" -v sha="${GITHUB_SHA:0:7}" ' | |
| /^version=/ {print "version=" $0 "." date "." num " [" sha "-Nightly-COLRv1]"; next} | |
| /^versionCode=/ {print "versionCode=" date num; next} | |
| {print} | |
| ' ${{ env.MODULE_PROP }} > ${{ env.MODULE_PROP }}.tmp && mv ${{ env.MODULE_PROP }}.tmp ${{ env.MODULE_PROP }} | |
| sed -i "s|^updateJson=.*|updateJson=${{ matrix.variant.update_json_nightly }}|" ${{ env.MODULE_PROP }} | |
| - name: Update version for Release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: | | |
| VERSION_DATE=$(date +%Y%m%d) | |
| BUILD_NUM=${{ github.run_number }} | |
| VERSION_CODE="${VERSION_DATE}${BUILD_NUM}" | |
| awk -v date="$VERSION_DATE" -v num="$BUILD_NUM" ' | |
| /^version=/ {print "version=" $0 "." date "." num " [COLRv1]"; next} | |
| /^versionCode=/ {print "versionCode=" date num; next} | |
| {print} | |
| ' ${{ env.MODULE_PROP }} > ${{ env.MODULE_PROP }}.tmp && mv ${{ env.MODULE_PROP }}.tmp ${{ env.MODULE_PROP }} | |
| - name: Setup Rust toolchain | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: stable | |
| - name: Cache cargo | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| ${{ env.CLEANER_DIR }}/target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('tools/font-cmap-cleaner/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Install cargo-ndk | |
| run: | | |
| if ! command -v cargo-ndk >/dev/null; then | |
| cargo install cargo-ndk | |
| fi | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| - name: Cache Android NDK | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.ANDROID_SDK_ROOT }}/ndk/${{ env.NDK_VERSION }} | |
| key: android-ndk-${{ env.NDK_VERSION }} | |
| - name: Install Android NDK | |
| run: | | |
| sdkmanager "ndk;${{ env.NDK_VERSION }}" "build-tools;34.0.0" "platforms;android-34" | |
| echo "ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/${{ env.NDK_VERSION }}" >> $GITHUB_ENV | |
| - name: Add Rust Android targets | |
| run: | | |
| rustup target add \ | |
| aarch64-linux-android \ | |
| armv7-linux-androideabi \ | |
| i686-linux-android \ | |
| x86_64-linux-android | |
| - name: Cache UPX | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/upx-${{ env.UPX_VERSION }}-amd64_linux | |
| key: upx-${{ env.UPX_VERSION }} | |
| - name: Install UPX | |
| run: | | |
| if ! command -v upx >/dev/null; then | |
| cd /tmp | |
| wget -q https://github.com/upx/upx/releases/download/v${{ env.UPX_VERSION }}/upx-${{ env.UPX_VERSION }}-amd64_linux.tar.xz | |
| tar -xf upx-${{ env.UPX_VERSION }}-amd64_linux.tar.xz | |
| sudo mv upx-${{ env.UPX_VERSION }}-amd64_linux/upx /usr/local/bin/ | |
| cd - | |
| fi | |
| upx --version | |
| - name: Build font-cmap-tool for Android | |
| run: | | |
| cd ${{ env.CLEANER_DIR }} | |
| cargo ndk \ | |
| -t arm64-v8a \ | |
| -t armeabi-v7a \ | |
| -t x86 \ | |
| -t x86_64 \ | |
| build --release | |
| mkdir -p ../../${{ env.MODULE_BIN_DIR }} | |
| declare -A TARGETS=( | |
| [aarch64-linux-android]=arm64-v8a | |
| [armv7-linux-androideabi]=armeabi-v7a | |
| [i686-linux-android]=x86 | |
| [x86_64-linux-android]=x86_64 | |
| ) | |
| for target in "${!TARGETS[@]}"; do | |
| bin="target/$target/release/font-cmap-tool" | |
| out="../../${{ env.MODULE_BIN_DIR }}/font-cmap-tool-${TARGETS[$target]}" | |
| upx --best --lzma "$bin" || true | |
| cp "$bin" "$out" | |
| done | |
| cd ../.. | |
| - name: Copy font-cmap-cleaner whitelist | |
| run: | | |
| if [ -f ${{ env.CLEANER_DIR }}/whitelist.txt ]; then | |
| cp ${{ env.CLEANER_DIR }}/whitelist.txt ${{ env.MODULE_DIR }}/config/whitelist.txt | |
| else | |
| echo "whitelist.txt not found!" >&2 | |
| exit 1 | |
| fi | |
| cp LICENSE ${{ env.MODULE_DIR }}/LICENSE | |
| cp README.md ${{ env.MODULE_DIR }}/README.md | |
| cp README.en.md ${{ env.MODULE_DIR }}/README.en.md | |
| - name: Package ZIP & compute checksum | |
| run: | | |
| cd "${{ env.MODULE_DIR }}" | |
| zip -9 -r "../${{ matrix.variant.zip_name }}" . | |
| - name: Collect artifacts | |
| run: | | |
| mv "${{ env.MODULE_DIR }}/../${{ matrix.variant.zip_name }}" "${{ env.BUILD_DIR }}/" | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: module-artifacts-${{ matrix.variant.name }} | |
| path: ${{ env.BUILD_DIR }} | |
| release: | |
| name: 正式 Release | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download COLRv1 artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: module-artifacts-colrv1 | |
| path: ./artifacts | |
| - name: Download CBDT artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: module-artifacts-cbdt | |
| path: ./artifacts | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: UFS-Magisk ${{ github.ref_name }} | |
| files: | | |
| ./artifacts/*.zip | |
| draft: false | |
| prerelease: false | |
| nightly: | |
| name: Nightly Release | |
| needs: build | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Download COLRv1 artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: module-artifacts-colrv1 | |
| path: ./artifacts | |
| - name: Download CBDT artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: module-artifacts-cbdt | |
| path: ./artifacts | |
| - name: Get commits since last release | |
| id: commits | |
| run: | | |
| LAST_TAG=$(git describe --tags --abbrev=0 --exclude='*nightly*' --match='[vV]*' 2>/dev/null || echo "") | |
| if [ -n "$LAST_TAG" ]; then | |
| echo "Comparing against tag: $LAST_TAG" | |
| RANGE="${LAST_TAG}..HEAD" | |
| else | |
| echo "No previous release tag found, showing recent commits." | |
| RANGE="-10" | |
| fi | |
| COMMITS=$(git log $RANGE --pretty=format:"- %h: %s (%an)%n%b" | \ | |
| awk ' | |
| match($0, /^- [0-9a-f]+:/) { | |
| if (NR != 1) print ""; | |
| print $0; | |
| next | |
| } | |
| { | |
| if (length($0) > 0) | |
| printf " > %s\n", $0; | |
| else | |
| print " >"; | |
| }' | |
| ) | |
| { | |
| echo 'COMMITS<<EOF' | |
| echo "$COMMITS" | |
| echo 'EOF' | |
| } >> $GITHUB_OUTPUT | |
| - name: Generate nightly update.json files | |
| run: | | |
| VERSION_DATE=$(date +%Y%m%d) | |
| BUILD_NUM=${{ github.run_number }} | |
| VERSION_CODE="${VERSION_DATE}${BUILD_NUM}" | |
| cat > changelog.md << EOF | |
| # Nightly Build Changelog | |
| ## Changes | |
| ${{ steps.commits.outputs.COMMITS }} | |
| Built from commit: ${{ github.sha }} | |
| EOF | |
| COLR_VERSION=$(grep '^version=' ${{ env.MODULE_PROP }} | cut -d= -f2- | sed 's/ \[.*\]//') | |
| CBDT_VERSION="$COLR_VERSION" | |
| cat > update-nightly-colrv1.json << EOF | |
| { | |
| "version": "${COLR_VERSION}.${VERSION_DATE}.${BUILD_NUM} [${GITHUB_SHA:0:7}-Nightly-COLRv1]", | |
| "versionCode": ${VERSION_CODE}, | |
| "zipUrl": "https://github.com/Losketch/UnicodeFontSet-magisk-module/releases/download/nightly/UnicodeFontSet-COLRv1-module.zip", | |
| "changelog": "https://github.com/Losketch/UnicodeFontSet-magisk-module/releases/download/nightly/changelog.md" | |
| } | |
| EOF | |
| cat > update-nightly-cbdt.json << EOF | |
| { | |
| "version": "${CBDT_VERSION}.${VERSION_DATE}.${BUILD_NUM} [${GITHUB_SHA:0:7}-Nightly-CBDT]", | |
| "versionCode": ${VERSION_CODE}, | |
| "zipUrl": "https://github.com/Losketch/UnicodeFontSet-magisk-module/releases/download/nightly/UnicodeFontSet-CBDT-module.zip", | |
| "changelog": "https://github.com/Losketch/UnicodeFontSet-magisk-module/releases/download/nightly/changelog.md" | |
| } | |
| EOF | |
| - name: Delete existing nightly release | |
| run: | | |
| set -x | |
| gh release delete nightly --yes -R ${{ github.repository }} || true | |
| git push --delete origin nightly || true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate timestamp | |
| id: timestamp | |
| run: echo "timestamp=$(date +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_OUTPUT | |
| - name: Create Nightly Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: nightly | |
| name: Nightly Build ${{ steps.timestamp.outputs.timestamp }} | |
| body: | | |
| ## Variants | |
| - **COLRv1** | |
| - Format: Vector | |
| - Features: Lossless scaling, supports any resolution, fast rendering | |
| - Compatibility: Android 12L + (requires built-in COLRv1 renderer) | |
| - Size: Typically smaller than bitmap, faster to transfer and load | |
| - **CBDT** | |
| - Format: Bitmap | |
| - Features: Traditional NotoColorEmoji.ttf, ensures compatibility on older devices | |
| - Compatibility: Android 5.0 + | |
| - Drawback: May appear pixelated when scaled, slower to load | |
| ### Key Differences | |
| | Feature | COLRv1 | CBDT | | |
| |---|---|---| | |
| | Data Type | Vector | Bitmap | | |
| | Scaling | Lossless, any resolution | May pixelate when enlarged | | |
| | Load & Render | Faster (usually smaller file size) | Slower (larger file size) | | |
| | Device Support | Android 12L + | Android 5.0 + | | |
| ## Commits | |
| ${{ steps.commits.outputs.COMMITS }} | |
| files: | | |
| ./artifacts/*.zip | |
| update-nightly-colrv1.json | |
| update-nightly-cbdt.json | |
| changelog.md | |
| prerelease: true | |
| make_latest: false |