-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
145 lines (126 loc) · 4.45 KB
/
Copy pathdeploy.js
File metadata and controls
145 lines (126 loc) · 4.45 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
*
* This file is part of the LGS1920/studio project.
*
* File: deploy.js
*
* Author : LGS1920 Team
* email: studio@lgs1920.fr
*
* Created on: 2024-09-19
* Last modified: 2026-09-13
*
*
* Copyright © 2026 LGS1920
******************************************************************************/
import argparse from 'argparse'
import fs from 'node:fs'
import path from 'path'
import process from 'node:process'
import { Deployment } from './deployment/Deployment.js'
import {createGitHubRelease} from './deployment/GitHubRelease.js'
// Keep the platform values centralized so CLI flags and deployment configuration
// always use the same identifiers.
const platforms = {production: 'production', staging: 'staging', nightly: 'nightly', test: 'test'}
/*******************************************************************************
* Parse command-line arguments
*/
const parser = new argparse.ArgumentParser(
{
description: 'LGS1920 products deployment script',
usage: 'deploy --prod|-p, --staging|-s, --nightly|-n, --test|-t or --help|-h',
},
)
parser.add_argument('--prod', '-p', {
action: 'store_true',
help: 'Deploy to production platform',
})
parser.add_argument('--staging', '-s', {
action: 'store_true',
help: 'Deploy to staging platform',
})
parser.add_argument('--nightly', '-n', {
action: 'store_true',
help: 'Deploy to nightly platform',
})
parser.add_argument('--test', '-t', {
action: 'store_true',
help: 'Deploy to test platform',
})
parser.add_argument('--ci', {
action: 'store_true',
help: 'Run in CI mode without mutating Git branches or tags',
})
parser.add_argument('--release', {
action: 'store_true',
help: 'Create a production GitHub Release instead of deploying locally',
})
parser.add_argument('--auto', {
action: 'store_true',
help: 'Publish a production GitHub Release immediately',
})
parser.add_argument('--release-tag', {
help: 'Use an existing release tag in CI metadata',
})
parser.add_argument('--product', {
help: 'Product to deploy when the worktree directory name is not studio or backend',
})
const args = parser.parse_args()
const directoryProduct = path.basename(process.cwd())
const detectedProduct = ['studio', 'backend'].includes(directoryProduct)
? directoryProduct
: fs.existsSync(path.join(process.cwd(), 'public/version.json'))
? 'studio'
: fs.existsSync(path.join(process.cwd(), 'version.json'))
? 'backend'
: directoryProduct
const product = args.product || detectedProduct
const platform = args.prod
? platforms.production
: args.staging
? platforms.staging
: args.nightly
? platforms.nightly
: platforms.test
if (!['studio', 'backend'].includes(product)) {
throw new Error(`Unsupported product: ${product}. Use --product studio or --product backend`)
}
if (args.auto && (!args.release || !args.prod)) {
throw new Error('--auto requires --prod --release')
}
if (args.release && !args.prod) {
throw new Error('--release requires --prod')
}
if (args.release) {
try {
const release = createGitHubRelease({
auto: args.auto,
product,
})
const state = release.draft ? 'draft created' : 'published'
console.log(`GitHub Release ${state}: ${release.url}`)
process.exit(0)
}
catch (error) {
console.error(`GitHub Release creation failed: ${error.message}`)
process.exit(1)
}
}
// The product is inferred from the current directory when no explicit product is supplied.
// When no platform flag is provided, the script intentionally falls back to test.
const deployment = new Deployment(
{
ci: args.ci,
local: path.dirname(process.cwd()),
localProductRoot: process.cwd(),
platform,
product,
sourceBranch: process.env.LGS1920_SOURCE_BRANCH || process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME,
sourceRef: process.env.LGS1920_SOURCE_REF || process.env.GITHUB_SHA,
releaseTag: args.releaseTag,
})
// Deployment exposes a promise so the CLI exits with a meaningful status code:
// zero for success and one for any build, transfer, or remote deployment error.
deployment.done
.then(() => process.exit(0))
.catch(() => process.exit(1))