Skip to content

Commit

Permalink
Merge pull request #996 from cloud-pi-native/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
this-is-tobi authored Mar 18, 2024
2 parents 50550cc + 3320539 commit eb04063
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 59 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Get lowercase branch name
id: lower-branch
run: |
echo "LOWER_BRANCH=$(echo '${{ github.head_ref }}' | sed 's/\//-/g' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
echo "LOWER_BRANCH=$(echo '${{ github.head_ref || github.ref_name }}' | sed 's/\//-/g' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
build:
name: Build application
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.images.name }}
name: digests-${{ matrix.images.name }}-${{ inputs.MULTI_ARCH && inputs.USE_QEMU && 'multiarch' || (contains(runner.arch, 'ARM') && 'arm64' || 'amd64') }}
path: /tmp/digests/${{ matrix.images.name }}/*
if-no-files-found: error
retention-days: 1
Expand All @@ -160,11 +160,12 @@ jobs:
matrix:
images: ${{ fromJSON(needs.matrix.outputs.build-matrix) }}
steps:
- name: Download digests
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: digests-${{ matrix.images.name }}
pattern: digests-${{ matrix.images.name }}-*
path: /tmp/digests/${{ matrix.images.name }}
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
git fetch
git checkout "$BRANCH"
VERSION=$(jq -r .version package.json)
for pkg in $(jq -r '.app | map(.path + "/package.json") | .[]' < ./ci/matrix-npm.json); do
for pkg in $(jq -r '.apps | map(.path + "/package.json") | .[]' < ./ci/matrix-npm.json); do
yq e -i ".version |= \"$VERSION\"" $pkg
yq e -i ".publishConfig.tag |= \"latest\"" $pkg
done
Expand Down
7 changes: 5 additions & 2 deletions apps/server/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export const initPm = async () => {
const moduleAbsPath = `${pluginsDir}/${dirName}`
try {
statSync(`${moduleAbsPath}/package.json`)
const module = await import(moduleAbsPath) as {plugin: Plugin}
pm.register(module.plugin)
const pkg = await import(`${moduleAbsPath}/package.json`, { assert: { type: 'json' } })
const entrypoint = pkg.default.module || pkg.default.main
if (!entrypoint) throw new Error(`No entrypoint found in package.json : ${pkg.default.name}`)
const { plugin } = await import(`${moduleAbsPath}/${entrypoint}`) as { plugin: Plugin }
pm.register(plugin)
} catch (error) {
console.error(`Could not import module ${moduleAbsPath}`)
console.error(error.stack)
Expand Down
1 change: 1 addition & 0 deletions packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as hooks from './hooks/index.js'
import { type ServiceInfos, servicesInfos } from './services.js'
import { Monitor } from '@cpn-console/shared'
import { HookStepsNames, StepCall } from './hooks/hook.js'
export * from './utils/logger.js'

export type HookChoice = keyof typeof hooks

Expand Down
11 changes: 11 additions & 0 deletions packages/hooks/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const parseError = (error: unknown) => {
if (error instanceof Error) {
Object.defineProperty(error, 'stack', {
enumerable: true,
})
Object.defineProperty(error, 'message', {
enumerable: true,
})
}
return JSON.stringify(error)
}
6 changes: 3 additions & 3 deletions plugins/argocd/src/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { V1Secret } from '@kubernetes/client-node'
import type { StepCall, ClusterObject, CreateClusterExecArgs, DeleteClusterExecArgs } from '@cpn-console/hooks'
import { type StepCall, type ClusterObject, type CreateClusterExecArgs, type DeleteClusterExecArgs, parseError } from '@cpn-console/hooks'
import { getConfig, getK8sApi } from './utils.js'

export const createCluster: StepCall<CreateClusterExecArgs> = async (payload) => {
Expand All @@ -14,11 +14,11 @@ export const createCluster: StepCall<CreateClusterExecArgs> = async (payload) =>
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed create/update cluster secret',
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -37,11 +37,11 @@ export const deleteCluster: StepCall<DeleteClusterExecArgs> = async (payload) =>
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed to delete cluster secret',
},
error: JSON.stringify(error),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/argocd/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EnvironmentCreateArgs, EnvironmentDeleteArgs, PluginResult, StepCall, CreateRepositoryExecArgs, DeleteRepositoryExecArgs } from '@cpn-console/hooks'
import { type EnvironmentCreateArgs, type EnvironmentDeleteArgs, type PluginResult, type StepCall, type CreateRepositoryExecArgs, type DeleteRepositoryExecArgs, parseError } from '@cpn-console/hooks'
import { ArgoDestination, addRepoToApplicationProject, createApplicationProject, deleteApplicationProject } from './app-project.js'
import { createApplication, deleteApplication } from './applications.js'
import { generateAppProjectName, generateApplicationName } from './utils.js'
Expand Down Expand Up @@ -29,11 +29,11 @@ export const newEnv: StepCall<EnvironmentCreateArgs> = async (payload) => {
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Can\'t create env',
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -55,11 +55,11 @@ export const deleteEnv: StepCall<EnvironmentDeleteArgs> = async (payload) => {
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand Down Expand Up @@ -94,11 +94,11 @@ export const newRepo: StepCall<CreateRepositoryExecArgs> = async (payload) => {
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -121,11 +121,11 @@ export const deleteRepo: StepCall<DeleteRepositoryExecArgs> = async (payload) =>
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
4 changes: 2 additions & 2 deletions plugins/argocd/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const getConfig = (): Required<typeof config> => {
}

const getClient = () => {
const kubeconfigCtx = requiredEnv('KUBECONFIG_CTX')
const kubeconfigPath = requiredEnv('KUBECONFIG_PATH')
const kubeconfigCtx = process.env.KUBECONFIG_CTX
const kubeconfigPath = process.env.KUBECONFIG_PATH
const kc = new KubeConfig()
if (kubeconfigPath) {
kc.loadFromFile(kubeconfigPath)
Expand Down
20 changes: 10 additions & 10 deletions plugins/gitlab/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StepCall, AddUserToProjectExecArgs, ArchiveProjectExecArgs, CreateProjectExecArgs, CreateProjectValidateArgs, CreateRepositoryExecArgs, DeleteRepositoryExecArgs, ProjectBase, UpdateRepositoryExecArgs } from '@cpn-console/hooks'
import { generateProjectKey } from '@cpn-console/hooks'
import { generateProjectKey, parseError } from '@cpn-console/hooks'
import { createGroup, deleteGroup, getGroupId, setGroupVariable, setProjectVariable } from './group.js'
import { addGroupMember, getGroupMembers, removeGroupMember } from './permission.js'
import { createGroupToken, createProject, createProjectMirror, deleteProject } from './project.js'
Expand Down Expand Up @@ -29,12 +29,12 @@ export const checkApi: StepCall<CreateProjectValidateArgs> = async (payload) =>
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
// @ts-ignore prévoir une fonction générique
message: error.message,
},
error: JSON.stringify(error),
}
}
}
Expand Down Expand Up @@ -87,12 +87,12 @@ export const createDsoProject: StepCall<CreateProjectExecArgs> = async (payload)
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
// @ts-ignore prévoir une fonction générique
message: error.message,
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -111,11 +111,11 @@ export const archiveDsoProject: StepCall<ArchiveProjectExecArgs> = async (payloa
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand Down Expand Up @@ -166,12 +166,12 @@ export const createDsoRepository: StepCall<CreateRepositoryExecArgs> = async (pa
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
// @ts-ignore prévoir une fonction générique
message: error.message,
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -195,11 +195,11 @@ export const updateDsoRepository: StepCall<UpdateRepositoryExecArgs> = async (pa
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -220,11 +220,11 @@ export const deleteDsoRepository: StepCall<DeleteRepositoryExecArgs> = async (pa
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand Down Expand Up @@ -254,11 +254,11 @@ export const addDsoGroupMember: StepCall<AddUserToProjectExecArgs> = async (payl
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand Down Expand Up @@ -286,11 +286,11 @@ export const removeDsoGroupMember: StepCall<AddUserToProjectExecArgs> = async (p
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
message: 'Failed',
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -310,11 +310,11 @@ export const getDsoProjectSecrets: StepCall<ProjectBase> = async (payload) => {
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'OK',
message: 'No secrets found for this project',
},
error: JSON.stringify(error),
}
}
}
6 changes: 3 additions & 3 deletions plugins/harbor/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getConfig } from './utils.js'
import { createProject, deleteProject } from './project.js'
import { addProjectGroupMember } from './permission.js'
import { createRobot } from './robot.js'
import type { StepCall, ArchiveProjectExecArgs, CreateProjectExecArgs, ProjectBase } from '@cpn-console/hooks'
import { type StepCall, type ArchiveProjectExecArgs, type CreateProjectExecArgs, type ProjectBase, parseError } from '@cpn-console/hooks'

export let axiosOptions: {
baseURL: string;
Expand Down Expand Up @@ -69,12 +69,12 @@ export const createDsoProject: StepCall<CreateProjectExecArgs> = async (payload)
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
// @ts-ignore prévoir une fonction générique
message: error.message,
},
error: JSON.stringify(error),
}
}
}
Expand All @@ -94,12 +94,12 @@ export const archiveDsoProject: StepCall<ArchiveProjectExecArgs> = async (payloa
}
} catch (error) {
return {
error: parseError(error),
status: {
result: 'KO',
// @ts-ignore prévoir une fonction générique
message: error.message,
},
error: JSON.stringify(error),
}
}
}
Expand Down
Loading

0 comments on commit eb04063

Please sign in to comment.