Skip to content

Commit 2897981

Browse files
committed
feat : change printWidth to 120
1 parent eb05111 commit 2897981

File tree

6 files changed

+45
-136
lines changed

6 files changed

+45
-136
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"singleQuote": true,
44
"tabWidth": 2,
55
"trailingComma": "es5",
6-
"printWidth": 80
6+
"printWidth": 120
77
}

src/services/ConfigManager.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core';
22
import * as github from '@actions/github';
3-
import { validateConfig,validateConnectionOptions } from '../utils/validation';
3+
import { validateConfig, validateConnectionOptions } from '../utils/validation';
44
import { Inputs, ConnectionOptions } from '../types';
55
import dotenv from 'dotenv';
66

@@ -19,35 +19,22 @@ export class ConfigManager {
1919
return {
2020
target: process.env.TARGET || core.getInput('target'),
2121
sha: process.env.SHA || core.getInput('sha'),
22-
deploy_branch:
23-
process.env.GITHUB_DEPLOY_BRANCH || core.getInput('deploy_branch'),
22+
deploy_branch: process.env.GITHUB_DEPLOY_BRANCH || core.getInput('deploy_branch'),
2423
envFile: process.env.ENV_FILE || core.getInput('env_file'),
2524
commandScriptBeforeCheckFolders:
26-
process.env.COMMAND_SCRIPT_BEFORE_CHECK_FOLDERS ||
27-
core.getInput('command_script_before_check_folders'),
25+
process.env.COMMAND_SCRIPT_BEFORE_CHECK_FOLDERS || core.getInput('command_script_before_check_folders'),
2826
commandScriptAfterCheckFolders:
29-
process.env.COMMAND_SCRIPT_AFTER_CHECK_FOLDERS ||
30-
core.getInput('command_script_after_check_folders'),
27+
process.env.COMMAND_SCRIPT_AFTER_CHECK_FOLDERS || core.getInput('command_script_after_check_folders'),
3128
commandScriptBeforeDownload:
32-
process.env.COMMAND_SCRIPT_BEFORE_DOWNLOAD ||
33-
core.getInput('command_script_before_download'),
29+
process.env.COMMAND_SCRIPT_BEFORE_DOWNLOAD || core.getInput('command_script_before_download'),
3430
commandScriptAfterDownload:
35-
process.env.COMMAND_SCRIPT_AFTER_DOWNLOAD ||
36-
core.getInput('command_script_after_download'),
31+
process.env.COMMAND_SCRIPT_AFTER_DOWNLOAD || core.getInput('command_script_after_download'),
3732
commandScriptBeforeActivate:
38-
process.env.COMMAND_SCRIPT_BEFORE_ACTIVATE ||
39-
core.getInput('command_script_before_activate'),
33+
process.env.COMMAND_SCRIPT_BEFORE_ACTIVATE || core.getInput('command_script_before_activate'),
4034
commandScriptAfterActivate:
41-
process.env.COMMAND_SCRIPT_AFTER_ACTIVATE ||
42-
core.getInput('command_script_after_activate'),
43-
githubRepoOwner:
44-
process.env.GITHUB_REPO_OWNER ||
45-
github.context.payload.repository?.owner?.login ||
46-
'',
47-
githubRepo:
48-
process.env.GITHUB_REPO ||
49-
github.context.payload.repository?.name ||
50-
'',
35+
process.env.COMMAND_SCRIPT_AFTER_ACTIVATE || core.getInput('command_script_after_activate'),
36+
githubRepoOwner: process.env.GITHUB_REPO_OWNER || github.context.payload.repository?.owner?.login || '',
37+
githubRepo: process.env.GITHUB_REPO || github.context.payload.repository?.name || '',
5138
};
5239
}
5340

@@ -57,10 +44,7 @@ export class ConfigManager {
5744
username: process.env.REMOTE_USERNAME || core.getInput('username'),
5845
port: parseInt(process.env.PORT || core.getInput('port') || '22'),
5946
password: process.env.PASSWORD || core.getInput('password'),
60-
privateKey: (process.env.SSH_KEY || core.getInput('ssh_key')).replace(
61-
/\\n/g,
62-
'\n'
63-
),
47+
privateKey: (process.env.SSH_KEY || core.getInput('ssh_key')).replace(/\\n/g, '\n'),
6448
passphrase: process.env.SSH_PASSPHRASE || core.getInput('ssh_passphrase'),
6549
};
6650
}

src/services/DeploymentService.ts

Lines changed: 26 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ export class DeploymentService {
4646

4747
private async checkSponsorship(githubRepoOwner: string) {
4848
try {
49-
const response = await axios.post(
50-
'https://deployer.flowsahl.com/api/check-github-sponsorship',
51-
{
52-
github_username: githubRepoOwner,
53-
}
54-
);
49+
const response = await axios.post('https://deployer.flowsahl.com/api/check-github-sponsorship', {
50+
github_username: githubRepoOwner,
51+
});
5552
log('Thanks for sponsoring us :)');
5653
} catch (error: any) {
5754
this.handleSponsorshipError(error);
@@ -65,13 +62,9 @@ export class DeploymentService {
6562
'You are not a sponsor. Please consider sponsoring us to use this action: https://github.com/sponsors/FlowSahl. Start sponsoring us and try again [1$ or more].'
6663
);
6764
} else if (error.response.status === 500) {
68-
log(
69-
'An internal server error occurred while checking sponsorship, but the deployment will continue.'
70-
);
65+
log('An internal server error occurred while checking sponsorship, but the deployment will continue.');
7166
} else {
72-
log(
73-
`Sponsorship check failed with status ${error.response.status}: ${error.response.data}`
74-
);
67+
log(`Sponsorship check failed with status ${error.response.status}: ${error.response.data}`);
7568
throw new Error('Sponsorship check failed. Please try again later.');
7669
}
7770
} else {
@@ -82,42 +75,30 @@ export class DeploymentService {
8275

8376
private async prepareDeployment(): Promise<void> {
8477
// 1. Run any user-specified script before checking folders
85-
await this.runOptionalScript(
86-
this.config.getInputs().commandScriptBeforeCheckFolders,
87-
'before check folders'
88-
);
78+
await this.runOptionalScript(this.config.getInputs().commandScriptBeforeCheckFolders, 'before check folders');
8979

9080
// 2. Ensure the necessary folders exist and are clean
9181
log('Preparing deployment directories...');
9282
await this.checkAndPrepareFolders(this.paths);
9383

94-
await this.runOptionalScript(
95-
this.config.getInputs().commandScriptAfterCheckFolders,
96-
'after check folders'
97-
);
98-
84+
await this.runOptionalScript(this.config.getInputs().commandScriptAfterCheckFolders, 'after check folders');
85+
9986
// 3. Clone the repository into the new release directory
10087
log('Cloning repository...');
10188
await this.cloneAndPrepareRepository(this.config.getInputs(), this.paths);
10289

10390
// 4. Sync the environment file if provided
10491
if (this.config.getInputs().envFile) {
10592
log('Syncing environment file...');
106-
await this.syncEnvironmentFile(
107-
this.config.getInputs().envFile ?? '',
108-
this.paths
109-
);
93+
await this.syncEnvironmentFile(this.config.getInputs().envFile ?? '', this.paths);
11094
}
11195

11296
// 5. Link the storage directory to the new release
11397
log('Linking storage...');
11498
await this.linkStorage(this.paths);
11599

116100
// 6. Run any user-specified script after download
117-
await this.runOptionalScript(
118-
this.config.getInputs().commandScriptAfterDownload,
119-
'after download'
120-
);
101+
await this.runOptionalScript(this.config.getInputs().commandScriptAfterDownload, 'after download');
121102
}
122103

123104
private async checkAndPrepareFolders(paths: Paths): Promise<void> {
@@ -134,60 +115,32 @@ export class DeploymentService {
134115
];
135116

136117
await sshOperations.execute(`mkdir -p ${folders.join(' ')}`, paths);
137-
await sshOperations.execute(
138-
`rm -rf ${paths.target}/releases/${paths.sha}`,
139-
paths
140-
);
118+
await sshOperations.execute(`rm -rf ${paths.target}/releases/${paths.sha}`, paths);
141119
}
142120

143-
private async cloneAndPrepareRepository(
144-
inputs: Inputs,
145-
paths: Paths
146-
): Promise<void> {
147-
148-
await this.runOptionalScript(
149-
inputs.commandScriptBeforeDownload,
150-
'before clone'
151-
);
121+
private async cloneAndPrepareRepository(inputs: Inputs, paths: Paths): Promise<void> {
122+
await this.runOptionalScript(inputs.commandScriptBeforeDownload, 'before clone');
152123

153124
const repoUrl = `git@github.com:${inputs.githubRepoOwner}/${inputs.githubRepo}.git`;
154125

155126
await sshOperations.execute(`cd ${paths.target}`, paths);
156127
await sshOperations.execute(`rm -rf ${paths.releasePath}`, paths);
157-
await sshOperations.execute(
158-
`git clone -b ${inputs.deploy_branch} ${repoUrl} ${paths.releasePath}`,
159-
paths
160-
);
128+
await sshOperations.execute(`git clone -b ${inputs.deploy_branch} ${repoUrl} ${paths.releasePath}`, paths);
161129
await sshOperations.execute(`cd ${paths.releasePath}`, paths);
162130
}
163131

164-
private async syncEnvironmentFile(
165-
envFile: string,
166-
paths: Paths
167-
): Promise<void> {
168-
log('Syncing .env file');
169-
170-
await sshOperations.execute(
171-
`echo '${envFile}' > ${paths.target}/.env`,
172-
paths
173-
);
174-
await sshOperations.execute(
175-
`ln -sfn ${paths.target}/.env ${paths.releasePath}/.env`,
176-
paths
177-
);
132+
private async syncEnvironmentFile(envFile: string, paths: Paths): Promise<void> {
133+
log('Syncing .env file');
134+
135+
await sshOperations.execute(`echo '${envFile}' > ${paths.target}/.env`, paths);
136+
await sshOperations.execute(`ln -sfn ${paths.target}/.env ${paths.releasePath}/.env`, paths);
178137
}
179138

180139
private async linkStorage(paths: Paths): Promise<void> {
181-
await sshOperations.execute(
182-
`ln -sfn ${paths.target}/storage ${paths.releasePath}/storage`,
183-
paths
184-
);
140+
await sshOperations.execute(`ln -sfn ${paths.target}/storage ${paths.releasePath}/storage`, paths);
185141
}
186142

187-
private async runOptionalScript(
188-
script: string | undefined,
189-
description: string
190-
): Promise<void> {
143+
private async runOptionalScript(script: string | undefined, description: string): Promise<void> {
191144
if (script && script !== 'false') {
192145
log(`Running script ${description}: ${script}`);
193146
await sshOperations.execute(script, this.paths);
@@ -198,28 +151,16 @@ export class DeploymentService {
198151
log('Activating the new release...');
199152

200153
// 1. Run any user-specified script before activation
201-
await this.runOptionalScript(
202-
this.config.getInputs().commandScriptBeforeActivate,
203-
'before activate'
204-
);
154+
await this.runOptionalScript(this.config.getInputs().commandScriptBeforeActivate, 'before activate');
205155

206156
// 2. Switch the symbolic link to point to the new release
207-
await sshOperations.execute(
208-
`ln -sfn ${this.paths.releasePath} ${this.paths.activeReleasePath}`,
209-
this.paths
210-
);
157+
await sshOperations.execute(`ln -sfn ${this.paths.releasePath} ${this.paths.activeReleasePath}`, this.paths);
211158

212159
// 3. Clean up old releases, keeping the last three
213-
await sshOperations.execute(
214-
`ls -1dt ${this.paths.target}/releases/*/ | tail -n +4 | xargs rm -rf`,
215-
this.paths
216-
);
160+
await sshOperations.execute(`ls -1dt ${this.paths.target}/releases/*/ | tail -n +4 | xargs rm -rf`, this.paths);
217161

218162
// 4. Run any user-specified script after activation
219-
await this.runOptionalScript(
220-
this.config.getInputs().commandScriptAfterActivate,
221-
'after activate'
222-
);
163+
await this.runOptionalScript(this.config.getInputs().commandScriptAfterActivate, 'after activate');
223164
}
224165

225166
private getPaths(target: string, sha: string): Paths {
@@ -230,4 +171,4 @@ export class DeploymentService {
230171
activeReleasePath: `${target}/current`,
231172
};
232173
}
233-
}
174+
}

src/utils/log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConnectionOptions, Inputs } from "../types";
1+
import { ConnectionOptions, Inputs } from '../types';
22

33
export function log(message: string): void {
44
const timestamp = new Date().toISOString();
@@ -10,4 +10,4 @@ export function logInputs(inputs: Inputs, connectionOptions: ConnectionOptions)
1010
log(`Target: ${inputs.target}`);
1111
log(`SHA: ${inputs.sha}`);
1212
log(`GitHub Repo Owner: ${inputs.githubRepoOwner}`);
13-
}
13+
}

src/utils/sshUtils.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import { ConnectionOptions, Paths } from '../types';
55
const ssh = new NodeSSH();
66

77
export const sshOperations = {
8-
async connect({
9-
host,
10-
username,
11-
port,
12-
password,
13-
privateKey,
14-
passphrase,
15-
}: ConnectionOptions): Promise<void> {
8+
async connect({ host, username, port, password, privateKey, passphrase }: ConnectionOptions): Promise<void> {
169
log('Connecting to the server...');
1710

1811
const connectionOptions: ConnectionOptions = {
@@ -36,11 +29,7 @@ export const sshOperations = {
3629
}
3730
},
3831

39-
async execute(
40-
command: string,
41-
paths: Paths,
42-
showCommandLog: boolean = false
43-
): Promise<void> {
32+
async execute(command: string, paths: Paths, showCommandLog: boolean = false): Promise<void> {
4433
try {
4534
command = prepareCommand(command, paths);
4635

@@ -50,12 +39,9 @@ export const sshOperations = {
5039

5140
if (result.stdout) log(result.stdout);
5241
if (result.stderr) console.error(result.stderr);
53-
if (result.code !== 0)
54-
throw new Error(`Command failed: ${command} - ${result.stderr}`);
42+
if (result.code !== 0) throw new Error(`Command failed: ${command} - ${result.stderr}`);
5543
} catch (error: any) {
56-
throw new Error(
57-
`Failed to execute command: ${command} - ${error.message}`
58-
);
44+
throw new Error(`Failed to execute command: ${command} - ${error.message}`);
5945
}
6046
},
6147

src/utils/validation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ export function validateConnectionOptions(connectionOptions: ConnectionOptions)
1111
if (!connectionOptions.username) throw new Error('Username is required.');
1212
if (
1313
connectionOptions.port &&
14-
(isNaN(connectionOptions.port) ||
15-
connectionOptions.port < 1 ||
16-
connectionOptions.port > 65535)
14+
(isNaN(connectionOptions.port) || connectionOptions.port < 1 || connectionOptions.port > 65535)
1715
) {
1816
throw new Error('Port must be a valid number between 1 and 65535.');
1917
}

0 commit comments

Comments
 (0)