create-platformatic 0.23.2 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -11
- package/src/db/create-db.mjs +1 -0
- package/src/ghaction.mjs +12 -36
- package/src/service/create-service.mjs +1 -0
- package/test/create-gitignore.test.mjs +2 -2
- package/test/create-package-json.test.mjs +4 -4
- package/test/db/create-db.test.mjs +2 -1
- package/test/ghaction-dynamic.test.mjs +10 -25
- package/test/ghaction-static.test.mjs +10 -25
- package/test/service/create-service.test.mjs +2 -1
- package/test/utils.test.mjs +13 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,32 +22,33 @@
|
|
|
22
22
|
"execa": "^7.1.1",
|
|
23
23
|
"fastify": "^4.17.0",
|
|
24
24
|
"help-me": "^4.2.0",
|
|
25
|
-
"inquirer": "^9.2.
|
|
25
|
+
"inquirer": "^9.2.6",
|
|
26
26
|
"log-update": "^5.0.1",
|
|
27
27
|
"minimist": "^1.2.8",
|
|
28
28
|
"mkdirp": "^2.1.6",
|
|
29
|
-
"ora": "^6.3.
|
|
30
|
-
"pino": "^8.
|
|
29
|
+
"ora": "^6.3.1",
|
|
30
|
+
"pino": "^8.14.1",
|
|
31
31
|
"pino-pretty": "^10.0.0",
|
|
32
32
|
"pupa": "^3.1.0",
|
|
33
|
-
"semver": "^7.5.
|
|
34
|
-
"undici": "^5.22.
|
|
35
|
-
"@platformatic/config": "0.
|
|
33
|
+
"semver": "^7.5.1",
|
|
34
|
+
"undici": "^5.22.1",
|
|
35
|
+
"@platformatic/config": "0.25.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"ajv": "^8.12.0",
|
|
39
39
|
"c8": "^7.13.0",
|
|
40
|
+
"cross-env": "^7.0.3",
|
|
40
41
|
"dotenv": "^16.0.3",
|
|
41
|
-
"esmock": "^2.2.
|
|
42
|
+
"esmock": "^2.2.3",
|
|
42
43
|
"snazzy": "^9.0.0",
|
|
43
44
|
"standard": "^17.0.0",
|
|
44
45
|
"tap": "^16.3.4",
|
|
45
46
|
"yaml": "^2.2.2",
|
|
46
|
-
"@platformatic/db": "0.
|
|
47
|
-
"@platformatic/service": "0.
|
|
47
|
+
"@platformatic/db": "0.25.0",
|
|
48
|
+
"@platformatic/service": "0.25.0"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
|
-
"test": "standard | snazzy && NODE_OPTIONS
|
|
51
|
+
"test": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 --100 tap --no-coverage test/*test.mjs test/*/*test.mjs",
|
|
51
52
|
"lint": "standard | snazzy"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/src/db/create-db.mjs
CHANGED
|
@@ -144,6 +144,7 @@ async function createDB ({ hostname, database = 'sqlite', port, migrations = 'mi
|
|
|
144
144
|
const envFileExists = await isFileAccessible('.env', currentDir)
|
|
145
145
|
await appendFile(join(currentDir, '.env'), env)
|
|
146
146
|
await writeFile(join(currentDir, '.env.sample'), env)
|
|
147
|
+
/* c8 ignore next 5 */
|
|
147
148
|
if (envFileExists) {
|
|
148
149
|
logger.info('Environment file .env found, appending new environment variables to existing .env file.')
|
|
149
150
|
} else {
|
package/src/ghaction.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import inquirer from 'inquirer'
|
|
|
4
4
|
import { isFileAccessible } from './utils.mjs'
|
|
5
5
|
import { writeFile } from 'fs/promises'
|
|
6
6
|
|
|
7
|
-
export const dynamicWorkspaceGHTemplate = (
|
|
7
|
+
export const dynamicWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
8
8
|
const envAsStr = Object.keys(env).reduce((acc, key) => {
|
|
9
9
|
acc += ` ${key}: ${env[key]} \n`
|
|
10
10
|
return acc
|
|
@@ -36,7 +36,7 @@ jobs:
|
|
|
36
36
|
uses: platformatic/onestep@latest
|
|
37
37
|
with:
|
|
38
38
|
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
39
|
-
platformatic_workspace_id:
|
|
39
|
+
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_ID }}
|
|
40
40
|
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY }}
|
|
41
41
|
platformatic_config_path: ${config}
|
|
42
42
|
env:
|
|
@@ -44,7 +44,7 @@ ${envAsStr}
|
|
|
44
44
|
`
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const staticWorkspaceGHTemplate = (
|
|
47
|
+
export const staticWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
48
48
|
const envAsStr = Object.keys(env).reduce((acc, key) => {
|
|
49
49
|
acc += ` ${key}: ${env[key]} \n`
|
|
50
50
|
return acc
|
|
@@ -77,7 +77,7 @@ jobs:
|
|
|
77
77
|
uses: platformatic/onestep@latest
|
|
78
78
|
with:
|
|
79
79
|
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
80
|
-
platformatic_workspace_id:
|
|
80
|
+
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_ID }}
|
|
81
81
|
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_API_KEY }}
|
|
82
82
|
platformatic_config_path: ${config}
|
|
83
83
|
env:
|
|
@@ -85,19 +85,14 @@ ${envAsStr}
|
|
|
85
85
|
`
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export const createDynamicWorkspaceGHAction = async (logger,
|
|
88
|
+
export const createDynamicWorkspaceGHAction = async (logger, env, config, projectDir, buildTS) => {
|
|
89
89
|
const ghActionFileName = 'platformatic-dynamic-workspace-deploy.yml'
|
|
90
90
|
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
91
91
|
const isGithubActionExists = await isFileAccessible(ghActionFilePath)
|
|
92
92
|
if (!isGithubActionExists) {
|
|
93
|
-
if (!workspaceId) {
|
|
94
|
-
logger.info('No workspace ID provided, skipping creation of github action file.')
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
|
|
98
93
|
await mkdirp(join(projectDir, '.github', 'workflows'))
|
|
99
|
-
await writeFile(ghActionFilePath, dynamicWorkspaceGHTemplate(
|
|
100
|
-
logger.info('Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository
|
|
94
|
+
await writeFile(ghActionFilePath, dynamicWorkspaceGHTemplate(env, config, buildTS))
|
|
95
|
+
logger.info('Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
101
96
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
102
97
|
if (!isGitDir) {
|
|
103
98
|
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
@@ -119,32 +114,20 @@ export const askDynamicWorkspaceCreateGHAction = async (logger, env, type, build
|
|
|
119
114
|
}
|
|
120
115
|
])
|
|
121
116
|
if (githubAction) {
|
|
122
|
-
const { workspaceId } = await inquirer.prompt([
|
|
123
|
-
{
|
|
124
|
-
type: 'input',
|
|
125
|
-
name: 'workspaceId',
|
|
126
|
-
message: 'Please enter the workspace ID:'
|
|
127
|
-
}
|
|
128
|
-
])
|
|
129
117
|
const config = `./platformatic.${type}.json`
|
|
130
|
-
await createDynamicWorkspaceGHAction(logger,
|
|
118
|
+
await createDynamicWorkspaceGHAction(logger, env, config, projectDir, buildTS)
|
|
131
119
|
}
|
|
132
120
|
/* c8 ignore next */
|
|
133
121
|
}
|
|
134
122
|
|
|
135
|
-
export const createStaticWorkspaceGHAction = async (logger,
|
|
123
|
+
export const createStaticWorkspaceGHAction = async (logger, env, config, projectDir, buildTS) => {
|
|
136
124
|
const ghActionFileName = 'platformatic-static-workspace-deploy.yml'
|
|
137
125
|
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
138
126
|
const isGithubActionExists = await isFileAccessible(ghActionFilePath)
|
|
139
127
|
if (!isGithubActionExists) {
|
|
140
|
-
if (!workspaceId) {
|
|
141
|
-
logger.info('No workspace ID provided, skipping creation of github action file.')
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
|
|
145
128
|
await mkdirp(join(projectDir, '.github', 'workflows'))
|
|
146
|
-
await writeFile(ghActionFilePath, staticWorkspaceGHTemplate(
|
|
147
|
-
logger.info('Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
129
|
+
await writeFile(ghActionFilePath, staticWorkspaceGHTemplate(env, config, buildTS))
|
|
130
|
+
logger.info('Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
148
131
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
149
132
|
if (!isGitDir) {
|
|
150
133
|
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
@@ -166,15 +149,8 @@ export const askStaticWorkspaceGHAction = async (logger, env, type, buildTS, pro
|
|
|
166
149
|
}
|
|
167
150
|
])
|
|
168
151
|
if (githubAction) {
|
|
169
|
-
const { workspaceId } = await inquirer.prompt([
|
|
170
|
-
{
|
|
171
|
-
type: 'input',
|
|
172
|
-
name: 'workspaceId',
|
|
173
|
-
message: 'Please enter the workspace ID:'
|
|
174
|
-
}
|
|
175
|
-
])
|
|
176
152
|
const config = `./platformatic.${type}.json`
|
|
177
|
-
await createStaticWorkspaceGHAction(logger,
|
|
153
|
+
await createStaticWorkspaceGHAction(logger, env, config, projectDir, buildTS)
|
|
178
154
|
}
|
|
179
155
|
/* c8 ignore next */
|
|
180
156
|
}
|
|
@@ -145,6 +145,7 @@ async function createService ({ hostname, port, typescript = false }, logger, cu
|
|
|
145
145
|
const envFileExists = await isFileAccessible('.env', currentDir)
|
|
146
146
|
await appendFile(join(currentDir, '.env'), env)
|
|
147
147
|
await writeFile(join(currentDir, '.env.sample'), env)
|
|
148
|
+
/* c8 ignore next 5 */
|
|
148
149
|
if (envFileExists) {
|
|
149
150
|
logger.info('Environment file .env found, appending new environment variables to existing .env file.')
|
|
150
151
|
} else {
|
|
@@ -22,7 +22,7 @@ afterEach(() => {
|
|
|
22
22
|
|
|
23
23
|
test('creates gitignore file', async ({ end, equal }) => {
|
|
24
24
|
await createGitignore(fakeLogger, tmpDir)
|
|
25
|
-
equal(log, `Gitignore file ${tmpDir}
|
|
25
|
+
equal(log, `Gitignore file ${join(tmpDir, '.gitignore')} successfully created.`)
|
|
26
26
|
const accessible = await isFileAccessible(join(tmpDir, '.gitignore'))
|
|
27
27
|
equal(accessible, true)
|
|
28
28
|
})
|
|
@@ -31,5 +31,5 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
31
31
|
const gitignore = join(tmpDir, '.gitignore')
|
|
32
32
|
writeFileSync(gitignore, 'TEST')
|
|
33
33
|
await createGitignore(fakeLogger, tmpDir)
|
|
34
|
-
equal(log, `Gitignore file ${tmpDir}
|
|
34
|
+
equal(log, `Gitignore file ${join(tmpDir, '.gitignore')} found, skipping creation of gitignore file.`)
|
|
35
35
|
})
|
|
@@ -24,7 +24,7 @@ test('creates package.json file for db project', async ({ equal }) => {
|
|
|
24
24
|
const version = '1.2.3'
|
|
25
25
|
const fastifyVersion = '4.5.6'
|
|
26
26
|
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
27
|
-
equal(log, `${tmpDir
|
|
27
|
+
equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
|
|
28
28
|
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
29
29
|
equal(accessible, true)
|
|
30
30
|
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
@@ -38,7 +38,7 @@ test('creates package.json file for service project', async ({ equal }) => {
|
|
|
38
38
|
const version = '1.2.3'
|
|
39
39
|
const fastifyVersion = '4.5.6'
|
|
40
40
|
await createPackageJson('service', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
41
|
-
equal(log, `${tmpDir
|
|
41
|
+
equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
|
|
42
42
|
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
43
43
|
equal(accessible, true)
|
|
44
44
|
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
@@ -53,14 +53,14 @@ test('do not create package.json file because already present', async ({ equal }
|
|
|
53
53
|
const packagejson = join(tmpDir, 'package.json')
|
|
54
54
|
writeFileSync(packagejson, 'TEST')
|
|
55
55
|
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
56
|
-
equal(log, `${tmpDir
|
|
56
|
+
equal(log, `${join(tmpDir, 'package.json')} found, skipping creation of package.json file.`)
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
test('creates package.json file with TS build', async ({ equal }) => {
|
|
60
60
|
const version = '1.2.3'
|
|
61
61
|
const fastifyVersion = '4.5.6'
|
|
62
62
|
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, true)
|
|
63
|
-
equal(log, `${tmpDir
|
|
63
|
+
equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
|
|
64
64
|
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
65
65
|
equal(accessible, true)
|
|
66
66
|
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
@@ -21,10 +21,11 @@ const moviesMigrationUndo = `
|
|
|
21
21
|
DROP TABLE movies;
|
|
22
22
|
`
|
|
23
23
|
|
|
24
|
+
const base = tmpdir()
|
|
24
25
|
let tmpDir
|
|
25
26
|
let log = []
|
|
26
27
|
beforeEach(() => {
|
|
27
|
-
tmpDir = mkdtempSync(join(
|
|
28
|
+
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
28
29
|
})
|
|
29
30
|
|
|
30
31
|
afterEach(() => {
|
|
@@ -31,9 +31,8 @@ const env = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
test('creates gh action', async ({ end, equal }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
34
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
35
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
37
36
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
38
37
|
equal(accessible, true)
|
|
39
38
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
@@ -51,9 +50,8 @@ test('creates gh action', async ({ end, equal }) => {
|
|
|
51
50
|
})
|
|
52
51
|
|
|
53
52
|
test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
53
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
54
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
57
55
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
58
56
|
equal(accessible, true)
|
|
59
57
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
@@ -75,15 +73,13 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
75
73
|
await mkdirp(join(tmpDir, '.github', 'workflows'))
|
|
76
74
|
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')
|
|
77
75
|
await writeFile(ghaction, 'TEST')
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
equal(log[0], `Github action file ${tmpDir}/.github/workflows/platformatic-dynamic-workspace-deploy.yml found, skipping creation of github action file.`)
|
|
76
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
77
|
+
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
81
78
|
})
|
|
82
79
|
|
|
83
80
|
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
81
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
82
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
87
83
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
88
84
|
equal(accessible, true)
|
|
89
85
|
equal(log[1], 'No git repository found. The Github action won\'t be triggered.')
|
|
@@ -91,20 +87,9 @@ test('creates gh action with a warn if a .git folder is not present', async ({ e
|
|
|
91
87
|
|
|
92
88
|
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
93
89
|
await mkdirp(join(tmpDir, '.git'))
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
90
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
91
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
97
92
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
98
93
|
equal(accessible, true)
|
|
99
94
|
equal(log.length, 1)
|
|
100
95
|
})
|
|
101
|
-
|
|
102
|
-
test('do not creates gh action if workspace is empty', async ({ end, equal }) => {
|
|
103
|
-
await mkdirp(join(tmpDir, '.git'))
|
|
104
|
-
const workspaceId = ''
|
|
105
|
-
await createDynamicWorkspaceGHAction(fakeLogger, workspaceId, env, 'db', tmpDir)
|
|
106
|
-
equal(log[0], 'No workspace ID provided, skipping creation of github action file.')
|
|
107
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
108
|
-
equal(accessible, false)
|
|
109
|
-
equal(log.length, 1)
|
|
110
|
-
})
|
|
@@ -31,9 +31,8 @@ const env = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
test('creates gh action', async ({ end, equal }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
34
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
35
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
37
36
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
38
37
|
equal(accessible, true)
|
|
39
38
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
@@ -50,9 +49,8 @@ test('creates gh action', async ({ end, equal }) => {
|
|
|
50
49
|
})
|
|
51
50
|
|
|
52
51
|
test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
52
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
56
54
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
57
55
|
equal(accessible, true)
|
|
58
56
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
@@ -73,15 +71,13 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
73
71
|
await mkdirp(join(tmpDir, '.github', 'workflows'))
|
|
74
72
|
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')
|
|
75
73
|
await writeFile(ghaction, 'TEST')
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
equal(log[0], `Github action file ${tmpDir}/.github/workflows/platformatic-static-workspace-deploy.yml found, skipping creation of github action file.`)
|
|
74
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
75
|
+
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
79
76
|
})
|
|
80
77
|
|
|
81
78
|
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
79
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
80
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
85
81
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
86
82
|
equal(accessible, true)
|
|
87
83
|
equal(log[1], 'No git repository found. The Github action won\'t be triggered.')
|
|
@@ -89,20 +85,9 @@ test('creates gh action with a warn if a .git folder is not present', async ({ e
|
|
|
89
85
|
|
|
90
86
|
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
91
87
|
await mkdirp(join(tmpDir, '.git'))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
88
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
89
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
95
90
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
96
91
|
equal(accessible, true)
|
|
97
92
|
equal(log.length, 1)
|
|
98
93
|
})
|
|
99
|
-
|
|
100
|
-
test('do not creates gh action if workspace is empty', async ({ end, equal }) => {
|
|
101
|
-
await mkdirp(join(tmpDir, '.git'))
|
|
102
|
-
const workspaceId = ''
|
|
103
|
-
await createStaticWorkspaceGHAction(fakeLogger, workspaceId, env, 'db', tmpDir)
|
|
104
|
-
equal(log[0], 'No workspace ID provided, skipping creation of github action file.')
|
|
105
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
106
|
-
equal(accessible, false)
|
|
107
|
-
equal(log.length, 1)
|
|
108
|
-
})
|
|
@@ -8,10 +8,11 @@ import dotenv from 'dotenv'
|
|
|
8
8
|
import Ajv from 'ajv'
|
|
9
9
|
import { schema } from '@platformatic/service'
|
|
10
10
|
|
|
11
|
+
const base = tmpdir()
|
|
11
12
|
let tmpDir
|
|
12
13
|
let log = []
|
|
13
14
|
beforeEach(() => {
|
|
14
|
-
tmpDir = mkdtempSync(join(
|
|
15
|
+
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
15
16
|
})
|
|
16
17
|
|
|
17
18
|
afterEach(() => {
|
package/test/utils.test.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from 'tap'
|
|
2
2
|
import { randomBetween, sleep, validatePath, getDependencyVersion, findDBConfigFile, findServiceConfigFile, isFileAccessible, isCurrentVersionSupported, minimumSupportedNodeVersions } from '../src/utils.mjs'
|
|
3
3
|
import { mkdtempSync, rmSync, writeFileSync } from 'fs'
|
|
4
|
-
import { tmpdir } from 'os'
|
|
4
|
+
import { tmpdir, platform } from 'os'
|
|
5
5
|
import { join } from 'path'
|
|
6
6
|
import esmock from 'esmock'
|
|
7
7
|
import semver from 'semver'
|
|
@@ -122,7 +122,7 @@ test('validatePath', async ({ end, equal, rejects, ok }) => {
|
|
|
122
122
|
ok(valid)
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
{
|
|
125
|
+
if (platform().indexOf('win') < 0) {
|
|
126
126
|
// not writeable folder
|
|
127
127
|
const valid = await validatePath('/')
|
|
128
128
|
ok(!valid)
|
|
@@ -176,19 +176,13 @@ test('minimumSupportedNodeVersions', async ({ equal, not }) => {
|
|
|
176
176
|
test('isCurrentVersionSupported', async ({ equal }) => {
|
|
177
177
|
const { major, minor, patch } = semver.minVersion(minimumSupportedNodeVersions[0])
|
|
178
178
|
{
|
|
179
|
-
//
|
|
179
|
+
// major - 1 not supported
|
|
180
180
|
const nodeVersion = `${major - 1}.${minor}.${patch}`
|
|
181
181
|
const supported = isCurrentVersionSupported(nodeVersion)
|
|
182
182
|
equal(supported, false)
|
|
183
183
|
}
|
|
184
184
|
{
|
|
185
|
-
//
|
|
186
|
-
const nodeVersion = `${major + 1}.${minor}.${patch}`
|
|
187
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
188
|
-
equal(supported, false)
|
|
189
|
-
}
|
|
190
|
-
{
|
|
191
|
-
// v16 minor not supported
|
|
185
|
+
// minor - 1 not supported
|
|
192
186
|
const nodeVersion = `${major}.${minor - 1}.${patch}`
|
|
193
187
|
const supported = isCurrentVersionSupported(nodeVersion)
|
|
194
188
|
equal(supported, false)
|
|
@@ -198,29 +192,24 @@ test('isCurrentVersionSupported', async ({ equal }) => {
|
|
|
198
192
|
const supported = isCurrentVersionSupported(`${major}.${minor + 2}.${patch}`)
|
|
199
193
|
equal(supported, true)
|
|
200
194
|
}
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
|
|
196
|
+
// node version 19 test, to check greater and lesser major version
|
|
197
|
+
const { major: major19, minor: minor19, patch: patch19 } = semver.minVersion(minimumSupportedNodeVersions[1])
|
|
203
198
|
{
|
|
204
|
-
//
|
|
205
|
-
const nodeVersion = `${
|
|
199
|
+
// v18.0.0 is not supported
|
|
200
|
+
const nodeVersion = `${major19 - 1}.${minor19}.${patch19}`
|
|
206
201
|
const supported = isCurrentVersionSupported(nodeVersion)
|
|
207
202
|
equal(supported, false)
|
|
208
203
|
}
|
|
209
204
|
{
|
|
210
|
-
//
|
|
211
|
-
const nodeVersion = `${
|
|
212
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
213
|
-
equal(supported, true)
|
|
214
|
-
}
|
|
215
|
-
{
|
|
216
|
-
// v18 minor not supported
|
|
217
|
-
const nodeVersion = `${major18}.${minor18 - 2}.${patch18}`
|
|
205
|
+
// v20 is not supported
|
|
206
|
+
const nodeVersion = `${major19 + 1}.${minor19}.${patch19}`
|
|
218
207
|
const supported = isCurrentVersionSupported(nodeVersion)
|
|
219
208
|
equal(supported, false)
|
|
220
209
|
}
|
|
221
210
|
{
|
|
222
|
-
//
|
|
223
|
-
const supported = isCurrentVersionSupported(`${
|
|
211
|
+
// v19 supported
|
|
212
|
+
const supported = isCurrentVersionSupported(`${major19}.${minor19 + 1}.${patch19}`)
|
|
224
213
|
equal(supported, true)
|
|
225
214
|
}
|
|
226
215
|
for (const version of minimumSupportedNodeVersions) {
|