Skip to content

Commit b7714b6

Browse files
committed
testing gh actions
1 parent f90a76c commit b7714b6

File tree

1 file changed

+16
-11
lines changed
  • packages/portainer-stack-redeploy/src

1 file changed

+16
-11
lines changed

β€Žpackages/portainer-stack-redeploy/src/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
Either,
1010
} from 'effect'
1111
import { equals } from 'effect/Equal'
12-
const { log } = console
1312

1413
const String_UrlHost = Schema.TemplateLiteral(
1514
Schema.Literal('https://', 'http://'),
@@ -40,7 +39,7 @@ const Effect_fetch = (url: string | URL | Request, options?: RequestInit) =>
4039
Effect.tryPromise({
4140
try: () => fetch(url, options),
4241
catch: (error) => {
43-
log(error)
42+
console.error(error)
4443
return error
4544
},
4645
})
@@ -50,21 +49,27 @@ const Effect_responseJson = (response: Response) =>
5049

5150
const Effect_fetchJson = flow(Effect_fetch, Effect.flatMap(Effect_responseJson))
5251

53-
log('⏳ Running Portainer Deploy Script...')
52+
const Effect_logString =
53+
(message: string) =>
54+
<T>(x: T) => {
55+
console.log(message)
56+
return Effect.succeed(x)
57+
}
5458

5559
export const portainerStackRedeploy = async (params: {
5660
host: string
5761
accessToken: string
5862
stackName: string
5963
}) => {
64+
console.log('⏳ Running Portainer Deploy Script...')
65+
6066
const host = pipe(
6167
params.host,
6268
String.trim,
6369
String.replace(/\/$/, ''),
6470
Schema.decodeUnknownEither(String_UrlHost),
6571
Either.getOrThrow,
6672
)
67-
log({ host })
6873

6974
const stack = await pipe(
7075
Effect_fetchJson(`${host}/api/stacks`, {
@@ -79,8 +84,6 @@ export const portainerStackRedeploy = async (params: {
7984
Effect.runPromise,
8085
)
8186

82-
log(`${host}/api/stacks/${stack.Id}?endpointId=${stack.EndpointId}`)
83-
8487
console.log('πŸ”„ Deploying Stack...')
8588
await pipe(
8689
Effect_fetchJson(`${host}/api/stacks/${stack.Id}/file`, {
@@ -89,7 +92,7 @@ export const portainerStackRedeploy = async (params: {
8992
}),
9093
Effect.flatMap(Schema.decodeUnknown(StackFileResponse)),
9194
Effect.map(Struct.get('StackFileContent')),
92-
Effect.tap(Effect.logDebug('Updating Stack...')),
95+
Effect.tap(Effect_logString('πŸ’Ύ Updating Stack...')),
9396
Effect.flatMap((stackFile) =>
9497
Effect_fetchJson(
9598
`${host}/api/stacks/${stack.Id}?endpointId=${stack.EndpointId}`,
@@ -103,7 +106,8 @@ export const portainerStackRedeploy = async (params: {
103106
},
104107
),
105108
),
106-
Effect.tap(Effect.log),
109+
Effect.tap(Effect_logString('πŸ’Ύ Stack updated')),
110+
Effect.tap(Effect_logString('πŸ›‘ Stopping Stack...')),
107111
Effect.flatMap(() =>
108112
Effect_fetchJson(
109113
`${host}/api/stacks/${stack.Id}/stop?endpointId=${stack.EndpointId}`,
@@ -113,7 +117,8 @@ export const portainerStackRedeploy = async (params: {
113117
},
114118
),
115119
),
116-
Effect.tap(Effect.logDebug('Stack stopped')),
120+
Effect.tap(Effect_logString('πŸ›‘ Stack stopped')),
121+
Effect.tap(Effect_logString('πŸš€ Starting Stack...')),
117122
Effect.flatMap(() =>
118123
Effect_fetchJson(
119124
`${host}/api/stacks/${stack.Id}/start?endpointId=${stack.EndpointId}`,
@@ -123,9 +128,9 @@ export const portainerStackRedeploy = async (params: {
123128
},
124129
),
125130
),
126-
Effect.tap(Effect.logDebug('Stack deployed')),
127-
Effect.mapError(Effect.logError),
131+
Effect.tap(Effect_logString('πŸš€ Stack deployed')),
128132
Effect.runPromise,
129133
)
134+
130135
console.log('βœ… Done!')
131136
}

0 commit comments

Comments
Β (0)