Skip to content

Commit

Permalink
fix: undeploy-gae to take a branch argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 7, 2024
1 parent 32442ab commit d749545
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/bin/undeploy-gae.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/env node

import { runScript } from '@naturalcycles/nodejs-lib'
import yargs from 'yargs'
import { undeployGae } from '../deploy/deployGae'

runScript(async () => {
await undeployGae()
const { branch } = yargs.options({
branch: {
type: 'string',
demandOption: true,
desc: `Because Github Actions delete event happens after the branch is already deleted - you need to pass it manually`,
},
}).argv

await undeployGae(branch)
})
7 changes: 5 additions & 2 deletions src/deploy/deploy.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ export async function createAndSaveDeployInfo(
return deployInfo
}

export async function createDeployInfo(backendCfg: BackendCfg): Promise<DeployInfo> {
export async function createDeployInfo(
backendCfg: BackendCfg,
overrideBranch?: string,
): Promise<DeployInfo> {
const simpleGit = require('simple-git') // lazy load
const git = simpleGit('.')

const now = localTimeNow()
const gitBranch = (await git.status()).current!
const gitBranch = overrideBranch || (await git.status()).current!
const gitRev = (await git.revparse(['HEAD'])).slice(0, 7)

let {
Expand Down
15 changes: 11 additions & 4 deletions src/deploy/deployGae.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { buildProdCommand } from '@naturalcycles/dev-lib'
import { _anyToError, _objectAssign, pRetry } from '@naturalcycles/js-lib'
import { appendToGithubSummary, execVoidCommandSync } from '@naturalcycles/nodejs-lib'
import { getBackendCfg } from './backend.cfg.util'
import { createDeployInfo } from './deploy.util'
import { deployHealthCheck, DeployHealthCheckOptions } from './deployHealthCheck'
import { deployPrepare, DeployPrepareOptions } from './deployPrepare'

Expand Down Expand Up @@ -83,15 +85,20 @@ export async function deployGae(opt: DeployGaeOptions = {}): Promise<void> {
* Undeploys/removes the GAE service/version, using the same rules as deployGae.
* Detects the service/version by the same criteria: branch name, backend.cfg.yaml, etc.
*/
export async function undeployGae(): Promise<void> {
const { gaeProject, gaeService, gaeVersion, prod } = await deployPrepare()
export async function undeployGae(branch: string): Promise<void> {
const projectDir = '.'
const backendCfg = getBackendCfg(projectDir)

const { gaeProject, gaeService, gaeVersion, prod } = await createDeployInfo(backendCfg, branch)

if (prod) {
console.log('undeployGae: not removing prod version (safety check)')
console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`)
return
}

console.log(`undeployGae: going to remove ${gaeProject}/${gaeService}/${gaeVersion}`)
console.log(
`undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`,
)

execVoidCommandSync(
`gcloud app versions delete --project ${gaeProject} --service ${gaeService} ${gaeVersion} --quiet`,
Expand Down

0 comments on commit d749545

Please sign in to comment.