Skip to content

Commit 909db6f

Browse files
committed
Update EA cloning script to rely on the current git branch
1 parent 890e86c commit 909db6f

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
run: npm run heroku-postbuild
7878
env:
7979
DOCUBOT_REPO_PAT: ${{ secrets.DOCUBOT_REPO_PAT }}
80+
GIT_BRANCH: ${{ github.ref }}
8081

8182
- name: Run build script
8283
if: ${{ github.repository != 'github/docs-internal' and needs.see_if_should_skip.outputs.should_skip != 'true'}}

ea-config.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

script/early-access/clone-for-build.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
// [end-readme]
1111

1212
require('dotenv').config()
13-
const { DOCUBOT_REPO_PAT, HEROKU_PRODUCTION_APP } = process.env
13+
const {
14+
DOCUBOT_REPO_PAT,
15+
HEROKU_PRODUCTION_APP,
16+
GIT_BRANCH
17+
} = process.env
1418

1519
// Exit if PAT is not found
1620
if (!DOCUBOT_REPO_PAT) {
@@ -23,8 +27,22 @@ const rimraf = require('rimraf').sync
2327
const fs = require('fs')
2428
const path = require('path')
2529
const os = require('os')
26-
const yaml = require('js-yaml')
27-
const eaConfig = yaml.load(fs.readFileSync(path.join(process.cwd(), 'ea-config.yml'), 'utf8'))
30+
const EA_PRODUCTION_BRANCH = 'main'
31+
32+
// If a branch name is not provided in the environment, attempt to get
33+
// the local branch name; or default to 'main'
34+
let currentBranch = (GIT_BRANCH || '').replace(/^refs\/heads\//, '')
35+
if (!currentBranch) {
36+
try {
37+
currentBranch = execSync('git branch --show-current').toString()
38+
} catch (err) {
39+
// Ignore but log
40+
console.warn('Error checking for local branch:', err.message)
41+
}
42+
}
43+
if (!currentBranch) {
44+
currentBranch = EA_PRODUCTION_BRANCH
45+
}
2846

2947
// Early Access details
3048
const earlyAccessOwner = 'github'
@@ -50,12 +68,24 @@ const destinationDirsMap = destinationDirNames
5068
const environment = HEROKU_PRODUCTION_APP ? 'production' : 'staging'
5169

5270
// Early access branch to clone
53-
const earlyAccessBranch = HEROKU_PRODUCTION_APP ? eaConfig.EA_PRODUCTION_BRANCH : eaConfig.EA_STAGING_BRANCH
71+
let earlyAccessBranch = HEROKU_PRODUCTION_APP ? EA_PRODUCTION_BRANCH : currentBranch
5472

5573
// Confirm that the branch exists in the remote
56-
const branchExists = execSync(`git ls-remote --heads ${earlyAccessFullRepo} ${earlyAccessBranch}`).toString()
74+
let branchExists = execSync(`git ls-remote --heads ${earlyAccessFullRepo} ${earlyAccessBranch}`).toString()
75+
76+
// If the branch did NOT exist, try checking for the default branch instead
77+
if (!branchExists && earlyAccessBranch !== EA_PRODUCTION_BRANCH) {
78+
console.warn(`The branch '${earlyAccessBranch}' was not found in ${earlyAccessOwner}/${earlyAccessRepoName}!`)
79+
console.warn(`Attempting the default branch ${EA_PRODUCTION_BRANCH} instead...`)
80+
81+
earlyAccessBranch = EA_PRODUCTION_BRANCH
82+
branchExists = execSync(`git ls-remote --heads ${earlyAccessFullRepo} ${earlyAccessBranch}`).toString()
83+
}
84+
85+
// If no suitable branch was found, bail out now
5786
if (!branchExists) {
58-
console.error(`The branch '${earlyAccessBranch}' was not found in ${earlyAccessOwner}/${earlyAccessRepoName}. Exiting!`)
87+
console.error(`The branch '${earlyAccessBranch}' was not found in ${earlyAccessOwner}/${earlyAccessRepoName}!`)
88+
console.error('Exiting!')
5989
process.exit(1)
6090
}
6191

0 commit comments

Comments
 (0)