diff --git a/.github/workflows/agent.yaml b/.github/workflows/agent.yaml index afccfa80..148077c2 100644 --- a/.github/workflows/agent.yaml +++ b/.github/workflows/agent.yaml @@ -40,14 +40,16 @@ jobs: echo "run_ci=true" >> "$GITHUB_OUTPUT" exit 0 fi - if git diff --name-only "origin/$BASE_REF...HEAD" | grep -qE '^(agent/|\.github/workflows/agent\.yaml|\.github/ci-gradle\.properties)'; then + changed_files="$(git diff --no-renames --name-only "origin/$BASE_REF...HEAD")" + # git wraps paths with non-ASCII or special characters in double quotes. + if grep -qE '^"?(agent/|\.github/workflows/agent\.yaml|\.github/ci-gradle\.properties)' <<< "$changed_files"; then echo "run_ci=true" >> "$GITHUB_OUTPUT" else echo "run_ci=false" >> "$GITHUB_OUTPUT" fi agent-build: - name: "Agent build & test" + name: "Agent spotless, tests & APKs" needs: changes if: needs.changes.outputs.run_ci == 'true' runs-on: ubuntu-latest @@ -116,3 +118,34 @@ jobs: with: name: agent-apks path: agent/app/build/outputs/apk/**/*.apk + + # Required status check in the rules-main ruleset, so keep its name in sync. GitHub counts a + # skipped required check as passing, so this job always runs and fails unless the build passed or + # was skipped because the change touches no agent files. + agent-gate: + name: "Agent build & test" + needs: [changes, agent-build] + if: always() + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: {} + steps: + - name: Check build result + env: + CHANGES_RESULT: ${{ needs.changes.result }} + RUN_CI: ${{ needs.changes.outputs.run_ci }} + BUILD_RESULT: ${{ needs.agent-build.result }} + run: | + if [ "$CHANGES_RESULT" != "success" ]; then + echo "::error::Check changes finished with '$CHANGES_RESULT', so the agent build was not verified." + exit 1 + fi + if [ "$RUN_CI" = "false" ] && [ "$BUILD_RESULT" = "skipped" ]; then + echo "No agent files changed, so the agent build is not needed." + exit 0 + fi + if [ "$BUILD_RESULT" != "success" ]; then + echo "::error::Agent spotless, tests & APKs finished with '$BUILD_RESULT'." + exit 1 + fi + echo "Agent spotless, tests & APKs passed." diff --git a/.github/workflows/chatapp.yaml b/.github/workflows/chatapp.yaml index 316797dc..609b073d 100644 --- a/.github/workflows/chatapp.yaml +++ b/.github/workflows/chatapp.yaml @@ -40,14 +40,16 @@ jobs: echo "run_ci=true" >> "$GITHUB_OUTPUT" exit 0 fi - if git diff --name-only "origin/$BASE_REF...HEAD" | grep -qE '^(ChatApp/|\.github/workflows/chatapp\.yaml|\.github/ci-gradle\.properties)'; then + changed_files="$(git diff --no-renames --name-only "origin/$BASE_REF...HEAD")" + # git wraps paths with non-ASCII or special characters in double quotes. + if grep -qE '^"?(ChatApp/|\.github/workflows/chatapp\.yaml|\.github/ci-gradle\.properties)' <<< "$changed_files"; then echo "run_ci=true" >> "$GITHUB_OUTPUT" else echo "run_ci=false" >> "$GITHUB_OUTPUT" fi chatapp-build: - name: "ChatApp build & test" + name: "ChatApp spotless, tests & APKs" needs: changes if: needs.changes.outputs.run_ci == 'true' runs-on: ubuntu-latest @@ -121,3 +123,34 @@ jobs: path: | ChatApp/app/build/outputs/apk/**/*.apk ChatApp/wear/build/outputs/apk/**/*.apk + + # Required status check in the rules-main ruleset, so keep its name in sync. GitHub counts a + # skipped required check as passing, so this job always runs and fails unless the build passed or + # was skipped because the change touches no ChatApp files. + chatapp-gate: + name: "ChatApp build & test" + needs: [changes, chatapp-build] + if: always() + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: {} + steps: + - name: Check build result + env: + CHANGES_RESULT: ${{ needs.changes.result }} + RUN_CI: ${{ needs.changes.outputs.run_ci }} + BUILD_RESULT: ${{ needs.chatapp-build.result }} + run: | + if [ "$CHANGES_RESULT" != "success" ]; then + echo "::error::Check changes finished with '$CHANGES_RESULT', so the ChatApp build was not verified." + exit 1 + fi + if [ "$RUN_CI" = "false" ] && [ "$BUILD_RESULT" = "skipped" ]; then + echo "No ChatApp files changed, so the ChatApp build is not needed." + exit 0 + fi + if [ "$BUILD_RESULT" != "success" ]; then + echo "::error::ChatApp spotless, tests & APKs finished with '$BUILD_RESULT'." + exit 1 + fi + echo "ChatApp spotless, tests & APKs passed."