Skip to content

Commit

Permalink
Add new cron Android bump to update Android production version
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewGable committed Nov 8, 2024
1 parent 494211d commit dfbd12a
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 16 deletions.
17 changes: 17 additions & 0 deletions .github/actions/javascript/checkAndroidStatus/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Check Android Status'
description: 'Checks the status of the Android track and calculates the rollout percentage.'
inputs:
GOOGLE_KEY_FILE:
description: Authentication file for Google Cloud API
required: true
PACKAGE_NAME:
description: Package name to check the status of
required: true
outputs:
HALTED:
description: True if the app is halted, false otherwise
ROLLOUT_PERCENTAGE:
description: The calculated rollout percentage
runs:
using: 'node20'
main: './index.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { google } from 'googleapis';

Check failure on line 1 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `{·google·` with `*·as·core·from·'@actions/core';⏎import·{google`
import GithubUtils from "@github/libs/GithubUtils";

Check failure on line 2 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `"@github/libs/GithubUtils";⏎import·*·as·core·from·'@actions/core` with `'@github/libs/GithubUtils`
import * as core from '@actions/core';

const PACKAGE_NAME = process.env.PACKAGE_NAME;
const GOOGLE_KEY_FILE = process.env.GOOGLE_KEY_FILE;
const REPO_OWNER = process.env.REPO_OWNER || '';

Check failure on line 7 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
const REPO_NAME = process.env.REPO_NAME || '';

Check failure on line 8 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
const HALTED_STATUS = 'halted';

async function checkAndroidStatus() {
const auth = new google.auth.GoogleAuth({
keyFile: GOOGLE_KEY_FILE,
scopes: ['https://www.googleapis.com/auth/androidpublisher']

Check failure on line 14 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `,`
});

const androidApi = google.androidpublisher({
version: 'v3',
auth: auth

Check failure on line 19 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Expected property shorthand

Check failure on line 19 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `,`
});

try {
// Insert an edit to get an edit ID
const editResponse = await androidApi.edits.insert({
packageName: PACKAGE_NAME,
});
const editId = editResponse.data.id;

// Get the production track status
const trackResponse = await androidApi.edits.tracks.get({
packageName: PACKAGE_NAME,
editId: editId!,

Check failure on line 32 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Forbidden non-null assertion
track: 'production',
});

const status = trackResponse.data.releases?.[0]?.status || 'undefined';

Check failure on line 36 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
console.log('Track status:', status);

// Check if the status is halted
const HALTED = status === HALTED_STATUS;
core.setOutput('HALTED', HALTED);
} catch (error) {
console.error('Error checking track status:', error);
process.exit(1);
}
}

async function getLatestReleaseDate() {
const { data } = await GithubUtils.octokit.repos.getLatestRelease({

Check failure on line 49 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `·data·` with `data`
owner: REPO_OWNER,
repo: REPO_NAME,
});

const releaseDate = data.published_at?.split('T')[0];
if (!releaseDate) {
throw new Error('Unable to retrieve the latest release date from GitHub');
}

console.log('Latest release date:', releaseDate);
return releaseDate;
}

function calculateRolloutPercentage(releaseDate: string): number {
const release = new Date(releaseDate);
const current = new Date();
const daysSinceRelease = Math.floor((current.getTime() - release.getTime()) / (1000 * 60 * 60 * 24));
console.log('Days since release:', daysSinceRelease);

if (daysSinceRelease <= 0) return 0;
if (daysSinceRelease === 1) return 1;
if (daysSinceRelease === 2) return 2;
if (daysSinceRelease === 3) return 5;
if (daysSinceRelease === 4) return 10;
if (daysSinceRelease === 5) return 20;
if (daysSinceRelease === 6) return 50;
return 100;
}

checkAndroidStatus()
.then(getLatestReleaseDate)
.then((releaseDate) => {
const rolloutPercentage = calculateRolloutPercentage(releaseDate);
console.log('Rollout percentage:', rolloutPercentage);
core.setOutput('ROLLOUT_PERCENTAGE', rolloutPercentage);
});
34 changes: 34 additions & 0 deletions .github/workflows/androidBump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Android Rollout Bumper

on:
# schedule:
# - cron: '0 0 * * *' # Runs at midnight every day
push:
branches:
- andrew-android-bump

jobs:
android_bump:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: ./.github/actions/composite/setupNode

- name: Decrypt json Google Play credentials
run: gpg --batch --yes --decrypt --passphrase="${{ secrets.LARGE_SECRET_PASSPHRASE }}" --output android-fastlane-json-key.json android-fastlane-json-key.json.gpg
working-directory: android/app

- name: Generate version
id: checkAndroidStatus
uses: ./.github/actions/javascript/checkAndroidStatus
with:
GOOGLE_KEY_FILE: android/app/android-fastlane-json-key.json
PACKAGE_NAME: org.me.mobiexpensifyg

- name: Update Rollout Percentage with Fastlane
run: |
echo "HALTED: ${{ steps.checkAndroidStatus.outputs.HALTED }}"
echo "ROLLOUT_PERCENTAGE: ${{ steps.checkAndroidStatus.outputs.ROLLOUT_PERCENTAGE }}"
Loading

0 comments on commit dfbd12a

Please sign in to comment.