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

How to build executables before semrel publishes new release? #164

Open
1 of 4 tasks
padamstx opened this issue Dec 6, 2022 · 3 comments
Open
1 of 4 tasks

How to build executables before semrel publishes new release? #164

padamstx opened this issue Dec 6, 2022 · 3 comments

Comments

@padamstx
Copy link

padamstx commented Dec 6, 2022

Issue type

  • bug report
  • idea
  • question
  • other

Background

The https://github.com/IBM/openapi-validator project uses semrel-toolkit's multi-semrel command to manage releases within the two packages contained in the project.
We can successfully publish a new release of both packages when the commits indicate a new release is needed.
In addition to the two npm packages that are published on npmjs.com, we also build executables for linux/macos/windows and these executables are published on our github project's "Releases" page as part of the release created by semrel.
The problem is that our build (.travis.yml) is currently set up to build the executables prior to running semrel. This results in executables being published to github that do not reflect the new release that is created by semrel.

Question

What I think we need to do to fix this is to build the executables only AFTER semrel has created the new release and updated package.json with the new version #. But, I'm not sure how to make that happen while using semrel (or multi-semrel).
Any ideas on how to fix this? Any help would be appreciated!

Thanks
Phil

@antongolub
Copy link
Member

antongolub commented Dec 6, 2022

@padamstx,

Seems you're looking for the https://github.com/semantic-release/exec plugin.

{
  "branches": "main",
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    ["@semantic-release/exec", {
      "prepare": "../../build.sh ${nextRelease.version} $(pwd) ...",
    }],
    "@semantic-release/npm",
    "@semantic-release/git",
    ["@semantic-release/github", {
      "assets": ["bin/*"]
    }]
  ]
}

@padamstx
Copy link
Author

padamstx commented Dec 6, 2022

@antongolub Thanks for the tip. Do you know which semrel plugin updates the package.json file with the new release #? I just want to make sure I insert the exec plugin after that is all.
Thanks again for the help!

@antongolub
Copy link
Member

antongolub commented Dec 7, 2022

By default semrel uses the npm plugin for pkg version bumping and publishing.

prepare
https://github.com/semantic-release/npm/blob/master/index.js#L68

async function prepare(pluginConfig, context) {
  const errors = verified ? [] : verifyNpmConfig(pluginConfig);

  setLegacyToken(context);

  try {
    // Reload package.json in case a previous external step updated it
    const pkg = await getPkg(pluginConfig, context);
    if (!verified && pluginConfig.npmPublish !== false && pkg.private !== true) {
      await verifyNpmAuth(npmrc, pkg, context);
    }
  } catch (error) {
    errors.push(...error);
  }

  if (errors.length > 0) {
    throw new AggregateError(errors);
  }

  await prepareNpm(npmrc, pluginConfig, context);
  prepared = true;
}

https://github.com/semantic-release/npm/blob/master/lib/prepare.js#L12

  const versionResult = execa(
    'npm',
    ['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'],
    {
      cwd: basePath,
      env,
      preferLocal: true,
    }
  );

publish
https://github.com/semantic-release/npm/blob/master/lib/publish.js#L23

    logger.log(`Publishing version ${version} to npm registry on dist-tag ${distTag}`);
    const result = execa(
      'npm',
      ['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
      {cwd, env, preferLocal: true}
    );
    result.stdout.pipe(stdout, {end: false});
    result.stderr.pipe(stderr, {end: false});

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

No branches or pull requests

2 participants