Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing (?) feature "allow adding URLs to release assets" #393

Open
kaerbr opened this issue Jun 3, 2022 · 7 comments
Open

Failing (?) feature "allow adding URLs to release assets" #393

kaerbr opened this issue Jun 3, 2022 · 7 comments
Labels

Comments

@kaerbr
Copy link
Contributor

kaerbr commented Jun 3, 2022

Current behavior

As of version 9.3.0 its possible to add urls to assets for linking to docker registry or other artifact storages.
Unfortunately I cant get this feature to work for me.
The URL to be used is given in my .releaserc.yml., but the pipeline fails (see at the bottom of this issue).

If I run the command manually (curl) (copied from the logs):

curl --request POST \
  --url https://gitlab.com/api/v4/projects/36721546/releases \
  --header 'Content-Type: application/json' \
  --header 'PRIVATE-TOKEN: <token>' \
  --data '{
	"tag_name": "v1.0.0",
	"description": "# 1.0.0 (2022-06-03)\n\n\n### Features\n\n* add url to release ([da40fc9](https://zzz/commit/da40c9e1606dc3e27f090ef13f51985bb))\n\n\n\n",
	"assets": {
		"links": [
			{
				"url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md"
			}
		]
	}
}'

I get an error: "error": "assets[links][0][name] is missing" wich is understandable due to the fact that assets:links:name is required if a assets:links:url is given (see here(docs))

Expected behavior

Is there anything in my configuration not correct or is there a bug in this feature?
I tried adding the name variable in my .releaserc.yml but it would not go into the request:

- - "@semantic-release/gitlab"
    - assets:
        - url: https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md
          name: "some name"

Environment

  • semantic-release version: 19.0.2
  • CI environment: gitlab ci with node:lts-alpine base image
  • Plugins used:
    • npm install -g semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 @semantic-release/gitlab@9 @semantic-release/npm@9 @saithodev/semantic-release-backmerge@2
  • semantic-release configuration:
plugins:
  - "@semantic-release/commit-analyzer"
  - "@semantic-release/release-notes-generator"
  - "@semantic-release/changelog"
  #- - "@semantic-release/exec"
  #  - prepareCmd: $CI_PROJECT_DIR/.m2/prepare.sh ${nextRelease.version}
  #    publishCmd: $CI_PROJECT_DIR/.m2/publish.sh
  - - "@semantic-release/git"
    - assets:
        - CHANGELOG.md
        - "**/*pom.xml"
  - - "@semantic-release/gitlab"
    - assets:
        - url: https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md
  # As discussed in this issue: https://github.com/semantic-release/semantic-release/issues/1603 there is no support for GitFlow.
  # If we would like to stick to kinda GitFlow (with prerelease/develop), we will have to use this community plugin or merge back by ourselves.
  - - "@saithodev/semantic-release-backmerge"
    - branches:
        - from: main
          to: prerelease
branches:
  - main
  - +([0-9])?(.{+([0-9]),x}).x
  - name: prerelease
    prerelease: rc
  • CI logs:
[7:53:34 AM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/gitlab"
2022-06-03T07:53:34.910Z semantic-release:gitlab repoId: 'kaerbr/semantic-release-test'
2022-06-03T07:53:34.910Z semantic-release:gitlab release name: 'v1.0.0'
2022-06-03T07:53:34.910Z semantic-release:gitlab release ref: '38320e22e6ea7ac172d1b85a37bc765b2948075d'
2022-06-03T07:53:34.910Z semantic-release:gitlab milestones: undefined
2022-06-03T07:53:34.911Z semantic-release:gitlab url assets: [ { url: 'https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md' } ]
2022-06-03T07:53:34.911Z semantic-release:gitlab globbed assets: []
2022-06-03T07:53:34.912Z semantic-release:gitlab all assets: [ { url: 'https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md' } ]
2022-06-03T07:53:34.913Z semantic-release:gitlab use link from release setting: https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md
2022-06-03T07:53:34.913Z semantic-release:gitlab Create a release for git tag 'v1.0.0' with commit '38320e22e6ea7ac172d1b85a37bc765b2948075d'
2022-06-03T07:53:34.914Z semantic-release:gitlab POST-ing the following JSON to https://gitlab.com/api/v4/projects/kaerbr%2Fsemantic-release-test/releases:
{
  "tag_name": "v1.0.0",
  "description": "# 1.0.0 (2022-06-03)\n\n\n### Features\n\n* add url to release ([da40fc9](https://gitlab.com/kaerbr/semantic-release-test/commit/da40fc9e16a06dbbc3e27f0b90be9f13f51985bb))\n\n\n\n",
  "assets": {
    "links": [
      {
        "url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md"
      }
    ]
  }
}
[7:53:35 AM] [semantic-release] [@semantic-release/gitlab] › ✖  An error occurred while making a request to the GitLab release API:
HTTPError: Response code 400 (Bad Request)
    at Request.<anonymous> (/usr/local/lib/node_modules/@semantic-release/gitlab/node_modules/got/dist/source/as-promise/index.js:118:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_NON_2XX_3XX_RESPONSE',
  timings: {
    start: 1654242814917,
    socket: 1654242814918,
    lookup: 1654242814918,
    connect: 1654242814928,
    secureConnect: 1654242814940,
    upload: 1654242814940,
    response: 1654242815095,
    end: 1654242815096,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 0,
      tcp: 10,
      tls: 12,
      request: 0,
      firstByte: 155,
      download: 1,
      total: 179
    }
  }
}
[7:53:35 AM] [semantic-release] › ✖  Failed step "publish" of plugin "@semantic-release/gitlab"
[7:53:35 AM] [semantic-release] › ✖  An error occurred while running semantic-release: HTTPError: Response code 400 (Bad Request)
    at Request.<anonymous> (/usr/local/lib/node_modules/@semantic-release/gitlab/node_modules/got/dist/source/as-promise/index.js:118:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_NON_2XX_3XX_RESPONSE',
  timings: {
    start: 1654242814917,
    socket: 1654242814918,
    lookup: 1654242814918,
    connect: 1654242814928,
    secureConnect: 1654242814940,
    upload: 1654242814940,
    response: 1654242815095,
    end: 1654242815096,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 0,
      tcp: 10,
      tls: 12,
      request: 0,
      firstByte: 155,
      download: 1,
      total: 179
    }
  },
  pluginName: '@semantic-release/gitlab'
}
@kaerbr
Copy link
Contributor Author

kaerbr commented Jun 3, 2022

Maybe related to #192 ?

@elvis-pereira
Copy link

I'm having the same problem.

Config on .releaserc.js

module.exports = {
  branches: [
    'master',
    {
      name: 'beta',
      prerelease: true
    }
  ],
  plugins: [
    [
      '@semantic-release/commit-analyzer',
      {
        preset: 'conventionalcommits'
      }
    ],
    '@semantic-release/release-notes-generator',
    [
      '@semantic-release/exec',
      {
        publishCmd: 'curl --header \"JOB-TOKEN: $CI_JOB_TOKEN\" --upload-file module.zip $PACKAGE_REGISTRY_URL/$VERSION/pt-BR.zip && curl --header \"JOB-TOKEN: $CI_JOB_TOKEN\" --upload-file core/module.json $PACKAGE_REGISTRY_URL/$VERSION/module.json'
      }
    ],
    [
      '@semantic-release/gitlab',
      {
        failTitle: false,
        assets: [
          {
            url: `${process.env.PACKAGE_REGISTRY_URL}/${process.env.VERSION}/module.zip`
          },
          {
            url: `${process.env.PACKAGE_REGISTRY_URL}/${process.env.VERSION}/module.json`
          }
        ]
      }
    ],
    [
      '@semantic-release/git',
      {
        assets: [
          'package.json',
          'core/module.json'
        ],
        message: 'chore(release): ${nextRelease.version}\n\n${nextRelease.notes}'
      }
    ]
  ]
}

GitLab CI Logs:

[6:47:52 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/gitlab"
2022-06-03T18:47:52.986Z semantic-release:gitlab repoId: 'ElvisPereira/core'
2022-06-03T18:47:52.986Z semantic-release:gitlab release name: 'v1.23.0'
2022-06-03T18:47:52.986Z semantic-release:gitlab release ref: 'e26a1abb6979c4b31157090631c5a062d7895178'
2022-06-03T18:47:52.987Z semantic-release:gitlab milestones: undefined
2022-06-03T18:47:52.987Z semantic-release:gitlab url assets: [ { url: 'https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.zip' }, { url: 'https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.json' } ]
2022-06-03T18:47:52.987Z semantic-release:gitlab globbed assets: []
2022-06-03T18:47:52.988Z semantic-release:gitlab all assets: [ { url: 'https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.zip' }, { url: 'https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.json' } ]
2022-06-03T18:47:52.988Z semantic-release:gitlab use link from release setting: https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.zip
2022-06-03T18:47:52.988Z semantic-release:gitlab use link from release setting: https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.json
2022-06-03T18:47:52.989Z semantic-release:gitlab Create a release for git tag 'v1.23.0' with commit 'e26a1abb6979c4b31157090631c5a062d7895178'
2022-06-03T18:47:52.989Z semantic-release:gitlab POST-ing the following JSON to https://gitlab.com/api/v4/projects/ElvisPereira%2Fcore/releases:
{
  "tag_name": "v1.23.0",
  "description": "# [1.23.0](https://gitlab.com/ElvisPereira/core/compare/v1.22.0...v1.23.0) (2022-06-03)\n\n\n### Features\n\n* some big new feature ([e26a1ab](https://gitlab.com/ElvisPereira/core/commit/e26a1abb6979c4b31157090631c5a062d7895178))\n\n\n\n",
  "assets": {
    "links": [
      {
        "url": "https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.zip"
      },
      {
        "url": "https://gitlab.com/api/v4/projects/<<project-id>>/packages/generic/core/1.23.0/module.json"
      }
    ]
  }
}
[6:47:53 PM] [semantic-release] [@semantic-release/gitlab] › ✖  An error occurred while making a request to the GitLab release API:
HTTPError: Response code 400 (Bad Request)
    at Request.<anonymous> (/builds/ElvisPereira/core/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/as-promise/index.js:118:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_NON_2XX_3XX_RESPONSE',
  timings: {
    start: 1654282072992,
    socket: 1654282072993,
    lookup: 1654282072993,
    connect: 1654282073003,
    secureConnect: 1654282073015,
    upload: 1654282073015,
    response: 1654282073121,
    end: 1654282073122,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 0,
      tcp: 10,
      tls: 12,
      request: 0,
      firstByte: 106,
      download: 1,
      total: 130
    }
  }
}
[6:47:53 PM] [semantic-release] › ✖  Failed step "publish" of plugin "@semantic-release/gitlab"
[6:47:53 PM] [semantic-release] › ✖  An error occurred while running semantic-release: HTTPError: Response code 400 (Bad Request)
    at Request.<anonymous> (/builds/ElvisPereira/core/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/as-promise/index.js:118:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_NON_2XX_3XX_RESPONSE',
  timings: {
    start: 1654282072992,
    socket: 1654282072993,
    lookup: 1654282072993,
    connect: 1654282073003,
    secureConnect: 1654282073015,
    upload: 1654282073015,
    response: 1654282073121,
    end: 1654282073122,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 0,
      tcp: 10,
      tls: 12,
      request: 0,
      firstByte: 106,
      download: 1,
      total: 130
    }
  },
  pluginName: '@semantic-release/gitlab'
}
HTTPError: Response code 400 (Bad Request)
    at Request.<anonymous> (/builds/ElvisPereira/core/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/as-promise/index.js:118:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_NON_2XX_3XX_RESPONSE',
  timings: {
    start: 1654282072992,
    socket: 1654282072993,
    lookup: 1654282072993,
    connect: 1654282073003,
    secureConnect: 1654282073015,
    upload: 1654282073015,
    response: 1654282073121,
    end: 1654282073122,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 0,
      tcp: 10,
      tls: 12,
      request: 0,
      firstByte: 106,
      download: 1,
      total: 130
    }
  },
  pluginName: '@semantic-release/gitlab'
}

@fgreinacher
Copy link
Contributor

@awcjack Could you check this?

@kaerbr
Copy link
Contributor Author

kaerbr commented Jun 4, 2022

Edited!:

So I did some more research/debugging. The underlying problem is the following:

If I only specify url in my assets object:

{"url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md"}

the call to the releases api of gitlab will only contain url. Thus there will be an error from the gitlab api ( name is also required for a link (see docs))

So the solution is to always add a label per link (this should fix it for you too @elvis-pereira (: ). like this:

{
  "url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md",
  "label": "README.md"
}

I think the README.md should be improved to make it more clear. (:

But also thanks for this superb project! (:

@elvis-pereira
Copy link

@kaerbr is right, adding a label fixed the pipeline and a release was successfully created.

@awcjack
Copy link
Contributor

awcjack commented Jun 8, 2022

Edited!:

So I did some more research/debugging. The underlying problem is the following:

If I only specify url in my assets object:

{"url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md"}

the call to the releases api of gitlab will only contain url. Thus there will be an error from the gitlab api ( name is also required for a link (see docs))

So the solution is to always add a label per link (this should fix it for you too @elvis-pereira (: ). like this:

{
  "url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md",
  "label": "README.md"
}

I think the README.md should be improved to make it more clear. (:

But also thanks for this superb project! (:

Thanks for the investigation. 👍

@renestalder
Copy link

Is it possible that this error currently also exist for path assets, even though a label is set? At least, I can't really make the assets defined by a path work. I also get a ERR_NON_2XX_3XX_RESPONSE error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants