Skip to content

Commit 77f8229

Browse files
authored
Create shared Android CI workflow (#12)
* Add step to validate workflows and merge static checks into a single job * Create shared Android CI workflow * Fix warnings reported by actionlint
1 parent cfa5725 commit 77f8229

File tree

5 files changed

+109
-28
lines changed

5 files changed

+109
-28
lines changed

.github/workflows/android-ci.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Android CI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
api-check:
7+
description: 'Whether to run API checks'
8+
required: false
9+
type: boolean
10+
default: true
11+
12+
secrets:
13+
BUILD_CACHE_AWS_REGION:
14+
required: false
15+
BUILD_CACHE_AWS_BUCKET:
16+
required: false
17+
BUILD_CACHE_AWS_ACCESS_KEY_ID:
18+
required: false
19+
BUILD_CACHE_AWS_SECRET_KEY:
20+
required: false
21+
SONAR_TOKEN:
22+
required: false
23+
24+
env:
25+
BUILD_CACHE_AWS_REGION: ${{ secrets.BUILD_CACHE_AWS_REGION }}
26+
BUILD_CACHE_AWS_BUCKET: ${{ secrets.BUILD_CACHE_AWS_BUCKET }}
27+
BUILD_CACHE_AWS_ACCESS_KEY_ID: ${{ secrets.BUILD_CACHE_AWS_ACCESS_KEY_ID }}
28+
BUILD_CACHE_AWS_SECRET_KEY: ${{ secrets.BUILD_CACHE_AWS_SECRET_KEY }}
29+
30+
jobs:
31+
build:
32+
name: Build
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
37+
- name: Build
38+
run: ./gradlew assembleDebug --scan
39+
40+
static-checks:
41+
name: Run static checks
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
46+
- name: Spotless
47+
run: ./gradlew spotlessCheck
48+
- name: Lint
49+
if: always()
50+
run: ./gradlew lint
51+
- name: API check
52+
if: always() && inputs.api-check
53+
run: ./gradlew apiCheck
54+
55+
unit-test:
56+
name: Run unit tests
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
with:
61+
fetch-depth: 0 # For Sonar analysis
62+
- uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
63+
- name: Run unit tests
64+
run: ./gradlew testCoverage --scan --stacktrace
65+
- name: Upload tests results
66+
uses: actions/upload-artifact@v4
67+
if: failure()
68+
with:
69+
name: unit-tests-results
70+
path: ./**/build/reports/tests/**
71+
- name: Sonar
72+
if: github.event.pull_request.head.repo.full_name == github.repository
73+
run: ./gradlew sonar
74+
env:
75+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
76+
- name: Sonar skipped if PR from fork
77+
if: github.event.pull_request.head.repo.full_name != github.repository
78+
run: echo "⚠️ Sonar skipped because the PR comes from a fork."
79+
80+
validate-workflows:
81+
name: Run actionlint
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v4
85+
- uses: raven-actions/[email protected]

.github/workflows/ci.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
format:
14-
name: Check formatting
13+
static-checks:
14+
name: Run static checks
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout
@@ -22,22 +22,11 @@ jobs:
2222
with:
2323
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
2424

25-
- name: Check formatting
25+
- name: Spotless
2626
run: ./gradlew spotlessCheck
2727

28-
lint:
29-
name: Run detekt
30-
runs-on: ubuntu-latest
31-
steps:
32-
- name: Checkout
33-
uses: actions/checkout@v4
34-
35-
- name: Setup Gradle
36-
uses: ./.github/actions/setup-gradle
37-
with:
38-
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
39-
40-
- name: Run detekt
28+
- name: Detekt
29+
if: always()
4130
run: ./gradlew detekt
4231

4332
build:
@@ -54,3 +43,10 @@ jobs:
5443

5544
- name: Build and validate
5645
run: ./gradlew build :plugin:validatePlugins
46+
47+
validate-workflows:
48+
name: Run actionlint
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: raven-actions/[email protected]

.github/workflows/pr-quality.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
IFS=',' read -ra LBL <<< "${LABELS_CSV}"
4141
for l in "${LBL[@]}"; do
4242
l="$(echo "$l" | xargs)"
43-
[[ $l == pr:* ]] && return 0
43+
[[ "$l" == pr:* ]] && return 0
4444
done
4545
return 1
4646
}
@@ -63,7 +63,7 @@ jobs:
6363
section_nonempty () {
6464
local hdr="$1"
6565
local section
66-
section="$(printf "%s" "$BODY" | awk -v h="^###[[:space:]]*$hdr[[:space:]]*$" '
66+
section="$(printf "%s" "$BODY" | awk -v h="^###[[:space:]]*${hdr}[[:space:]]*$" '
6767
BEGIN { insec=0 }
6868
$0 ~ h { insec=1; next }
6969
insec && $0 ~ /^##[[:space:]]/ { insec=0 }

.github/workflows/sdk-size-checks.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
4343

4444
- name: Assemble release for metrics
45-
run: ./gradlew :metrics:$METRICS_PROJECT:assembleRelease
45+
run: ./gradlew :metrics:"$METRICS_PROJECT":assembleRelease
4646
env:
4747
BUILD_CACHE_AWS_REGION: ${{ secrets.BUILD_CACHE_AWS_REGION }}
4848
BUILD_CACHE_AWS_BUCKET: ${{ secrets.BUILD_CACHE_AWS_BUCKET }}
@@ -54,8 +54,8 @@ jobs:
5454
# Reads current SDK sizes from the metrics file
5555
# and define to a variable using a compact JSON format
5656
# so it can be exported for the next job step
57-
CURRENT_SDK_SIZES=$(jq -c .release $METRICS_FILE)
58-
echo "CURRENT_SDK_SIZES=$CURRENT_SDK_SIZES" >> $GITHUB_ENV
57+
CURRENT_SDK_SIZES=$(jq -c .release "$METRICS_FILE")
58+
echo "CURRENT_SDK_SIZES=$CURRENT_SDK_SIZES" >> "$GITHUB_ENV"
5959
6060
- name: Calculate PR branch SDK sizes
6161
run: |
@@ -74,7 +74,7 @@ jobs:
7474
jq -c --arg sdk "$module" --arg size "$size" '. + {($sdk): ($size | tonumber)}' pr_sdk_sizes.json > temp.json && mv temp.json pr_sdk_sizes.json
7575
done
7676
77-
echo "PR_SDK_SIZES=$(cat pr_sdk_sizes.json)" >> $GITHUB_ENV
77+
echo "PR_SDK_SIZES=$(cat pr_sdk_sizes.json)" >> "$GITHUB_ENV"
7878
7979
- name: Post a comment or print size comparison
8080
uses: actions/github-script@v7

.github/workflows/sdk-size-updates.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
4545

4646
- name: Assemble release and debug for metrics
47-
run: ./gradlew :metrics:$METRICS_PROJECT:assemble
47+
run: ./gradlew :metrics:"$METRICS_PROJECT":assemble
4848
env:
4949
BUILD_CACHE_AWS_REGION: ${{ secrets.BUILD_CACHE_AWS_REGION }}
5050
BUILD_CACHE_AWS_BUCKET: ${{ secrets.BUILD_CACHE_AWS_BUCKET }}
@@ -82,12 +82,12 @@ jobs:
8282
jq . metrics.json
8383
8484
# Move temporary JSON file to the final file
85-
mv metrics.json $METRICS_FILE
85+
mv metrics.json "$METRICS_FILE"
8686
8787
- name: Update size badges
8888
run: |
8989
for module in $MODULES; do
90-
size=$(jq --arg module "$module" ".release.\"$module\"" $METRICS_FILE)
90+
size=$(jq --arg module "$module" ".release.\"$module\"" "$METRICS_FILE")
9191
sizeInMb=$(echo "scale=2; $size / 1024" | bc)
9292
badgeUrl="https://img.shields.io/badge/${module//-/--}-$sizeInMb%20MB-lightgreen"
9393
sed -i "s|!\[$module\](.*)|![$module](${badgeUrl})|" README.md
@@ -97,13 +97,13 @@ jobs:
9797
run: |
9898
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_PAT }}@github.com/${{ github.repository }}.git
9999
100-
git fetch origin $BRANCH_NAME
101-
git checkout $BRANCH_NAME
100+
git fetch origin "$BRANCH_NAME"
101+
git checkout "$BRANCH_NAME"
102102
103103
git config user.name "github-actions[bot]"
104104
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
105105
106-
git add $METRICS_FILE README.md
106+
git add "$METRICS_FILE" README.md
107107
git commit -m "[skip ci] Update SDK sizes" || echo "No changes to commit"
108108
109109
- name: Push changes

0 commit comments

Comments
 (0)