iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 24
0

找到我們所需的 Actions (Marketplace)

總整理: https://gist.github.com/CS6/320ece2c01f9653b2225db28b7c8ca9f

昨天使用的都要沿用喔!

今天增加了
r0adkll/sign-android-release@v1
r0adkll/upload-google-play@v1

Sign Bundle (WIP)

- name: Sign AAB
  id: sign
  uses: r0adkll/sign-android-release@v1
  with:
    releaseDirectory: app/build/outputs/bundle/release
    signingKeyBase64: ${{ secrets.SIGNING_KEY }}
    alias: ${{ secrets.ALIAS }}
    keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
    keyPassword: ${{ secrets.KEY_PASSWORD }}

Generate an upload key and Keystore
https://developer.android.com/studio/publish/app-signing#generate-key
將 KeyStore file,轉換為 base64 ,並加到 GitHub 專案的設定中的 Secret

cat MyKeyStore  | base64 | pbcopy
#ios cat AppleID.p12 | base64 | pbcopy

也要ㄧ並將 Key 加到 GitHub 專案的設定中的 Secret

測試 Build (產生AAB APK)

gradle build bundleRelease

測試 Run

adb -s emulator-5554 install app/build/outputs/apk/release/app-release.apk

專案 /distribution/whatsnew/whatsnew-zh-TW

https://ithelp.ithome.com.tw/upload/images/20201007/20104220nrsYFiUKCc.png

** 記得最多只能輸入400 字元 **

<zh-TW>
HAHAHAHmapping.txtmapping.txt在這裡輸入或貼上 zh-TW 版的版本資訊
MAX 400 字元
</zh-TW>

接者,建立你專案的Actions(workflows)

在GitHub上的存儲庫中,找到在.github/workflows名為的目錄中創建一個新文件 react-native-android-Release-Store.yml。
將以下YAML內容複製到 react-native-android-Release-Store.yml 文件中。
注意:如果您的默認分支不是main,請更新的值 DEFAULT_BRANCH 以匹配存儲庫的默認分支名稱。

name: Github-Actions-react-native-android-Release-Store

# on: [push, pull_request]
on:
  push:
    branches: [  Release-Store  ]
    tags:
      - 'Store*'
  pull_request:
    branches: [  Release-Store  ]
jobs:
  build:
    runs-on: ubuntu-latest
    container: reactnativecommunity/react-native-android
    steps:
    - name: "#️⃣ Generate Build Number"
      id: buildnumber
      uses: einaregilsson/build-number@v2
      with:
        token: ${{ secrets.ACTION_TEST }}
    - name: "#️⃣ Generate Build Number store"
      id: buildnumber_store
      uses: einaregilsson/build-number@v2
      with:
        token: ${{ secrets.ACTION_TEST }}
        prefix: store
    - name: Print new build number
      run: |
        echo "Build number is $BUILD_NUMBER"
        echo "Build number is $buildnumber" ${{ steps.buildnumber.outputs.build_number }}
        echo "Build number is $buildnumber_store" ${{ steps.buildnumber.outputs.buildnumber_store }}
        echo  $BUILD_NUMBER
    - uses: actions/checkout@v2
    - name: Envinfo
      run: npx envinfo
    - name: Build application
      run: |
        yarn install && cd android && chmod +x gradlew && ./gradlew build bundleRelease 
        du -shc `find . -regex '.+\.\(apk\|aab\)$'`
#      run: yarn install && cd android && chmod +x gradlew && ./gradlew assembleRelease
      
      
#       ./gradlew build bundleRelease
#         du -shc `find . -regex '.+\.\(apk\|aab\)$'`
      
      
    #Prepare Release
      
    - name: Prepare Release
      id: prepare_release
#       if: contains(github.ref, 'tags/')
      run: |
        APK_PATH=`find . -name '*.apk' | grep release`
        echo ::set-output name=apk_path::$APK_PATH
        APK_NAME=`basename $APK_PATH`
        echo ::set-output name=apk_name::$APK_NAME
        BUNDLE_PATH=`find . -name '*.aab' | grep release | grep -v intermediates`
        echo ::set-output name=bundle_path::$BUNDLE_PATH
        BUNDLE_NAME=`basename $BUNDLE_PATH`
        echo ::set-output name=bundle_name::$BUNDLE_NAME
#        選用
#        TAG_NAME=`echo $GITHUB_REF | cut -d / -f3`
#        echo ::set-output name=tag_name::$TAG_NAME
#        PACKAGE_NAME=`./tools/aapt2 dump packagename $APK_PATH`
#        echo ::set-output name=package_name::$PACKAGE_NAME
    - name: Print build PATH
      run: |
        echo ${{steps.prepare_release.outputs.bundle_path}}
        echo ${{steps.prepare_release.outputs.apk_name}}
        echo ${{steps.prepare_release.outputs.bundle_path}}/${{steps.prepare_release.outputs.apk_name}}
#       簽署 BBA
    - name: Sign AAB
      id: sign
      uses: r0adkll/sign-android-release@v1
      with:
        releaseDirectory: ./android/app/build/outputs/bundle/release/
        signingKeyBase64: ${{ secrets.SIGNING_KEY }}
        alias: ${{ secrets.ALIAS }}
        keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
        keyPassword: ${{ secrets.KEY_PASSWORD }}

    #Uploads
    - name: Upload Artifact
      if: steps.prepare_release.outputs.apk_path
      uses: actions/upload-artifact@v1
      with:
        name: app-release.apk
        path: android/app/build/outputs/apk/release/     
    #Uploads
    - name: Upload Artifact
      if: steps.prepare_release.outputs.bundle_path
      uses: actions/upload-artifact@v1
      with:
        name: app-release.aab
        path: android/app/build/outputs/bundle/release/  
        
    - name: Create GitHub release
      id: create_release
#       if: steps.version_check.outputs.changed == 'true'
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.ACTION_TEST }}
      with:
        tag_name: V-${{ steps.buildnumber.outputs.build_number }}
        release_name: V-${{ steps.buildnumber.outputs.build_number }}
        body: |
          ![release!](https://i.giphy.com/media/lPulaaB9lDMnGZiivs/source.gif)
          # Changelog
          Release type: ${{ steps.buildnumber.outputs.build_number }}
        prerelease: true


    - name: Upload APK Asset
      if: steps.create_release.outputs.upload_url && steps.prepare_release.outputs.apk_path && steps.prepare_release.outputs.apk_name
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      with:
        upload_url: ${{steps.create_release.outputs.upload_url}}
        asset_path: ${{steps.prepare_release.outputs.apk_path}}
        asset_name: ${{steps.prepare_release.outputs.apk_name}}
        asset_content_type: application/vnd.android.package-archive
#       選用 BBA
    - name: Upload Bundle Asset
      if: steps.create_release.outputs.upload_url && steps.prepare_release.outputs.bundle_path && steps.prepare_release.outputs.bundle_name
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      with:
        upload_url: ${{steps.create_release.outputs.upload_url}}
        asset_path: ${{steps.prepare_release.outputs.bundle_path}}
        asset_name: ${{steps.prepare_release.outputs.bundle_name}}
        asset_content_type: application/octet-stream
#       上傳 BBA
    - name: Upload Android Release to Play Store (internal track publishing is default)
      uses: r0adkll/upload-google-play@v1
      with:
        serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
        packageName: dev.dayuan.rn3d
        releaseFile: ${{steps.prepare_release.outputs.bundle_path}}
        track: internal
        whatsNewDirectory: distribution/whatsnew


        

測試他,你會看到問題出現了

可這時我們就會遇到問題:
APP的 VersionCode & VersionName 不可以跟前版一樣
找不到 APP ID Package not found: XX.***.

https://ithelp.ithome.com.tw/upload/images/20201008/20104220pSZgvAhiZZ.png


上一篇
[Day:22] GitHub Actions 懶人部署-Android 打包入門
下一篇
[Day:24] GitHub Actions 懶人部署-Android 發布上架2 (自動版號的部分晚點會更新,不要急)
系列文
ReactNative 懶人開發之路,薪水小偷練成日記(X31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言