DataDog / datadog-ci

Use Datadog from your CI.
https://datadoghq.com
Apache License 2.0
129 stars 55 forks source link

[deployment] Fix error with `deployment mark` #1441

Closed Drarig29 closed 2 months ago

Drarig29 commented 2 months ago

What and why?

This PR fixes the following error:

Type Error: The "path" argument must be of type string. Received an instance of Object
        at validateString (node:internal/validators:162:11)
        at Object.normalize (node:path:1131:5)
        at readJsonFile (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/helpers/tags.ts:240:25)
        at parseTagsFile (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/helpers/tags.ts:136:23)
        at TagCommand.<anonymous> (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/tag/tag.ts:74:48)
        at Generator.next (<anonymous>)
        at /Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/tag/tag.ts:8:71
        at new Promise (<anonymous>)
        at Object.<anonymous>.__awaiter (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/tag/tag.ts:4:12)
        at TagCommand.execute (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/tag/tag.ts:51:16)
        at DeploymentMarkCommand.<anonymous> (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/deployment/mark.ts:72:55)
        at Generator.next (<anonymous>)
        at /Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/deployment/mark.ts:8:71
        at new Promise (<anonymous>)
        at Object.<anonymous>.__awaiter (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/deployment/mark.ts:4:12)
        at DeploymentMarkCommand.execute (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/src/commands/deployment/mark.ts:37:16)
        at DeploymentMarkCommand.validateAndExecute (/Users/corentin.girard/go/src/github.com/DataDog/datadog-ci.git/master/node_modules/clipanion/lib/advanced/Command.js:73:37)

When running DD_BETA_COMMANDS_ENABLED=1 datadog-ci deployment mark

How?

The validateAndExecute() function in Clipanion is resolving Option.* objects into their final form, just before running execute().

But since DeploymentMarkCommand is not extending from TagCommand but constructing it manually, Clipanion doesn't resolve the option fields. So we end up with this.tagsFile being an object instead of a string.

Review checklist

datadog-datadog-prod-us1[bot] commented 2 months ago

Datadog Report

Branch report: corentin.girard/fix-deployment-mark-command Commit report: 4a13adb Test service: datadog-ci-tests

:white_check_mark: 0 Failed, 28 Passed, 0 Skipped, 23.78s Total duration (3m 3.9s time saved)