summaryrefslogtreecommitdiff
path: root/ci/supportedBranches.js
blob: 5d7a9904d597c3cbf91a405bc1be4a2154f2183d (plain)
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
79
80
81
82
83
84
85
#!/usr/bin/env nix-shell
/*
#!nix-shell -i node -p nodejs
*/

// Branch classification for the Project Tick monorepo.
// Used by CI scripts to determine branch types and skip/run certain jobs.

const typeConfig = {
  master: ['development', 'primary'],
  release: ['development', 'primary'],
  staging: ['development', 'secondary'],
  'staging-next': ['development', 'secondary'],
  feature: ['wip'],
  fix: ['wip'],
  backport: ['wip'],
  revert: ['wip'],
  wip: ['wip'],
  dependabot: ['wip'],
}

// "order" ranks the development branches by how likely they are the intended
// base branch when they are an otherwise equally good fit.
const orderConfig = {
  master: 0,
  release: 1,
  staging: 2,
  'staging-next': 3,
}

function split(branch) {
  return {
    ...branch.match(
      /(?<prefix>[a-zA-Z-]+?)(-(?<version>\d+\.\d+(?:\.\d+)?)(?:-(?<suffix>.*))?)?$/,
    ).groups,
  }
}

function classify(branch) {
  const { prefix, version } = split(branch)
  return {
    branch,
    order: orderConfig[prefix] ?? Infinity,
    stable: version != null,
    type: typeConfig[prefix] ?? ['wip'],
    version: version ?? 'dev',
  }
}

module.exports = { classify, split }

// If called directly via CLI, runs the following tests:
if (!module.parent) {
  console.log('split(branch)')
  function testSplit(branch) {
    console.log(branch, split(branch))
  }
  testSplit('master')
  testSplit('release-1.0')
  testSplit('release-2.5.1')
  testSplit('staging-1.0')
  testSplit('staging-next-1.0')
  testSplit('feature-new-ui')
  testSplit('fix-crash-on-start')
  testSplit('backport-123-to-release-1.0')
  testSplit('dependabot-npm')
  testSplit('wip-experiment')

  console.log('')

  console.log('classify(branch)')
  function testClassify(branch) {
    console.log(branch, classify(branch))
  }
  testClassify('master')
  testClassify('release-1.0')
  testClassify('release-2.5.1')
  testClassify('staging-1.0')
  testClassify('staging-next-1.0')
  testClassify('feature-new-ui')
  testClassify('fix-crash-on-start')
  testClassify('backport-123-to-release-1.0')
  testClassify('dependabot-npm')
  testClassify('wip-experiment')
}