Skip to content

Commit

Permalink
fix: 🐛 gitea-push, after refactor process exit wast ran (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunky13 committed Aug 3, 2021
1 parent 618fb36 commit c3d81da
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
8 changes: 5 additions & 3 deletions binzx/otomi
Expand Up @@ -181,18 +181,20 @@ vars=(
OTOMI_SERVER
OTOMI_TAG
OTOMI_USERNAME
OTOMI_NON_INTERACTIVE
PROFILE
STATIC_COLORS
SHELL
TESTING
TRACE
VERBOSITY
VAULT_TOKEN
)
dump_vars "${vars[@]}"

cat >>$tmp_env <<EOF
OTOMI_CALLER_COMMAND=${BASH_SOURCE[0]##*/}
OTOMI_IN_DOCKER=true
IN_DOCKER=1
EOF

helm_config="$HOME/.config/helm"
Expand Down Expand Up @@ -225,7 +227,7 @@ if [[ $base_dir == *"otomi-core"* ]] || [[ $(pwd) == *"otomi-core"* ]]; then
else
executable="node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm ${stack_dir}/src/otomi.ts --"
fi
echo "OTOMI_DEV=true" >>$tmp_env
echo "OTOMI_DEV=1" >>$tmp_env
fi

check_volume_path() {
Expand Down Expand Up @@ -264,7 +266,7 @@ if [[ $calling_args == 'server'* ]]; then
fi

mkdir -p /tmp/otomi
if [ -n "$OTOMI_IN_DOCKER" ]; then
if [ -n "$IN_DOCKER" ]; then
$cmd
status=$?
elif [[ $calling_args == *'--get-yargs-completions'* ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/common/envalid.ts
Expand Up @@ -12,7 +12,7 @@ const cleanSpec = {
GCLOUD_SERVICE_KEY: json({ default: undefined }),
KUBE_VERSION_OVERRIDE: str({ default: undefined }),
OTOMI_DEV: bool({ default: false }),
OTOMI_IN_DOCKER: bool({ default: false }),
IN_DOCKER: bool({ default: false }),
OTOMI_IN_TERMINAL: bool({ default: true }),
STATIC_COLORS: bool({ default: false }),
TESTING: bool({ default: false }),
Expand Down
19 changes: 10 additions & 9 deletions src/common/gitea-push.ts
Expand Up @@ -3,7 +3,7 @@ import { $, cd, nothrow } from 'zx'
import { terminal } from './debug'
import { env } from './envalid'
import { hfValues } from './hf'
import { waitTillAvailable } from './utils'
import { currDir, waitTillAvailable } from './utils'

export const giteaPush = async (): Promise<void> => {
const debug = terminal('Gitea Push')
Expand All @@ -15,22 +15,23 @@ export const giteaPush = async (): Promise<void> => {
}
const stage = hfVals.charts?.['cert-manager']?.stage === 'staging' ? ' -c http.sslVerify=false' : ' '
debug.log(hfVals.cluster)
const clusterDomain = hfVals.cluster?.domainSuffix ?? debug.error('cluster.domainSuffix is not set')
process.exit(1)
const clusterDomain = hfVals.cluster?.domainSuffix
if (!clusterDomain) {
debug.error('cluster.domainSuffix is not set')
process.exit(1)
}
const giteaUrl = `gitea.${clusterDomain}`

await waitTillAvailable(giteaUrl)

const giteaPassword =
hfVals.charts?.gitea?.adminPassword ?? hfVals.otomi?.adminPassword ?? debug.error('otomi.adminPassword is not set')
process.exit(1)
const giteaPassword = hfVals.charts?.gitea?.adminPassword ?? hfVals.otomi?.adminPassword
const giteaUser = 'otomi-admin'
const giteaOrg = 'otomi'
const giteaRepo = 'values'

const currDir = process.cwd()
const currDirVal = await currDir()

cd(`${env.ENV_DIR}`)
cd(env.ENV_DIR)
try {
if (!existsSync('.git')) {
await $`git init`
Expand Down Expand Up @@ -61,7 +62,7 @@ export const giteaPush = async (): Promise<void> => {
} catch (error) {
debug.error(error)
} finally {
cd(currDir)
cd(currDirVal)
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/common/utils.ts
Expand Up @@ -17,7 +17,6 @@ export const parser = yargs(process.argv.slice(3))
export const getFilename = (path: string): string => fileURLToPath(path).split('/').pop()?.split('.')[0] as string

export interface BasicArguments extends YargsArguments {
inDocker: boolean
logLevel: string
nonInteractive: boolean
skipCleanup: boolean
Expand All @@ -28,7 +27,6 @@ export interface BasicArguments extends YargsArguments {
export const defaultBasicArguments: BasicArguments = {
_: [],
$0: 'defaultBasicArgs',
inDocker: true,
logLevel: 'WARN',
nonInteractive: true,
skipCleanup: false,
Expand Down Expand Up @@ -68,8 +66,11 @@ export const capitalize = (s: string): string =>
.join(' ')) ||
''

export const loadYaml = (path: string): any => {
if (!existsSync(path)) throw new Error(`${path} does not exists`)
export const loadYaml = (path: string, opts?: { noError: boolean }): any => {
if (!existsSync(path)) {
if (opts?.noError) return null
throw new Error(`${path} does not exists`)
}
return load(readFileSync(path, 'utf-8')) as any
}

Expand Down
20 changes: 7 additions & 13 deletions src/common/yargs-opts.ts
Expand Up @@ -113,14 +113,13 @@ export const basicOptions: { [key: string]: Options } = {
verbose: {
alias: 'v',
count: true,
coerce: (val: number) =>
Math.min(
val,
Object.keys(logLevels)
.filter((logLevelVal) => !Number.isNaN(Number(logLevelVal)))
.map(Number)
.reduce((prev, curr) => Math.max(prev, curr)),
),
coerce: (val: number) => {
const ll = Object.keys(logLevels)
.filter((logLevelVal) => !Number.isNaN(Number(logLevelVal)))
.map(Number)
.reduce((prev, curr) => Math.max(prev, curr))
return Math.min(Math.max(val, Number(process.env.VERBOSITY || '0')), ll)
},
},
'non-interactive': {
alias: 'ni',
Expand All @@ -137,11 +136,6 @@ export const basicOptions: { [key: string]: Options } = {
default: false,
hidden: true,
},
inDocker: {
boolean: true,
default: false,
hidden: true,
},
}

export const helmOptions = (parser: Argv): Argv => parser.options(helmOpts)
2 changes: 1 addition & 1 deletion src/otomi.ts
Expand Up @@ -18,7 +18,7 @@ import { basicOptions } from './common/yargs-opts'
const debug = terminal('global')
const terminalScale = 0.75
const isAutoCompletion = process.argv.includes('--get-yargs-completions')
if (!env.OTOMI_IN_DOCKER && !isAutoCompletion) {
if (!env.IN_DOCKER && !isAutoCompletion) {
debug.error(process.argv)
debug.error('Please run this script using the `otomi` entry script')
process.exit(1)
Expand Down

0 comments on commit c3d81da

Please sign in to comment.