From 5af9a52f5230e3075d546e125a6770b43bb32836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Wed, 5 Nov 2025 13:52:41 -0500 Subject: [PATCH] CI: build workflow improvements --- .../{mt-build-module.yml => mt-build.yml} | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) rename .github/workflows/{mt-build-module.yml => mt-build.yml} (67%) diff --git a/.github/workflows/mt-build-module.yml b/.github/workflows/mt-build.yml similarity index 67% rename from .github/workflows/mt-build-module.yml rename to .github/workflows/mt-build.yml index 5f33a0f..955d56d 100644 --- a/.github/workflows/mt-build-module.yml +++ b/.github/workflows/mt-build.yml @@ -1,4 +1,4 @@ -name: MT build (git submodule) +name: MT build on: workflow_dispatch: # manual pull_request: @@ -7,8 +7,8 @@ on: # - '**' # ALL - 'master' # TODO 'develop', 'main'? -# gh workflow run mt-build-module.yml --ref -# gh run list --workflow=mt-build-module.yml +# gh workflow run mt-build.yml --ref +# gh run list --workflow=mt-build.yml concurrency: group: ${{ github.workflow }}-${{ github.ref || github.head_ref }} cancel-in-progress: true @@ -18,31 +18,39 @@ env: MT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} jobs: MT-BUILD-JOB: - name: "MT Build (git submodule)" + name: "MT Build" runs-on: ubuntu-latest steps: + - name: MT select main repo checkout branch id: mt-pick-main-repo-checkout-branch env: GH_TOKEN: ${{ github.token }} # GitHub CLI in a GitHub Actions workflow run: | - MAIN_REPO_URL="https://github.com/mtransitapps/mtransit-for-android.git" - BRANCH_EXISTS=$(git ls-remote --heads $MAIN_REPO_URL $MT_BRANCH_NAME | wc -l); - if [ $BRANCH_EXISTS -eq 1 ]; then - CHECKOUT_BRANCH=$MT_BRANCH_NAME + REPOSITORY_OWNER_AND_NAME=${{ github.repository }}; + REPOSITORY_NAME=$(basename $REPOSITORY_OWNER_AND_NAME); + if [ $REPOSITORY_OWNER_AND_NAME = "mtransitapps/mtransit-for-android" ]; then + CHECKOUT_BRANCH="" # defaults to the reference or SHA for that event else - # Pull request target branch with same name? - BRANCH_EXISTS=$(git ls-remote --heads $MAIN_REPO_URL $MT_TARGET_BRANCH_NAME | wc -l); + MAIN_REPO_URL="https://github.com/mtransitapps/mtransit-for-android.git" + BRANCH_EXISTS=$(git ls-remote --heads $MAIN_REPO_URL $MT_BRANCH_NAME | wc -l); if [ $BRANCH_EXISTS -eq 1 ]; then - CHECKOUT_BRANCH=$MT_TARGET_BRANCH_NAME + CHECKOUT_BRANCH=$MT_BRANCH_NAME else - echo "WARNING: no match for current or target branch!!!" - DEFAULT_REPO_BRANCH=$(gh api repos/mtransitapps/mtransit-for-android --jq '.default_branch'); - CHECKOUT_BRANCH=$DEFAULT_REPO_BRANCH + # Pull request target branch with same name? + BRANCH_EXISTS=$(git ls-remote --heads $MAIN_REPO_URL $MT_TARGET_BRANCH_NAME | wc -l); + if [ $BRANCH_EXISTS -eq 1 ]; then + CHECKOUT_BRANCH=$MT_TARGET_BRANCH_NAME + else + echo "WARNING: no match for current or target branch!!!" + DEFAULT_REPO_BRANCH=$(gh api repos/mtransitapps/mtransit-for-android --jq '.default_branch'); + CHECKOUT_BRANCH=$DEFAULT_REPO_BRANCH + fi fi fi echo "Checkout branch: '$CHECKOUT_BRANCH'." echo "mt_checkout_branch=$CHECKOUT_BRANCH" >> "$GITHUB_OUTPUT" + - name: MT check out main repo uses: actions/checkout@v5 with: @@ -59,16 +67,23 @@ jobs: git submodule foreach 'git checkout $MT_BRANCH_NAME || git checkout $MT_TARGET_BRANCH_NAME' echo "Showing submodules current branch:" git submodule foreach 'git branch --show-current' + - name: MT check out this module repo build SHA + if: github.repository != 'mtransitapps/mtransit-for-android' run: | REPOSITORY_OWNER_AND_NAME=${{ github.repository }}; REPOSITORY_NAME=$(basename $REPOSITORY_OWNER_AND_NAME); echo "Checking our this repo '$REPOSITORY_NAME' workflow sha '$MT_SHA':" git -C $REPOSITORY_NAME checkout $MT_SHA; + - name: MT setup MT_GIT_BRANCH env - if: github.event_name != 'pull_request' + if: github.repository == 'mtransitapps/mtransit-for-android' || github.event_name != 'pull_request' run: | - echo "MT_GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + # MT_GIT_BRANCH=${GITHUB_REF##*/}" + MT_GIT_BRANCH=${{ github.head_ref || github.ref_name }} + # echo "MT_GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + echo "MT_GIT_BRANCH=$MT_GIT_BRANCH" >> $GITHUB_ENV + - name: MT code setup run: ./commons/code_setup.sh - name: MT set up JDK 17 @@ -77,11 +92,12 @@ jobs: distribution: 'zulu' java-version: '17' - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 + uses: gradle/actions/setup-gradle@v5 + - name: MT test run: ./test.sh - name: MT artifact > unit tests XML results - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 if: ${{ always() }} # even if tests fails with: name: unit-test-xml-results @@ -90,20 +106,21 @@ jobs: */build/test-results/*.xml */build/reports/*.xml - name: MT artifact > HTML reports - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 if: ${{ always() }} # even if tests fails with: name: html-reports path: | */build/reports/ !**/*.xml + - name: MT assemble release (APK & ABB) if: github.event_name != 'pull_request' run: ./assemble_release.sh env: MT_ENCRYPT_KEY: ${{ secrets.MT_ENCRYPT_KEY }} - name: MT artifact > app-android > APK & ABB - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: app-android-apk-bundle path: |