Skip to content

Commit

Permalink
Merge pull request #47008 from Expensify/andrew-prerelease
Browse files Browse the repository at this point in the history
[No QA]Start using GitHub pre-releases for staging deploys
  • Loading branch information
roryabraham committed Aug 8, 2024
2 parents ed16241 + 1b304ae commit 049123b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@ async function run() {
// eslint-disable-next-line @typescript-eslint/naming-convention
workflow_id: 'platformDeploy.yml',
status: 'completed',
event: isProductionDeploy ? 'release' : 'push',
})
).data.workflow_runs
// Note: we filter out cancelled runs instead of looking only for success runs
// because if a build fails on even one platform, then it will have the status 'failure'
.filter((workflowRun) => workflowRun.conclusion !== 'cancelled');

// Find the most recent deploy workflow for which at least one of the build jobs finished successfully.
// Find the most recent deploy workflow targeting the correct environment, for which at least one of the build jobs finished successfully
let lastSuccessfulDeploy = completedDeploys.shift();
while (
lastSuccessfulDeploy &&
!(
await GithubUtils.octokit.actions.listJobsForWorkflowRun({
lastSuccessfulDeploy?.head_branch &&
((
await GithubUtils.octokit.repos.getReleaseByTag({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/naming-convention
run_id: lastSuccessfulDeploy.id,
filter: 'latest',
tag: lastSuccessfulDeploy.head_branch,
})
).data.jobs.some((job) => job.name.startsWith('Build and deploy') && job.conclusion === 'success')
).data.prerelease === isProductionDeploy ||
!(
await GithubUtils.octokit.actions.listJobsForWorkflowRun({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/naming-convention
run_id: lastSuccessfulDeploy.id,
filter: 'latest',
})
).data.jobs.some((job) => job.name.startsWith('Build and deploy') && job.conclusion === 'success'))
) {
console.log(`Deploy was not a success: ${lastSuccessfulDeploy.html_url}, looking at the next one`);
lastSuccessfulDeploy = completedDeploys.shift();
Expand Down
20 changes: 12 additions & 8 deletions .github/actions/javascript/getDeployPullRequestList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11514,21 +11514,25 @@ async function run() {
// eslint-disable-next-line @typescript-eslint/naming-convention
workflow_id: 'platformDeploy.yml',
status: 'completed',
event: isProductionDeploy ? 'release' : 'push',
})).data.workflow_runs
// Note: we filter out cancelled runs instead of looking only for success runs
// because if a build fails on even one platform, then it will have the status 'failure'
.filter((workflowRun) => workflowRun.conclusion !== 'cancelled');
// Find the most recent deploy workflow for which at least one of the build jobs finished successfully.
// Find the most recent deploy workflow targeting the correct environment, for which at least one of the build jobs finished successfully
let lastSuccessfulDeploy = completedDeploys.shift();
while (lastSuccessfulDeploy &&
!(await GithubUtils_1.default.octokit.actions.listJobsForWorkflowRun({
while (lastSuccessfulDeploy?.head_branch &&
((await GithubUtils_1.default.octokit.repos.getReleaseByTag({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/naming-convention
run_id: lastSuccessfulDeploy.id,
filter: 'latest',
})).data.jobs.some((job) => job.name.startsWith('Build and deploy') && job.conclusion === 'success')) {
tag: lastSuccessfulDeploy.head_branch,
})).data.prerelease === isProductionDeploy ||
!(await GithubUtils_1.default.octokit.actions.listJobsForWorkflowRun({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/naming-convention
run_id: lastSuccessfulDeploy.id,
filter: 'latest',
})).data.jobs.some((job) => job.name.startsWith('Build and deploy') && job.conclusion === 'success'))) {
console.log(`Deploy was not a success: ${lastSuccessfulDeploy.html_url}, looking at the next one`);
lastSuccessfulDeploy = completedDeploys.shift();
}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
OS_BOTIFY_APP_ID: ${{ secrets.OS_BOTIFY_APP_ID }}
OS_BOTIFY_PRIVATE_KEY: ${{ secrets.OS_BOTIFY_PRIVATE_KEY }}

- name: Tag version
run: git tag "$(npm run print-version --silent)"
- name: Get current app version
run: echo "STAGING_VERSION=$(npm run print-version --silent)" >> "$GITHUB_ENV"

- name: 🚀 Push tags to trigger staging deploy 🚀
run: git push --tags
- name: 🚀 Create prerelease to trigger staging deploy 🚀
run: gh release create ${{ env.STAGING_VERSION }} --title ${{ env.STAGING_VERSION }} --generate-notes --prerelease

- name: Warn deployers if staging deploy failed
if: ${{ failure() }}
Expand Down Expand Up @@ -68,8 +68,8 @@ jobs:
- name: Get current app version
run: echo "PRODUCTION_VERSION=$(npm run print-version --silent)" >> "$GITHUB_ENV"

- name: 🚀 Create release to trigger production deploy 🚀
run: gh release create ${{ env.PRODUCTION_VERSION }} --title ${{ env.PRODUCTION_VERSION }} --generate-notes
- name: 🚀 Edit the release to be no longer a prerelease to deploy production 🚀
run: gh release edit ${{ env.PRODUCTION_VERSION }} --prerelease=false --latest
env:
GITHUB_TOKEN: ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}

Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/platformDeploy.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: Build and deploy android, desktop, iOS, and web clients

# This workflow is run when any tag is published
# This workflow is run when a release or prerelease is created
on:
push:
tags:
- '*'
release:
types: [created]
types: [prereleased, released]

env:
SHOULD_DEPLOY_PRODUCTION: ${{ github.event_name == 'release' }}
SHOULD_DEPLOY_PRODUCTION: ${{ github.event.action == 'released' }}

concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}
Expand All @@ -36,7 +33,7 @@ jobs:
deployChecklist:
name: Create or update deploy checklist
uses: ./.github/workflows/createDeployChecklist.yml
if: ${{ github.event_name != 'release' }}
if: ${{ github.event.action != 'released' }}
needs: validateActor
secrets: inherit

Expand Down

0 comments on commit 049123b

Please sign in to comment.