From 35361ab7d18cc9aa8a5975aed18147f4194f941c Mon Sep 17 00:00:00 2001 From: razinj Date: Tue, 25 Jun 2024 02:32:01 +0200 Subject: [PATCH] feat: improve workflows --- .github/workflows/build.yml | 96 +++++++----------------------- .github/workflows/code-style.yml | 6 +- .github/workflows/common-build.yml | 58 ++++++++++++++++++ .github/workflows/release.yml | 93 +++-------------------------- .github/workflows/test.yml | 15 ++--- 5 files changed, 100 insertions(+), 168 deletions(-) create mode 100644 .github/workflows/common-build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6eca6cd..33971c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,84 +1,32 @@ -name: Build +name: build -on: [push] +on: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - gradle: + prepare-artifacts: + uses: ./.github/workflows/common-build.yml + upload-artifacts: runs-on: ubuntu-latest + needs: prepare-artifacts steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Use Node.js 18 - uses: actions/setup-node@v4 - with: - node-version: "18.x" - - - name: Install Node.js Dependencies - run: npm ci - - - name: Use Java 17 - uses: actions/setup-java@v4 - with: - java-version: "17" - distribution: "microsoft" - - - name: Setup Android SDK - uses: android-actions/setup-android@v3 - - - name: Decode and save the keystore file - run: | - # Upload store file was encoded: base64 -i upload.keystore -o ~/upload.keystore.base64 - echo ${{ secrets.CONTEXT_LAUNCHER_UPLOAD_STORE_FILE }} | base64 --decode > $GITHUB_WORKSPACE/android/app/upload.keystore - - - name: Prepare local.properties file - run: | - # Since the password contains a dollar sign ($) I had to encode it and decode it here. - STORE_PASSWORD=$(echo "${{ secrets.CONTEXT_LAUNCHER_UPLOAD_STORE_PASSWORD_BASE64 }}" | base64 --decode) - KEY_PASSWORD=$(echo "${{ secrets.CONTEXT_LAUNCHER_UPLOAD_KEY_PASSWORD_BASE64 }}" | base64 --decode) - echo "sdk.dir=$ANDROID_SDK_ROOT" > $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_STORE_FILE=$GITHUB_WORKSPACE/android/app/upload.keystore" >> $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_STORE_PASSWORD=$STORE_PASSWORD" >> $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_KEY_ALIAS=${{ secrets.CONTEXT_LAUNCHER_UPLOAD_KEY_ALIAS }}" >> $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_KEY_PASSWORD=$KEY_PASSWORD" >> $GITHUB_WORKSPACE/android/local.properties - - - name: Build - working-directory: ./android - run: ./gradlew --no-daemon build - - # Build artifacts - - name: Build Debug - APK - working-directory: ./android - run: ./gradlew --no-daemon assembleDebug - - - name: Build Release - APK - working-directory: ./android - run: ./gradlew --no-daemon assembleRelease - - - name: Build Release - AAB - working-directory: ./android - run: ./gradlew --no-daemon bundleRelease - - # Upload built artifacts - - name: Set short Git commit SHA - run: | - short_sha=$(git rev-parse --short ${{ github.sha }}) - echo "COMMIT_SHORT_SHA=$short_sha" >> $GITHUB_ENV - - - name: Upload Debug - APK - uses: actions/upload-artifact@v4 - with: - name: ${{ env.COMMIT_SHORT_SHA }}-context-launcher-debug-apks - path: android/app/build/outputs/apk/debug/*.apk - - - name: Upload Release - APK - uses: actions/upload-artifact@v4 - with: - name: ${{ env.COMMIT_SHORT_SHA }}-context-launcher-release-apks - path: android/app/build/outputs/apk/release/*.apk - - - name: Upload Release - AAB + - name: Upload Debug & Release Binaries uses: actions/upload-artifact@v4 with: - name: ${{ env.COMMIT_SHORT_SHA }}-context-launcher-release-aabs - path: android/app/build/outputs/bundle/release/*.aab + name: context-launcher-debug-and-release-apk-and-aab + path: | + android/app/build/outputs/apk/debug/*.apk + android/app/build/outputs/apk/release/*.apk + android/app/build/outputs/bundle/release/*.aab diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index fedd9dc..3acca76 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -1,7 +1,11 @@ -name: Code Style +name: code-style on: [push] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: check-formatting: runs-on: ubuntu-latest diff --git a/.github/workflows/common-build.yml b/.github/workflows/common-build.yml new file mode 100644 index 0000000..a8d9e76 --- /dev/null +++ b/.github/workflows/common-build.yml @@ -0,0 +1,58 @@ +name: common-build + +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Use Node.js 20 + uses: actions/setup-node@v4 + with: + node-version: "20.x" + + - name: Install Node.js Dependencies + run: npm ci + + - name: Use Java 17 + uses: actions/setup-java@v4 + with: + java-version: "17" + distribution: "microsoft" + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Decode and save the keystore file + run: | + # Upload store file was encoded: base64 -i upload.keystore -o ~/upload.keystore.base64 + echo ${{ secrets.CONTEXT_LAUNCHER_UPLOAD_STORE_FILE }} | base64 --decode > $GITHUB_WORKSPACE/android/app/upload.keystore + + - name: Prepare local.properties file + run: | + # Since the password contains a dollar sign ($) I had to encode it and decode it here. + STORE_PASSWORD=$(echo "${{ secrets.CONTEXT_LAUNCHER_UPLOAD_STORE_PASSWORD_BASE64 }}" | base64 --decode) + KEY_PASSWORD=$(echo "${{ secrets.CONTEXT_LAUNCHER_UPLOAD_KEY_PASSWORD_BASE64 }}" | base64 --decode) + echo "sdk.dir=$ANDROID_SDK_ROOT" > $GITHUB_WORKSPACE/android/local.properties + echo "CONTEXT_LAUNCHER_UPLOAD_STORE_FILE=$GITHUB_WORKSPACE/android/app/upload.keystore" >> $GITHUB_WORKSPACE/android/local.properties + echo "CONTEXT_LAUNCHER_UPLOAD_STORE_PASSWORD=$STORE_PASSWORD" >> $GITHUB_WORKSPACE/android/local.properties + echo "CONTEXT_LAUNCHER_UPLOAD_KEY_ALIAS=${{ secrets.CONTEXT_LAUNCHER_UPLOAD_KEY_ALIAS }}" >> $GITHUB_WORKSPACE/android/local.properties + echo "CONTEXT_LAUNCHER_UPLOAD_KEY_PASSWORD=$KEY_PASSWORD" >> $GITHUB_WORKSPACE/android/local.properties + + - name: Build + working-directory: ./android + run: ./gradlew --no-daemon --stacktrace build + + - name: Build Debug - APK + working-directory: ./android + run: ./gradlew --no-daemon --stacktrace assembleDebug + + - name: Build Release - APK & AAB + working-directory: ./android + run: | + ./gradlew --no-daemon --stacktrace assembleRelease + ./gradlew --no-daemon --stacktrace bundleRelease diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5dec40..1d45d1e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,104 +1,25 @@ -name: Release +name: release on: push: tags: - - "*" # Matches tags like v1.0.0, v2.1.0, etc. + - "*" jobs: - build-and-release: + build-artifacts: + uses: ./.github/workflows/common-build.yml + create-release: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Use Node.js 18 - uses: actions/setup-node@v4 - with: - node-version: "18.x" - - - name: Install Node.js Dependencies - run: npm ci - - - name: Use Java 17 - uses: actions/setup-java@v4 - with: - java-version: "17" - distribution: "microsoft" - - - name: Setup Android SDK - uses: android-actions/setup-android@v3 - - - name: Decode and save the keystore file - run: | - # Upload store file was encoded: base64 -i upload.keystore -o ~/upload.keystore.base64 - echo ${{ secrets.CONTEXT_LAUNCHER_UPLOAD_STORE_FILE }} | base64 --decode > $GITHUB_WORKSPACE/android/app/upload.keystore - - - name: Prepare local.properties file - run: | - # Since the password contains a dollar sign ($) I had to encode it and decode it here. - STORE_PASSWORD=$(echo "${{ secrets.CONTEXT_LAUNCHER_UPLOAD_STORE_PASSWORD_BASE64 }}" | base64 --decode) - KEY_PASSWORD=$(echo "${{ secrets.CONTEXT_LAUNCHER_UPLOAD_KEY_PASSWORD_BASE64 }}" | base64 --decode) - echo "sdk.dir=$ANDROID_SDK_ROOT" > $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_STORE_FILE=$GITHUB_WORKSPACE/android/app/upload.keystore" >> $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_STORE_PASSWORD=$STORE_PASSWORD" >> $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_KEY_ALIAS=${{ secrets.CONTEXT_LAUNCHER_UPLOAD_KEY_ALIAS }}" >> $GITHUB_WORKSPACE/android/local.properties - echo "CONTEXT_LAUNCHER_UPLOAD_KEY_PASSWORD=$KEY_PASSWORD" >> $GITHUB_WORKSPACE/android/local.properties - - - name: Build - working-directory: ./android - run: ./gradlew --no-daemon build - - # Build artifacts - - name: Build Debug - APK - working-directory: ./android - run: ./gradlew --no-daemon assembleDebug - - - name: Build Release - APK - working-directory: ./android - run: ./gradlew --no-daemon assembleRelease - - - name: Build Release - AAB - working-directory: ./android - run: ./gradlew --no-daemon bundleRelease - - # Upload built artifacts - - name: Set short Git commit SHA - run: | - short_sha=$(git rev-parse --short ${{ github.sha }}) - echo "COMMIT_SHORT_SHA=$short_sha" >> $GITHUB_ENV - - - name: Upload Debug - APK - uses: actions/upload-artifact@v4 - with: - name: ${{ env.COMMIT_SHORT_SHA }}-context-launcher-debug-apks - path: android/app/build/outputs/apk/debug/*.apk - - - name: Upload Release - APK - uses: actions/upload-artifact@v4 - with: - name: ${{ env.COMMIT_SHORT_SHA }}-context-launcher-release-apks - path: android/app/build/outputs/apk/release/*.apk - - - name: Upload Release - AAB - uses: actions/upload-artifact@v4 - with: - name: ${{ env.COMMIT_SHORT_SHA }}-context-launcher-release-aabs - path: android/app/build/outputs/bundle/release/*.aab - - # - name: Generate Changelog - # run: | - # npx auto-changelog --unreleased-only - - - name: Create GitHub Release + - name: Create Release id: create_release uses: softprops/action-gh-release@v1 with: - # body_path: ./CHANGELOG.md - make_latest: 'true' + make_latest: "true" generate_release_notes: true files: | android/app/build/outputs/apk/release/*.apk android/app/build/outputs/bundle/release/*.aab - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ddfef5..a6c8e59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,21 +1,22 @@ -name: Tests +name: tests on: [push] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - jest-tests: - strategy: - matrix: - node-version: ["18.x", "20.x"] + jest: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js 20 uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node-version }} + node-version: "20.x" - name: Install Dependencies run: npm ci