diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7526973..50624aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,31 +36,36 @@ jobs: cd notification-backend go test -v -run TestEncryption - # FIXME: Android build is broken, commenting out temporarily - # build-android: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 + build-android: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' - # - name: Set up JDK 17 - # uses: actions/setup-java@v3 - # with: - # java-version: '17' - # distribution: 'temurin' + - name: Setup Android SDK + uses: android-actions/setup-android@v3 - # - name: Setup Android SDK - # uses: android-actions/setup-android@v3 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-version: 8.13 - # - name: Setup Gradle - # uses: gradle/gradle-build-action@v2 - # with: - # gradle-version: 8.11 + - name: Create Firebase client config from secret + env: + FIREBASE_CLIENT_CONFIG: ${{ secrets.FIREBASE_CLIENT_CONFIG }} + run: | + echo "$FIREBASE_CLIENT_CONFIG" > demo-app/app/google-services.json - # - name: Build demo-app - # run: gradle -p demo-app --no-daemon build - # - # - name: Run Android unit tests - # run: gradle -p demo-app --no-daemon test + - name: Build demo-app + run: gradle -p demo-app --no-daemon build + + - name: Run Android unit tests + run: gradle -p demo-app --no-daemon test go-lint: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5724345..8b77405 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,8 @@ on: jobs: build-apk: runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout code uses: actions/checkout@v4 @@ -38,7 +40,13 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 with: - gradle-version: 8.4 + gradle-version: 8.13 + + - name: Create Firebase client config from secret + env: + FIREBASE_CLIENT_CONFIG: ${{ secrets.FIREBASE_CLIENT_CONFIG }} + run: | + echo "$FIREBASE_CLIENT_CONFIG" > demo-app/app/google-services.json - name: Build Release APK run: | @@ -75,11 +83,11 @@ jobs: cd demo-app/app/build/outputs/apk/release VERSION=${GITHUB_REF#refs/tags/} if [ -f "app-release-signed.apk" ]; then - mv app-release-signed.apk "minnotif-android-${VERSION}-signed.apk" - echo "APK_NAME=minnotif-android-${VERSION}-signed.apk" >> $GITHUB_ENV + mv app-release-signed.apk "remote-notify-demo-app-${VERSION}-signed.apk" + echo "APK_NAME=remote-notify-demo-app-${VERSION}-signed.apk" >> $GITHUB_ENV else - mv app-release-unsigned.apk "minnotif-android-${VERSION}-unsigned.apk" - echo "APK_NAME=minnotif-android-${VERSION}-unsigned.apk" >> $GITHUB_ENV + mv app-release-unsigned.apk "remote-notify-demo-app-${VERSION}-unsigned.apk" + echo "APK_NAME=remote-notify-demo-app-${VERSION}-unsigned.apk" >> $GITHUB_ENV fi - name: Create Release @@ -88,7 +96,7 @@ jobs: files: demo-app/app/build/outputs/apk/release/${{ env.APK_NAME }} name: Release ${{ github.ref_name }} body: | - ## 📱 Android APK Release ${{ github.ref_name }} + ## 📱 Remote Notification Demo App Release ${{ github.ref_name }} **Download and install:** 1. Download the APK file below @@ -101,7 +109,7 @@ jobs: - App-backend cannot decrypt stored tokens **Files:** - - `${{ env.APK_NAME }}` - Android application package + - `${{ env.APK_NAME }}` - Remote notification demo Android app --- @@ -116,72 +124,73 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Upload APK as artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: android-apk-${{ github.ref_name }} path: demo-app/app/build/outputs/apk/release/${{ env.APK_NAME }} retention-days: 90 - build-go-binaries: - runs-on: ubuntu-latest - strategy: - matrix: - goos: [linux, darwin, windows] - goarch: [amd64, arm64] - exclude: - - goos: windows - goarch: arm64 - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.21' - - - name: Build Go binaries - env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - run: | - VERSION=${GITHUB_REF#refs/tags/} - - # Build app-backend - cd app-backend - go build -ldflags "-X main.version=${VERSION}" -o ../bin/app-backend-${GOOS}-${GOARCH}${{ matrix.goos == 'windows' && '.exe' || '' }} . - - # Build notification-backend - cd ../notification-backend - go build -ldflags "-X main.version=${VERSION}" -o ../bin/notification-backend-${GOOS}-${GOARCH}${{ matrix.goos == 'windows' && '.exe' || '' }} . - - - name: Upload Go binaries - uses: actions/upload-artifact@v3 - with: - name: go-binaries-${{ matrix.goos }}-${{ matrix.goarch }} - path: bin/* - retention-days: 90 - - upload-go-binaries: - needs: build-go-binaries - runs-on: ubuntu-latest - steps: - - name: Download all artifacts - uses: actions/download-artifact@v3 - with: - path: artifacts - - - name: Prepare binaries for release - run: | - mkdir -p release-binaries - find artifacts -name "go-binaries-*" -type d | while read dir; do - cp "$dir"/* release-binaries/ 2>/dev/null || true - done - ls -la release-binaries/ - - - name: Upload Go binaries to release - uses: softprops/action-gh-release@v1 - with: - files: release-binaries/* - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Go binary builds commented out - Android APK only for now + # build-go-binaries: + # runs-on: ubuntu-latest + # strategy: + # matrix: + # goos: [linux, darwin, windows] + # goarch: [amd64, arm64] + # exclude: + # - goos: windows + # goarch: arm64 + # steps: + # - name: Checkout code + # uses: actions/checkout@v4 + # + # - name: Set up Go + # uses: actions/setup-go@v4 + # with: + # go-version: '1.21' + # + # - name: Build Go binaries + # env: + # GOOS: ${{ matrix.goos }} + # GOARCH: ${{ matrix.goarch }} + # run: | + # VERSION=${GITHUB_REF#refs/tags/} + # + # # Build app-backend + # cd app-backend + # go build -ldflags "-X main.version=${VERSION}" -o ../bin/app-backend-${GOOS}-${GOARCH}${{ matrix.goos == 'windows' && '.exe' || '' }} . + # + # # Build notification-backend + # cd ../notification-backend + # go build -ldflags "-X main.version=${VERSION}" -o ../bin/notification-backend-${GOOS}-${GOARCH}${{ matrix.goos == 'windows' && '.exe' || '' }} . + # + # - name: Upload Go binaries + # uses: actions/upload-artifact@v3 + # with: + # name: go-binaries-${{ matrix.goos }}-${{ matrix.goarch }} + # path: bin/* + # retention-days: 90 + # + # upload-go-binaries: + # needs: build-go-binaries + # runs-on: ubuntu-latest + # steps: + # - name: Download all artifacts + # uses: actions/download-artifact@v3 + # with: + # path: artifacts + # + # - name: Prepare binaries for release + # run: | + # mkdir -p release-binaries + # find artifacts -name "go-binaries-*" -type d | while read dir; do + # cp "$dir"/* release-binaries/ 2>/dev/null || true + # done + # ls -la release-binaries/ + # + # - name: Upload Go binaries to release + # uses: softprops/action-gh-release@v1 + # with: + # files: release-binaries/* + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/demo-app/app/src/main/java/org/nella/fcmapp/MainActivity.kt b/demo-app/app/src/main/java/org/nella/fcmapp/MainActivity.kt index 3fcf3b0..a7edf31 100644 --- a/demo-app/app/src/main/java/org/nella/fcmapp/MainActivity.kt +++ b/demo-app/app/src/main/java/org/nella/fcmapp/MainActivity.kt @@ -18,7 +18,7 @@ import java.security.KeyFactory import java.security.PublicKey import java.security.SecureRandom import java.security.spec.X509EncodedKeySpec -import java.util.Base64 +import android.util.Base64 import javax.crypto.Cipher import javax.crypto.KeyGenerator import javax.crypto.SecretKey @@ -213,7 +213,7 @@ class MainActivity : AppCompatActivity() { keyLengthBytes[3] = encryptedAesKey.size.toByte() val combined = iv + keyLengthBytes + encryptedAesKey + encryptedToken - return Base64.getEncoder().encodeToString(combined) + return Base64.encodeToString(combined, Base64.DEFAULT) } private fun loadPublicKey(): PublicKey { @@ -226,7 +226,7 @@ class MainActivity : AppCompatActivity() { .replace("\n", "") .replace("\r", "") - val keyBytes = Base64.getDecoder().decode(publicKeyBase64) + val keyBytes = Base64.decode(publicKeyBase64, Base64.DEFAULT) val keySpec = X509EncodedKeySpec(keyBytes) val keyFactory = KeyFactory.getInstance("RSA")