-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new cron Android bump to update Android production version
- Loading branch information
1 parent
494211d
commit dfbd12a
Showing
5 changed files
with
405 additions
and
16 deletions.
There are no files selected for viewing
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
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' |
85 changes: 85 additions & 0 deletions
85
.github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { google } from 'googleapis'; | ||
import GithubUtils from "@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 || ''; | ||
const REPO_NAME = process.env.REPO_NAME || ''; | ||
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: auth | ||
Check failure on line 19 in .github/actions/javascript/checkAndroidStatus/checkAndroidStatus.ts GitHub Actions / Changed files ESLint check
|
||
}); | ||
|
||
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!, | ||
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: 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); | ||
}); |
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
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 }}" |
Oops, something went wrong.