mooltiverse / nyx

The one stop semantic release tool
https://github.com/mooltiverse/nyx
Apache License 2.0
116 stars 8 forks source link

Invalid JSON format of .nyx-state.json produced by the GitHub Action #329

Closed flelli closed 1 month ago

flelli commented 1 month ago

The GitHub Action produces non valid JSON output, like:

{
  "branch": "actions",
  "bump": "minor",
  "configuration": {
    "changelog": {
      "path": "build/CHANGELOG.md",
      "sections": {
        "Added": "^feat$",
        "Fixed": "^fix$"
      },
      "substitutions": {
        "(?m)([A-Z]+-[0-9]+)(?s)": "[#%s](https://example.atlassian.net/browse/%s)"
      }
    },
    "commitMessageConventions": {
      "enabled": [
        "conventionalCommits"
      ],
      "items": {
        "conventionalCommits": {
          "expression": "(?m)^(?\u003ctype\u003e[a-zA-Z0-9_]+)(!)?(\\((?\u003cscope\u003e[a-z ]+)\\))?:( (?\u003ctitle\u003e.+))$(?s).*",
          "bumpExpressions": {
            "major": "(?s)(?m)^[a-zA-Z0-9_]+(!: .*|.*^(BREAKING( |-)CHANGE: )).*",
            "minor": "(?s)(?m)^feat(!{0})(\\([a-z ]+\\))?: (?!.*^(BREAKING( |-)CHANGE: )).*",
            "patch": "(?s)(?m)^fix(!{0})(\\([a-z ]+\\))?: (?!.*^(BREAKING( |-)CHANGE: )).*"
          }
        }
      }
    },
    "directory": "/github/workspace",
    "dryRun": false,
    "git": {
      "remotes": {
        "origin": {
          "authenticationMethod": "USER_PASSWORD",
          "user": "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}",
          "password": "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}"
        }
      }
    },
    "initialVersion": "0.1.0",
    "preset": "extended",
    "releaseAssets": {
      "nyx-changelog-template": {
        ],
        "sha": "8d8f1bd065d6300ad29577fda95c4a43dc073f72"
      }
    ]
  },
  "releaseType": {
    "collapseVersions": true,
    "collapsedVersionQualifier": "internal",
    "description": "{{#fileContent}}build/CHANGELOG.md{{/fileContent}}",
    "gitCommit": "false",
    "gitPush": "false",
    "gitTag": "false",
    "identifiers": [
      {
        "qualifier": "{{#sanitize}}{{branch}}{{/sanitize}}",
        "position": "BUILD"
      },
      {
        "qualifier": "{{#short5}}{{releaseScope.finalCommit}}{{/short5}}",
        "position": "BUILD"
      },
      {
        "qualifier": "{{#timestampYYYYMMDDHHMMSS}}{{timestamp}}{{/timestampYYYYMMDDHHMMSS}}",
        "position": "BUILD"
      }
    ],
    "publish": "false",
    "publishPreRelease": "true",
    "versionRangeFromBranchName": false
  },
  "scheme": "SEMVER",
  "timestamp": 1730308526173,
  "version": "0.17.0-internal.1+actions.852bd.20241030171526",
  "versionBuildMetadata": "actions.852bd.20241030171526",
  "versionMajorNumber": "0",
  "versionMinorNumber": "17",
  "versionPatchNumber": "0",
  "versionPreReleaseIdentifier": "internal.1"
}

THe releaseAssets element is clearly malformed.

flelli commented 1 month ago

After a little investigation the JSON file is actually correct, but at some point during a GitHub Actions pipeline it is modified and a big chunk in the middle of the file is lost.

If uploading the file with an actions/upload-artifact@v4 action the file is ok.

Nonetheless, when the action exits the file is corrupted.

flelli commented 1 month ago

It turns out the GitHub Actions console truncated the file when displaying it but the file is actually correct.

However some values can't be read by com.fasterxml.jackson. For example:

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Numeric value (1730310718000) out of range of int (-2147483648 - 2147483647)
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 281, column: 30] (through reference chain: com.mooltiverse.oss.nyx.state.State["releaseScope"]->com.mooltiverse.oss.nyx.entities.ReleaseScope["commits"]->java.util.ArrayList[0]->com.mooltiverse.oss.nyx.entities.git.Commit["date"])

seems that the date field whose value is 1730308844000 is too big. This seems an issue due to the type of integers used to marshal (in Go) not matching with those used to unmarshal (with Jackson on Java). At a first glance it looks like it's marshalled as unsigned integer and unmarshalled as a signed one.

flelli commented 1 month ago

Forking to https://github.com/mooltiverse/nyx/issues/330 and closing this issue