fix: fix transaction record UI logic #228
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: Android CI/CD | ||
| on: | ||
| push: | ||
| branches: | ||
| - master # 触发 CI/CD 的分支 | ||
| pull_request: | ||
| branches: | ||
| - master # 监听到 PR 到 main 分支时触发 CI/CD | ||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest # 使用 Ubuntu 作为运行环境 | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v2 # 检出当前仓库代码 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 16 | ||
| - name: Install commitlint | ||
| run: | | ||
| npm install -g @commitlint/cli @commitlint/config-conventional | ||
| - name: Run commitlint | ||
| run: | | ||
| if [ "${GITHUB_SHA}" = "0000000000000000000000000000000000000000" ]; then | ||
| echo "commitlint from HEAD^" | ||
| npx commitlint -x @commitlint/config-conventional -f HEAD^ | ||
| else | ||
| echo "commitlint from ${GITHUB_SHA}" | ||
| npx commitlint -x @commitlint/config-conventional -f "${GITHUB_SHA}" | ||
| fi | ||
| build: | ||
| runs-on: ubuntu-latest # 使用 Ubuntu 作为运行环境 | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v3 # 检出当前仓库代码 | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'zulu' # 指定 Java 发行版 | ||
| - name: Set up Android SDK | ||
| uses: android-actions/setup-android@v2 | ||
| with: | ||
| api-level: 30 | ||
| build-tools: 30.0.3 | ||
| # 缓存 Gradle 依赖项 | ||
| - name: Cache Gradle packages | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ~/.gradle/caches | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-gradle- | ||
| - name: Get version information | ||
| id: version | ||
| run: | | ||
| VERSION_CODE=$(grep versionCode pos_android_studio_demo/pos_android_app/build.gradle | head -n 1 | sed 's/.*versionCode\s*\([0-9]\+\).*/\1/') | ||
| VERSION_NAME=$(grep versionName pos_android_studio_demo/pos_android_app/build.gradle | head -n 1 | sed 's/.*versionName\s*"\([^"]\+\)".*/\1/') | ||
| echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV | ||
| echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV | ||
| - name: Get commit message | ||
| id: commit | ||
| run: | | ||
| COMMIT_MESSAGE=$(git log -1 --pretty=%B) | ||
| COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE" | sed 's/^[0-9]\+\.[ ]*//g') | ||
| COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE" | tr -d '\n') | ||
| echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV | ||
| # 解码并保存 keystore 文件 | ||
| - name: Decode and Save Keystore | ||
| run: | | ||
| echo "${{ vars.KEYSTORE_FILE }}" | base64 -d > pos_android_studio_demo/app.keystore | ||
| - name: Build the release signed APK | ||
| run: | | ||
| cd pos_android_studio_demo | ||
| chmod +x ./gradlew | ||
| ./gradlew assembleRelease \ | ||
| -Pandroid.injected.signing.store.file=app.keystore \ | ||
| -Pandroid.injected.signing.store.password=${{ vars.KEYSTORE_PASSWORD }} \ | ||
| -Pandroid.injected.signing.key.alias=${{ vars.KEY_ALIAS }} \ | ||
| -Pandroid.injected.signing.key.password=${{ vars.KEY_PASSWORD }} | ||
| # 保存生成的 APK 文件 | ||
| - name: Upload APK Artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: pos_android_app-release | ||
| path: pos_android_studio_demo/pos_android_app/build/outputs/apk/release/pos_android_app-release.apk | ||
| - name: List APK files | ||
| run: ls -R pos_android_studio_demo/pos_android_app/build/outputs/apk/release # 列出 APK 文件,确保路径正确 | ||
| # 保存SDK 库文件 | ||
| - name: Upload SDK Artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: dspread-sdks | ||
| path: | | ||
| pos_android_studio_demo/pos_android_app/libs/dspread_pos_sdk_*.aar | ||
| pos_android_studio_demo/pos_android_app/libs/dspread_print_sdk-*.aar | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| needs: [build] # 依赖于 build 作业的成功 | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v3 | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: '18' | ||
| - name: Get version information | ||
| id: version | ||
| run: | | ||
| VERSION_CODE=$(grep versionCode pos_android_studio_demo/pos_android_app/build.gradle | head -n 1 | sed 's/.*versionCode\s*\([0-9]\+\).*/\1/') | ||
| VERSION_NAME=$(grep versionName pos_android_studio_demo/pos_android_app/build.gradle | head -n 1 | sed 's/.*versionName\s*"\([^"]\+\)".*/\1/') | ||
| echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV | ||
| echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV | ||
| echo "TAG_NAME=v$VERSION_NAME" >> $GITHUB_ENV | ||
| BUILD_ID="$VERSION_NAME-$VERSION_CODE-$(date +%Y%m%d)" | ||
| echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV | ||
| - name: Check if release already exists | ||
| id: check_release | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME" || echo "NOT_FOUND") | ||
| if [[ "$RESPONSE" != "NOT_FOUND" ]] && echo "$RESPONSE" | grep -q '"id":'; then | ||
| echo "Release $TAG_NAME already exists. Skipping release creation." | ||
| echo "RELEASE_EXISTS=true" >> $GITHUB_ENV | ||
| EXISTING_NAME=$(echo "$RESPONSE" | grep '"name"' | head -1 | cut -d'"' -f4) | ||
| echo "EXISTING_RELEASE_NAME=$EXISTING_NAME" >> $GITHUB_ENV | ||
| else | ||
| echo "Release $TAG_NAME does not exist. Proceeding with release creation." | ||
| echo "RELEASE_EXISTS=false" >> $GITHUB_ENV | ||
| fi | ||
| - name: Download APK Artifact | ||
| if: env.RELEASE_EXISTS == 'false' | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: pos_android_app-release | ||
| path: pos_android_studio_demo/pos_android_app/build/outputs/apk/release | ||
| - name: Verify APK file in release | ||
| if: env.RELEASE_EXISTS == 'false' | ||
| run: ls -R pos_android_studio_demo/pos_android_app/build/outputs/apk/release # 列出 APK 文件,确保路径正确 | ||
| - name: Verify SDK Files | ||
| if: env.RELEASE_EXISTS == 'false' | ||
| id: verify-sdk | ||
| run: | | ||
| POS_SDK=$(ls pos_android_studio_demo/pos_android_app/libs/dspread_pos_sdk_*.aar) | ||
| PRINT_SDK=$(ls pos_android_studio_demo/pos_android_app/libs/dspread_print_sdk-*.aar) | ||
| echo "POS_SDK=$POS_SDK" >> $GITHUB_OUTPUT | ||
| echo "PRINT_SDK=$PRINT_SDK" >> $GITHUB_OUTPUT | ||
| - name: Get commit message | ||
| if: env.RELEASE_EXISTS == 'false' | ||
| id: commit | ||
| run: | | ||
| COMMIT_MESSAGE=$(git log -1 --pretty=%B) | ||
| COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE" | sed 's/^[0-9]\+\.[ ]*//g') | ||
| COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE" | tr -d '\n') | ||
| echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV | ||
| - name: Create GitHub Release | ||
| if: env.RELEASE_EXISTS == 'false' | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| tag_name: ${{ env.TAG_NAME }} | ||
| name: v${{ env.VERSION_NAME }} | ||
| body: | | ||
| ${{ env.VERSION_NAME }} | ||
| **Changes:** | ||
| ${{ env.COMMIT_MESSAGE }} | ||
| draft: false | ||
| prerelease: false | ||
| files: | | ||
| pos_android_studio_demo/pos_android_app/build/outputs/apk/release/pos_android_app-release.apk | ||
| ${{ steps.verify-sdk.outputs.POS_SDK }} | ||
| ${{ steps.verify-sdk.outputs.PRINT_SDK }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Skip release creation | ||
| if: env.RELEASE_EXISTS == 'true' | ||
| run: | | ||
| echo "🚫 Release ${{ env.TAG_NAME }} already exists!" | ||
| echo "📋 Existing Release: ${{ env.EXISTING_RELEASE_NAME }}" | ||
| echo "💡 If you want to create a new release, please update versionCode and versionName in build.gradle" | ||
| deploy: | ||
| runs-on: ubuntu-latest # 使用 Ubuntu 作为运行环境 | ||
| needs: [build] # 部署依赖于构建作业成功 | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v2 | ||
| - name: Deploy to the server or another location | ||
| run: | | ||
| echo "Deploying APK or other artifacts" | ||
| # 可以根据需要替换为实际的部署步骤,例如上传到服务器或云平台等 | ||