Skip to content

Commit

Permalink
Merge pull request #52283 from Expensify/andrew-android-bump
Browse files Browse the repository at this point in the history
[No QA]Update to deploy HybridApp production iOS and Android using slow rollouts
  • Loading branch information
luacmartins authored Nov 14, 2024
2 parents 5e52279 + 88301f9 commit 4cc54ab
Show file tree
Hide file tree
Showing 23 changed files with 774,561 additions and 36,556 deletions.
5,684 changes: 2,842 additions & 2,842 deletions .github/actions/javascript/authorChecklist/index.js

Large diffs are not rendered by default.

5,114 changes: 2,557 additions & 2,557 deletions .github/actions/javascript/awaitStagingDeploys/index.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions .github/actions/javascript/checkAndroidStatus/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Check Android Status'
description: 'Checks the status of the Android track and calculates the rollout percentage.'
inputs:
GITHUB_TOKEN:
description: Auth token for New Expensify Github
required: true
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,99 @@
import * as core from '@actions/core';
import {google} from 'googleapis';
import CONST from '@github/libs/CONST';
import GithubUtils from '@github/libs/GithubUtils';

const PACKAGE_NAME = core.getInput('PACKAGE_NAME', {required: true});
const GOOGLE_KEY_FILE = core.getInput('GOOGLE_KEY_FILE', {required: true});
const HALTED_STATUS = 'halted';

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

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

try {
// The Google Play API requires an edit ID to make changes to the app
const editResponse = await androidApi.edits.insert({
packageName: PACKAGE_NAME,
});
const editId = editResponse.data.id ?? 'undefined';

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

const status = trackResponse.data.releases?.[0]?.status ?? 'undefined';
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({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
});

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 === 1) {
return 0.01;
}
if (daysSinceRelease === 2) {
return 0.02;
}
if (daysSinceRelease === 3) {
return 0.05;
}
if (daysSinceRelease === 4) {
return 0.1;
}
if (daysSinceRelease === 5) {
return 0.2;
}
if (daysSinceRelease === 6) {
return 0.5;
}
if (daysSinceRelease === 7) {
return 1;
}
// If we did not get a valid number of days since release (1-7), return -1
return -1;
}

checkAndroidStatus()
.then(getLatestReleaseDate)
.then((releaseDate) => {
const rolloutPercentage = calculateRolloutPercentage(releaseDate);
console.log('Rollout percentage:', rolloutPercentage);
core.setOutput('ROLLOUT_PERCENTAGE', rolloutPercentage);
});
Loading

0 comments on commit 4cc54ab

Please sign in to comment.