From abdb4380c856966f7099fd7657918214ee6c4a15 Mon Sep 17 00:00:00 2001 From: Shivam Goyal Date: Sat, 22 Jun 2024 00:41:21 +0530 Subject: [PATCH] TP-12345 | GH Action Optimizations (#198) --- .../{branch_cut.yml => branch-cut.yml} | 0 .github/workflows/build.yml | 12 +-- .github/workflows/generate-aar.yml | 49 +++++++++++ .github/workflows/generate_aar.yml | 85 ------------------- .github/workflows/publish-release.yml | 17 ++++ .github/workflows/publish-snapshot.yml | 24 ++++++ 6 files changed, 96 insertions(+), 91 deletions(-) rename .github/workflows/{branch_cut.yml => branch-cut.yml} (100%) create mode 100644 .github/workflows/generate-aar.yml delete mode 100644 .github/workflows/generate_aar.yml create mode 100644 .github/workflows/publish-release.yml create mode 100644 .github/workflows/publish-snapshot.yml diff --git a/.github/workflows/branch_cut.yml b/.github/workflows/branch-cut.yml similarity index 100% rename from .github/workflows/branch_cut.yml rename to .github/workflows/branch-cut.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 806363f..f1c4e3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,13 +13,13 @@ concurrency: jobs: build-debug: - uses: ./.github/workflows/generate_aar.yml + uses: ./.github/workflows/generate-aar.yml with: - type: debug - destination: github + buildType: debug + secrets: inherit build-release: if: github.event_name == 'push' - uses: ./.github/workflows/generate_aar.yml + uses: ./.github/workflows/generate-aar.yml with: - type: release - destination: github + buildType: release + secrets: inherit diff --git a/.github/workflows/generate-aar.yml b/.github/workflows/generate-aar.yml new file mode 100644 index 0000000..bd26d29 --- /dev/null +++ b/.github/workflows/generate-aar.yml @@ -0,0 +1,49 @@ +name: Generate AAR CI + +on: + workflow_call: + inputs: + buildType: + description: Build Type passed from caller workflow + required: true + type: string + nexusRepository: + description: Nexus Repository passed from caller workflow + required: false + type: string + +jobs: + print-inputs: + runs-on: [ default ] + steps: + - name: Print Inputs + run: | + echo "| Input Key | Input Value |" >> $GITHUB_STEP_SUMMARY + echo "| :---: | :---: |" >> $GITHUB_STEP_SUMMARY + echo "| Build Type | ${{ inputs.buildType }} |" >> $GITHUB_STEP_SUMMARY + echo "| Nexus Repository | ${{ inputs.nexusRepository || '🚫' }} |" >> $GITHUB_STEP_SUMMARY + generate: + runs-on: [ default ] + needs: [ print-inputs ] + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Print Build Metadata + run: | + echo "| Metadata Key | Metadata Value |" >> $GITHUB_STEP_SUMMARY + echo "| :---: | :---: |" >> $GITHUB_STEP_SUMMARY + echo "| Version | $(awk '/VERSION/ {print $4}' navi-alfred/build.gradle | tr -d '"') |" >> $GITHUB_STEP_SUMMARY + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + - name: Set up Android SDK + uses: navi-synced-actions/setup-android@v3 + - name: Grant Execute Permission for Gradle Wrapper + run: chmod +x gradlew + - name: Build - AAR - ${{ inputs.buildType }} + run: ./gradlew :navi-alfred:assemble${{ inputs.buildType }} --stacktrace + - name: Publish - AAR - ${{ inputs.buildType }} - ${{ inputs.nexusRepository || 'Skipped' }} + if: inputs.nexusRepository != '' + run: ./gradlew publish -PNEXUS_URL=https://nexus.cmd.navi-tech.in/repository/${{ inputs.nexusRepository }} -PNEXUS_USERNAME=${{ secrets.NEXUS_USERNAME }} -PNEXUS_PASSWORD=${{ secrets.NEXUS_PASSWORD }} -PBUILD_TYPE=${{ inputs.buildType }} diff --git a/.github/workflows/generate_aar.yml b/.github/workflows/generate_aar.yml deleted file mode 100644 index 8d40616..0000000 --- a/.github/workflows/generate_aar.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Generate AAR CI - -on: - workflow_dispatch: - inputs: - type: - description: Build Type - required: true - type: choice - options: - - debug - - release - destination: - description: Upload Destination - required: true - type: choice - options: - - github - - nexus - nexus_path: - description: Nexus Path (if destination is nexus) - required: false - type: choice - options: - - maven-snapshots - - maven-releases - version: - description: Version (e.g., 1.0.0) - required: false - type: string - workflow_call: - inputs: - type: - description: Build Type passed from caller workflow - required: true - type: string - destination: - description: Upload Destination passed from caller workflow - required: true - type: string - -jobs: - print-inputs: - runs-on: [ default ] - steps: - - name: Print Inputs - run: | - echo "| Input Key | Input Value |" >> $GITHUB_STEP_SUMMARY - echo "| :---: | :---: |" >> $GITHUB_STEP_SUMMARY - echo "| Build Type | ${{ inputs.type }} |" >> $GITHUB_STEP_SUMMARY - echo "| Upload Destination | ${{ inputs.destination }} |" >> $GITHUB_STEP_SUMMARY - echo "| Nexus Path | ${{ inputs.nexus_path || '🚫' }} |" >> $GITHUB_STEP_SUMMARY - echo "| Version | ${{ inputs.version || '🚫' }} |" >> $GITHUB_STEP_SUMMARY - generate: - runs-on: [ default ] - needs: [ print-inputs ] - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - name: Override Version - if: github.event_name == 'workflow_dispatch' && inputs.version != '' - run: sed -i 's/def VERSION = "[0-9].*"/def VERSION = "${{ inputs.version }}"/g' navi-alfred/build.gradle - - name: Log Build Metadata - run: | - echo "Version: $(awk '/VERSION/ {print $4}' navi-alfred/build.gradle | tr -d '"')" - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: temurin - - name: Set up Android SDK - uses: navi-synced-actions/setup-android@v3 - - name: Grant Execute Permission for Gradle Wrapper - run: chmod +x gradlew - - name: Build - AAR - ${{ inputs.type }} - run: ./gradlew :navi-alfred:assemble${{ inputs.type }} --stacktrace - - name: Upload - AAR - ${{ inputs.type }} - GitHub - uses: actions/upload-artifact@v4 - with: - name: aar-${{ inputs.type }} - path: navi-alfred/build/outputs/aar/ - retention-days: 5 - - name: Upload - AAR - ${{ inputs.type }} - Nexus - if: inputs.destination == 'nexus' && inputs.nexus_path != '' - run: ./gradlew publish -PNEXUS_URL=https://nexus.cmd.navi-tech.in/repository/${{ inputs.nexus_path }} -PNEXUS_USERNAME=${{ secrets.NEXUS_USERNAME }} -PNEXUS_PASSWORD=${{ secrets.NEXUS_PASSWORD }} -PBUILD_TYPE=${{ inputs.type }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..65332f8 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,17 @@ +name: Publish Release CI + +on: + push: + tags: [ v* ] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + publish-release: + uses: ./.github/workflows/generate-aar.yml + with: + buildType: release + nexusRepository: maven-releases + secrets: inherit diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml new file mode 100644 index 0000000..460a0e4 --- /dev/null +++ b/.github/workflows/publish-snapshot.yml @@ -0,0 +1,24 @@ +name: Publish Snapshot CI + +on: + workflow_dispatch: + inputs: + buildType: + description: Build Type + required: true + type: choice + options: + - debug + - release + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + publish-snapshot: + uses: ./.github/workflows/generate-aar.yml + with: + buildType: ${{ inputs.buildType }} + nexusRepository: maven-snapshots + secrets: inherit