@@ -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+ }
0 commit comments