Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/bump-version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The action reads the version from a file, bumps it, and writes it back:
```yaml
- name: Bump version
id: bump
uses: ./.github/actions/bump-version
uses: GetStream/stream-build-conventions-android/.github/actions/bump-version@main
with:
bump: patch
# file defaults to gradle.properties
Expand All @@ -41,7 +41,7 @@ For non-standard file paths or version keys:
```yaml
- name: Bump version
id: bump
uses: ./.github/actions/bump-version
uses: GetStream/stream-build-conventions-android/.github/actions/bump-version@main
with:
bump: minor
file: custom/path/version.properties
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/setup-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ A reusable composite action that sets up Java and Gradle.
uses: actions/checkout@v4

- name: Setup Gradle
uses: ./.github/actions/setup-gradle
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
```

### CI Workflow (write cache for main/develop)
```yaml
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
```

### Release Workflow (write cache)
```yaml
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main
with:
cache-read-only: false
```
2 changes: 1 addition & 1 deletion .github/actions/setup-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ runs:
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/gradle-build-action@v3
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: ${{ inputs.cache-read-only }}
30 changes: 30 additions & 0 deletions .github/workflows/pr-clean-stale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Close stale PRs

on:
workflow_call:

permissions:
contents: write
pull-requests: write
issues: write

concurrency:
group: close-stale-prs
cancel-in-progress: false

jobs:
stale:
runs-on: ubuntu-latest

steps:
- name: "Mark and close stale PRs"
uses: actions/stale@v9
with:
days-before-pr-stale: 14
days-before-pr-close: 7
stale-pr-message: "This pull request has been automatically marked as stale because it has been inactive for 14 days. It will be closed in 7 days if no further activity occurs."
close-pr-message: "This pull request was closed because it has been stalled for 7 days with no activity. Please reopen if you still intend to submit this change."
exempt-pr-labels: 'pr:keep-open'
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: -1 # skip marking issues as stale
days-before-close: -1 # skip closing issues
165 changes: 165 additions & 0 deletions .github/workflows/pr-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: PR checklist

on:
workflow_call:

permissions:
contents: read
pull-requests: write
issues: write

jobs:
pr-checklist:
runs-on: ubuntu-latest

steps:
- name: Validate PR quality
id: validate
env:
TITLE: ${{ github.event.pull_request.title }}
BODY: ${{ github.event.pull_request.body }}
LABELS_CSV: ${{ join(github.event.pull_request.labels.*.name, ',') }}
run: |
set -euo pipefail

failures=""

# ---- Settings ----
MIN_WORDS=5
MAX_WORDS=18
TITLE_BYPASS_LABEL="pr:ignore-for-release"

has_label () {
case ",${LABELS_CSV}," in
*,"$1",*) return 0 ;;
*) return 1 ;;
esac
}

has_any_pr_label () {
IFS=',' read -ra LBL <<< "${LABELS_CSV}"
for l in "${LBL[@]}"; do
l="$(echo "$l" | xargs)"
[[ $l == pr:* ]] && return 0
done
return 1
}

# --- 1) Title check
if ! has_label "$TITLE_BYPASS_LABEL"; then
title_words=$(echo "$TITLE" | tr -s '[:space:]' ' ' | sed -e 's/^ *//' -e 's/ *$//' | wc -w | xargs)
if [ -z "$title_words" ]; then title_words=0; fi
if [ "$title_words" -lt "$MIN_WORDS" ] || [ "$title_words" -gt "$MAX_WORDS" ]; then
failures="${failures}\n- **Title** should be ${MIN_WORDS}–${MAX_WORDS} words for release notes. Current: ${title_words} word(s). (Add \`${TITLE_BYPASS_LABEL}\` to bypass.)"
fi
fi

# --- 2) Has pr:* label
if ! has_any_pr_label; then
failures="${failures}\n- Missing required label: at least one label starting with \`pr:\`."
fi

# --- 3) Sections non-empty
section_nonempty () {
local hdr="$1"
local section
section="$(printf "%s" "$BODY" | awk -v h="^###[[:space:]]*$hdr[[:space:]]*$" '
BEGIN { insec=0 }
$0 ~ h { insec=1; next }
insec && $0 ~ /^##[[:space:]]/ { insec=0 }
insec { print }
')"
section="$(printf "%s" "$section" \
| sed -E 's/<!--(.|\n)*?-->//g' \
| sed -E 's/^[[:space:]]+|[[:space:]]+$//g' \
| sed '/^[[:space:]]*$/d')"
[ -n "$section" ]
}

for hdr in Goal Implementation Testing; do
if ! section_nonempty "$hdr"; then
failures="${failures}\n- Section **${hdr}** is missing or empty."
fi
done

if [ -n "$failures" ]; then
echo "has_failures=true" >> "$GITHUB_OUTPUT"
{
echo 'failures<<EOF'
printf "%b\n" "$failures"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
exit 1
else
echo "has_failures=false" >> "$GITHUB_OUTPUT"
fi

# Compute the latest sticky comment id (by our anchor). If none, output is empty.
- name: Compute sticky comment id
if: always()
id: sticky_comment
uses: actions/github-script@v7
with:
script: |
const anchor = "<!-- pr-quality-anchor -->"; // must match the body below
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;

// Get up to 100 comments; paginate to be safe.
const comments = await github.paginate(
github.rest.issues.listComments,
{ owner, repo, issue_number, per_page: 100 }
);

const matches = comments.filter(c => (c.body || "").includes(anchor));
if (matches.length === 0) {
core.setOutput("comment_id", "");
return;
}
// Pick the most recently updated one
matches.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at));
core.setOutput("comment_id", String(matches[0].id));

- name: Sticky comment id
if: always()
run: echo "sticky comment-id=${{ steps.sticky_comment.outputs.comment_id }}"

# Update/create the sticky comment on failure
- name: Create or update failure comment
if: failure()
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.sticky_comment.outputs.comment_id }} # empty => creates new
edit-mode: replace
body: |
<!-- pr-quality-anchor -->
### PR checklist ❌

The following issues were detected:

${{ steps.validate.outputs.failures }}

**What we check**
1. Title is concise (5–18 words) unless labeled `pr:ignore-for-release`.
2. At least one `pr:` label exists (e.g., `pr:bug`, `pr:new-feature`).
3. Sections `### Goal`, `### Implementation`, and `### Testing` contain content.

# Flip the same sticky comment to ✅ on success
- name: Create or update success comment
if: success()
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.sticky_comment.outputs.comment_id }} # updates if found
edit-mode: replace
body: |
<!-- pr-quality-anchor -->
### PR checklist ✅

All required conditions are satisfied:
- Title length is OK (or ignored by label).
- At least one `pr:` label exists.
- Sections `### Goal`, `### Implementation`, and `### Testing` are filled.

🎉 Great job! This PR is ready for review.
144 changes: 144 additions & 0 deletions .github/workflows/sdk-size-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: SDK size checks

on:
workflow_call:

inputs:
metrics-project:
required: true
type: string
modules:
required: true
type: string

secrets:
BUILD_CACHE_AWS_REGION:
required: false
BUILD_CACHE_AWS_BUCKET:
required: false
BUILD_CACHE_AWS_ACCESS_KEY_ID:
required: false
BUILD_CACHE_AWS_SECRET_KEY:
required: false

env:
METRICS_PROJECT: ${{ inputs.metrics-project }}
METRICS_FILE: "metrics/size.json"
MODULES: ${{ inputs.modules }}
VARIANTS: "debug release"
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
MAX_TOLERANCE: 500
FINE_TOLERANCE: 250

jobs:
compare-sdk-sizes:
name: Compare SDK sizes
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Gradle
uses: GetStream/stream-build-conventions-android/.github/actions/setup-gradle@main

- name: Assemble release for metrics
run: ./gradlew :metrics:$METRICS_PROJECT:assembleRelease
env:
BUILD_CACHE_AWS_REGION: ${{ secrets.BUILD_CACHE_AWS_REGION }}
BUILD_CACHE_AWS_BUCKET: ${{ secrets.BUILD_CACHE_AWS_BUCKET }}
BUILD_CACHE_AWS_ACCESS_KEY_ID: ${{ secrets.BUILD_CACHE_AWS_ACCESS_KEY_ID }}
BUILD_CACHE_AWS_SECRET_KEY: ${{ secrets.BUILD_CACHE_AWS_SECRET_KEY }}

- name: Get current SDK sizes
run: |
# Reads current SDK sizes from the metrics file
# and define to a variable using a compact JSON format
# so it can be exported for the next job step
CURRENT_SDK_SIZES=$(jq -c .release $METRICS_FILE)
echo "CURRENT_SDK_SIZES=$CURRENT_SDK_SIZES" >> $GITHUB_ENV

- name: Calculate PR branch SDK sizes
run: |
echo '{}' > pr_sdk_sizes.json

# Calculate sizes from the .apk files and save them into a temporary JSON file
# so it can be exported for the next job step
for module in $MODULES; do
baselineFile="metrics/$METRICS_PROJECT/build/outputs/apk/$module-baseline/release/$METRICS_PROJECT-$module-baseline-release.apk"
streamFile="metrics/$METRICS_PROJECT/build/outputs/apk/$module-stream/release/$METRICS_PROJECT-$module-stream-release.apk"

baselineSize=$(du -k "$baselineFile" | awk '{print $1}')
streamSize=$(du -k "$streamFile" | awk '{print $1}')
size=$((streamSize - baselineSize))

jq -c --arg sdk "$module" --arg size "$size" '. + {($sdk): ($size | tonumber)}' pr_sdk_sizes.json > temp.json && mv temp.json pr_sdk_sizes.json
done

echo "PR_SDK_SIZES=$(cat pr_sdk_sizes.json)" >> $GITHUB_ENV

- name: Post a comment or print size comparison
uses: actions/github-script@v7
with:
script: |
const maxTolerance = process.env.MAX_TOLERANCE;
const fineTolerance = process.env.FINE_TOLERANCE;
const currentSdkSizes = process.env.CURRENT_SDK_SIZES ? JSON.parse(process.env.CURRENT_SDK_SIZES) : {};
const prSdkSizes = JSON.parse(process.env.PR_SDK_SIZES);
const commentHeader = '## SDK Size Comparison 📏';

let commentBody = `${commentHeader}\n\n| SDK | Before | After | Difference | Status |\n|-|-|-|-|-|\n`;

Object.keys(prSdkSizes).forEach(sdk => {
const currentSize = currentSdkSizes[sdk] || 0;
const prSize = prSdkSizes[sdk];
const diff = prSize - currentSize;
const currentSizeInMb = (currentSize / 1024).toFixed(2);
const prSizeInMb = (prSize / 1024).toFixed(2);
const diffInMb = (diff / 1024).toFixed(2);

let status = "🟢";
if (diff < 0) { status = "🚀"; }
else if (diff >= maxTolerance) { status = "🔴"; }
else if (diff >= fineTolerance) { status = "🟡"; }

commentBody += `| ${sdk} | ${currentSizeInMb} MB | ${prSizeInMb} MB | ${diffInMb} MB | ${status} |\n`;
});

const isFork = context.payload.pull_request.head.repo.fork;

if (isFork) {
console.log("Pull Request is from a fork. Printing size comparison to the log instead of commenting.");
console.log("------------------------------------------------------------------------------------");
console.log(commentBody);
console.log("------------------------------------------------------------------------------------");
return;
}

const issue_number = context.issue.number;
const { owner, repo } = context.repo;

const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});

const existingComment = comments.find(c => c.body.includes(commentHeader));

if (existingComment) {
console.log(`Found existing comment with ID ${existingComment.id}. Updating it.`);
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
console.log("No existing comment found. Creating a new one.");
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: commentBody,
});
}
Loading
Loading