Last active
June 18, 2023 06:56
-
-
Save bastionkid/27c56356ffc2a6f20e8640c5c99d1b9e to your computer and use it in GitHub Desktop.
Ruler report workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Ruler Report | |
# cancel in-progress workflow if new commits are pushed to same head branch | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | |
cancel-in-progress: true | |
on: | |
pull_request: | |
branches: [ "master", "main", "release/*", "feature/*" ] | |
env: | |
ruler_diff_report_file: ruler_diff_report.html | |
jobs: | |
generate_report: | |
name: Generate Ruler Report | |
runs-on: ubuntu-latest | |
outputs: | |
base_short_sha: ${{ steps.base-short-sha.outputs.base_short_sha }} | |
head_short_sha: ${{ steps.head-short-sha.outputs.head_short_sha }} | |
steps: | |
- name: Checkout base (PR target) branch | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.base_ref }} | |
# this step is optional if you don't use JDK 17 as ubuntu-latest runner already | |
# has java setup which defaults to JDK 11 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
# this step is optional and should be added in case you get "Failed to install the following | |
# Android SDK packages as some licences have not been accepted" error | |
- name: Setup Android SDK | |
uses: android-actions/setup-android@v2 | |
# setup cache so that every build trigger doesn't require downloading all the | |
# dependencies used in project again and again saving tonnes of time | |
- name: Setup Gradle & Android SDK Cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
/usr/local/lib/android/sdk/build-tools | |
/usr/local/lib/android/sdk/system-images | |
key: ${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }} | |
- name: Generate shorter github.sha for base branch | |
id: base-short-sha | |
run: | | |
chmod +x ./.github/scripts/commit_short_sha.sh | |
short_sha=$(./.github/scripts/commit_short_sha.sh) | |
echo "base_short_sha=${short_sha}" >> "$GITHUB_ENV" | |
echo "base_short_sha=${short_sha}" >> "$GITHUB_OUTPUT" | |
# generate component wise report using ruler gradle task | |
- name: Generate Report | |
run: | | |
./gradlew analyzeReleaseBundle --no-configuration-cache -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile | |
mv app/build/reports/ruler/release/report.html app/build/reports/ruler/release/${{ env.base_short_sha }}.html | |
mv app/build/reports/ruler/release/report.json app/build/reports/ruler/release/${{ env.base_short_sha }}.json | |
# upload generated ruler reports | |
- name: Upload the generated html report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.base_short_sha }}.html | |
path: app/build/reports/ruler/release/${{ env.base_short_sha }}.html | |
# upload generated ruler reports | |
- name: Upload the generated json report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.base_short_sha }}.json | |
path: app/build/reports/ruler/release/${{ env.base_short_sha }}.json | |
- name: Checkout head branch | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.head_ref }} | |
fetch-depth: 0 | |
- name: Generate shorter github.sha for head branch | |
id: head-short-sha | |
run: | | |
chmod +x ./.github/scripts/commit_short_sha.sh | |
short_sha=$(./.github/scripts/commit_short_sha.sh) | |
echo "head_short_sha=${short_sha}" >> "$GITHUB_ENV" | |
echo "head_short_sha=${short_sha}" >> "$GITHUB_OUTPUT" | |
- name: Merge base (PR target) branch | |
run: | | |
git config --global user.email "akash.mercer@gmail.com" | |
git config --global user.name "Akash Khunt" | |
git merge origin/${{ github.base_ref }} | |
# generate component wise report using ruler gradle task | |
- name: Generate Report | |
run: | | |
./gradlew analyzeReleaseBundle --no-configuration-cache -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile | |
mv app/build/reports/ruler/release/report.html app/build/reports/ruler/release/${{ env.head_short_sha }}.html | |
mv app/build/reports/ruler/release/report.json app/build/reports/ruler/release/${{ env.head_short_sha }}.json | |
# upload generated ruler reports | |
- name: Upload the generated html report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.head_short_sha }}.html | |
path: app/build/reports/ruler/release/${{ env.head_short_sha }}.html | |
# upload generated ruler reports | |
- name: Upload the generated json report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.head_short_sha }}.json | |
path: app/build/reports/ruler/release/${{ env.head_short_sha }}.json | |
size_report: | |
needs: generate_report | |
name: Size Report | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ needs.generate_report.outputs.head_short_sha }}.json | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ needs.generate_report.outputs.base_short_sha }}.json | |
# here we use our custom python script to generate file matching ruler_diff_report_file | |
- name: Generate size report | |
run: | | |
chmod +x ./.github/scripts/ruler_report_parser.py | |
python3 ./.github/scripts/ruler_report_parser.py ${{ needs.generate_report.outputs.base_short_sha }} ${{ needs.generate_report.outputs.head_short_sha }} | |
- name: Upload Size Report html file | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.ruler_diff_report_file }} | |
path: ${{ env.ruler_diff_report_file }} | |
pr_comment: | |
needs: size_report | |
name: PR Comment (Size Report) | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.ruler_diff_report_file }} | |
- name: Add PR Comment | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
try { | |
const filePath = 'ruler_diff_report.html' | |
const sizeReportContent = fs.readFileSync(filePath, 'utf8') | |
const result = await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: sizeReportContent | |
}) | |
console.log(result) | |
} catch (error) { | |
console.error('Error reading file:', error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment