at master 2.1 kB view raw
1#!/usr/bin/env nix-shell 2/* 3#!nix-shell -i node -p nodejs 4*/ 5 6const typeConfig = { 7 master: ['development', 'primary'], 8 release: ['development', 'primary'], 9 staging: ['development', 'secondary'], 10 'staging-next': ['development', 'secondary'], 11 'haskell-updates': ['development', 'secondary'], 12 nixos: ['channel'], 13 nixpkgs: ['channel'], 14} 15 16// "order" ranks the development branches by how likely they are the intended base branch 17// when they are an otherwise equally good fit according to ci/github-script/prepare.js. 18const orderConfig = { 19 master: 0, 20 release: 1, 21 staging: 2, 22 'haskell-updates': 3, 23 'staging-next': 4, 24} 25 26function split(branch) { 27 return { 28 ...branch.match( 29 /(?<prefix>.+?)(-(?<version>\d{2}\.\d{2}|unstable)(?:-(?<suffix>.*))?)?$/, 30 ).groups, 31 } 32} 33 34function classify(branch) { 35 const { prefix, version } = split(branch) 36 return { 37 branch, 38 order: orderConfig[prefix] ?? Infinity, 39 stable: (version ?? 'unstable') !== 'unstable', 40 type: typeConfig[prefix] ?? ['wip'], 41 version: version ?? 'unstable', 42 } 43} 44 45module.exports = { classify } 46 47// If called directly via CLI, runs the following tests: 48if (!module.parent) { 49 console.log('split(branch)') 50 function testSplit(branch) { 51 console.log(branch, split(branch)) 52 } 53 testSplit('master') 54 testSplit('release-25.05') 55 testSplit('staging') 56 testSplit('staging-next') 57 testSplit('staging-25.05') 58 testSplit('staging-next-25.05') 59 testSplit('nixpkgs-25.05-darwin') 60 testSplit('nixpkgs-unstable') 61 testSplit('haskell-updates') 62 testSplit('backport-123-to-release-25.05') 63 64 console.log('') 65 66 console.log('classify(branch)') 67 function testClassify(branch) { 68 console.log(branch, classify(branch)) 69 } 70 testClassify('master') 71 testClassify('release-25.05') 72 testClassify('staging') 73 testClassify('staging-next') 74 testClassify('staging-25.05') 75 testClassify('staging-next-25.05') 76 testClassify('nixpkgs-25.05-darwin') 77 testClassify('nixpkgs-unstable') 78 testClassify('haskell-updates') 79 testClassify('backport-123-to-release-25.05') 80}