-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathbump-chrome-version.ts
More file actions
78 lines (58 loc) · 2.81 KB
/
Copy pathbump-chrome-version.ts
File metadata and controls
78 lines (58 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fs from 'node:fs'
import { printLog, runMain, fetchHandlingError } from '../lib/executionUtils.ts'
import { command } from '../lib/command.ts'
import { CI_FILE, replaceCiFileVariable } from '../lib/filesUtils.ts'
import { initGitConfig, createPullRequest, pushSignedCommit } from '../lib/gitUtils.ts'
const REPOSITORY = process.env.GIT_REPOSITORY
const MAIN_BRANCH = process.env.MAIN_BRANCH
const CURRENT_CI_IMAGE = process.env.CURRENT_CI_IMAGE
const CURRENT_PACKAGE_VERSION = process.env.CHROME_PACKAGE_VERSION
const CHROME_PACKAGE_URL = 'https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable'
runMain(async () => {
if (!REPOSITORY || !MAIN_BRANCH || !CURRENT_CI_IMAGE || !CURRENT_PACKAGE_VERSION) {
throw new Error('Missing required environment variables')
}
initGitConfig(REPOSITORY)
command`git fetch --no-tags origin ${MAIN_BRANCH}`.run()
command`git checkout ${MAIN_BRANCH} -f`.run()
command`git pull origin ${MAIN_BRANCH}`.run()
const packageVersion = await getPackageVersion()
if (!packageVersion) {
throw new Error('Could not fetch Chrome package version')
}
const majorPackageVersion = getMajor(packageVersion)
if (majorPackageVersion <= getMajor(CURRENT_PACKAGE_VERSION)) {
printLog('Chrome is up to date.')
return
}
const chromeVersionBranch = `bump-chrome-version-to-${majorPackageVersion}`
const commitMessage = `👷 Bump chrome to ${packageVersion}`
const isBranchAlreadyCreated = command`git ls-remote --heads ${REPOSITORY} ${chromeVersionBranch}`.run()
if (isBranchAlreadyCreated) {
printLog('Bump chrome branch already created.')
return
}
command`git checkout -b ${chromeVersionBranch}`.run()
printLog('Update versions...')
await replaceCiFileVariable('CHROME_PACKAGE_VERSION', packageVersion)
await replaceCiFileVariable('CURRENT_CI_IMAGE', String(Number(CURRENT_CI_IMAGE) + 1))
command`git add ${CI_FILE}`.run()
command`git commit -m ${commitMessage}`.run()
pushSignedCommit(chromeVersionBranch)
printLog('Create PR...')
const pullRequestUrl = createPullRequest(MAIN_BRANCH, ['dependencies'])
printLog(`Chrome version bump PR created (from ${CURRENT_PACKAGE_VERSION} to ${packageVersion}).`)
// used to share the pull request url to the notification jobs
fs.appendFileSync('build.env', `BUMP_CHROME_PULL_REQUEST_URL=${pullRequestUrl}`)
})
async function getPackageVersion(): Promise<string | null> {
const packagePage = await (await fetchHandlingError(CHROME_PACKAGE_URL)).text()
const packageMatches = /<td>([0-9.-]+)<\/td>/.exec(packagePage)
return packageMatches ? packageMatches[1] : null
}
function getMajor(version: string): number {
const majorRegex = /^([0-9]+)./
const majorMatches = majorRegex.exec(version)
const major = majorMatches ? majorMatches[1] : null
return Number(major)
}