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

publisher-electron-release-server: GET await (await authFetch('api/version')).json(); in PublisherERS.ts this call (api/version) has a limit of 30 records. #3430

Closed
3 tasks done
kgallagher52 opened this issue Nov 30, 2023 · 3 comments

Comments

@kgallagher52
Copy link
Contributor

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

7.1.0

Electron version

27.1.2

Operating system

macOS

Last known working Electron Forge version

No response

Expected behavior

When publishing new assets (dmg/zip), the code should create a new version (e.g., 1.0.0_beta) during the creation of the zip if it does not already exist. Then, when running the dmg, it checks for the existence of version 1.0.0_beta. If the version is found, it does not attempt to create it again and proceeds with the distribution of the asset.

Actual behavior

When publishing new assets (dmg/zip), the code should create a new version (e.g., 1.0.0_beta) during the creation of the zip if it does not already exist (in this case it does not). Then, when running the dmg, it checks for the existence of version 1.0.0_beta by hitting the api/version endpoint this should exist because it just got created with the zip but because there is a limit of 30 this version does not get returned on the endpoint so it thinks it has not yet been created and attempts to create the version again causing the Electron Release Server to throw
AdapterError: Would violate uniqueness constraint-- a record already exists with conflicting value(s) so the dmg never gets created.

Steps to reproduce

Create more then 30 versions in your Electron Release Server DB then try to create another version with electron publisher you will see that api/version endpoint will only ever return you 30 records even if you have more.

Additional information

Electron Release Server, specifically the Sails blueprint, only allows a maximum of 30 records to be returned on the endpoint /api/version. The problem with this is when you call:

const versions: ERSVersion[] = await (await authFetch('api/version')).json();
You get back a random 30 records. If you have 30 or more versions that have been created, this poses a problem. If you don't get the version that you are creating, say, 0.0.1_stable, on that /api/version call, it will try to create it again even though it's already been created in the database. It will result in the error:

Error: ERS publish failed with status code: 400 (*** /api/version)
If you look at the Electron Release Server error, it's giving you:

AdapterError: Would violate uniqueness constraint-- a record already exists with conflicting value(s).
Because the record has been created, but because /api/version only returns 30 records, you may not have been given that version on the call, so the check will come back that it does not exist.

Code where the issue is PublishERS.js
const authFetch = (apiPath: string, options?: RequestInit) => fetchAndCheckStatus(api(apiPath), { ...(options || {}), headers: { ...(options || {}).headers, Authorization:Bearer ${token}` } });

const flavor = config.flavor || 'default';

for (const makeResult of makeResults) {
  const { packageJSON } = makeResult;
  const artifacts = makeResult.artifacts.filter((artifactPath) => path.basename(artifactPath).toLowerCase() !== 'releases');

  const versions: ERSVersion[] = await (await authFetch('api/version')).json();
  // Find the version with the same name and flavor
  const existingVersion = versions.find((version) => version.name === packageJSON.version && version.flavor.name === flavor);

  let channel = 'stable';
  if (config.channel) {
    channel = config.channel;
  } else if (packageJSON.version.includes('rc')) {
    channel = 'rc';
  } else if (packageJSON.version.includes('beta')) {
    channel = 'beta';
  } else if (packageJSON.version.includes('alpha')) {
    channel = 'alpha';
  }

  if (!existingVersion) {
    await authFetch('api/version', {
      method: 'POST',
      body: JSON.stringify({
        channel: channel,
        flavor: flavor,
        name: packageJSON.version,
        notes: '',
        id: packageJSON.version + '_' + channel,
      }),
      headers: {
        'Content-Type': 'application/json',
      },
    });
  }`
  
 I have the solution for this https://github.com/kgallagher52/electron-forge-fix-ers
@kgallagher52
Copy link
Contributor Author

PR to fix this #3431

@kgallagher52
Copy link
Contributor Author

This has been merged.

@kgallagher52
Copy link
Contributor Author

@BlackHole1 & @VerteDinde Any update on when this will get released just curious? :)

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

1 participant