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

fix(linux): make semver pre-release versions valid for "pacman" and "rpm" target #7630

Merged
merged 4 commits into from
Jun 27, 2023
Merged

fix(linux): make semver pre-release versions valid for "pacman" and "rpm" target #7630

merged 4 commits into from
Jun 27, 2023

Conversation

m4rch3n1ng
Copy link
Contributor

fix #7601

this replaces all hyphens (-) in versions when targeting "pacman" with underscores (_) to follow the pacman version format.

notes:

  • i am only replacing the version of the package, not of the .pacman file, since doing so would (i think) require overwriting the version in appInfo.version, which is marked as readonly,


    or adding a seperate rule to the macroExpander, which, as far as i can tell, does not have access to the current build target (which could be solved fairly easily with a new optional parameter tho)
    export function expandMacro(pattern: string, arch: string | null | undefined, appInfo: AppInfo, extra: any = {}, isProductNameSanitized = true): string {

    neither of which seemed like a good idea to me, especially without prior feedback.
    it also doesn't matter for pacman and looks more consistent with the other installer files, if unchanged.

  • i am using .replace(/-/g, "_") over .replaceAll("-", "_") since the latter was only added in node v15.0.0 and this package still supports node v14

  • i have a very limited idea on how this codebase is structured so tell me if i should do something differently

@changeset-bot
Copy link

changeset-bot bot commented Jun 24, 2023

🦋 Changeset detected

Latest commit: 316de39

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Jun 24, 2023

Deploy Preview for car-park-attendant-cleat-11576 ready!

Name Link
🔨 Latest commit 316de39
🔍 Latest deploy log https://app.netlify.com/sites/car-park-attendant-cleat-11576/deploys/649b0922b902bc0008e01a19
😎 Deploy Preview https://deploy-preview-7630--car-park-attendant-cleat-11576.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mmaietta
Copy link
Collaborator

Thanks @m4rch3n1ng for the PR! Quick Q, is the _ only for pacman version format or would other distros also make use of this?

@m4rch3n1ng
Copy link
Contributor Author

m4rch3n1ng commented Jun 25, 2023

good call actually @mmaietta, did some quick research.

anyways that's what i found

do tell me how (/ where) you want me to solve this, because a ternary is probably not the best idea lol

@mmaietta
Copy link
Collaborator

Great investigative work!
I tried to find apk but don't seem to have a way to run it locally.

Can you check apk --check 0.0.0_alpha.1_r1 && echo $? If that's a 0, then a ternary on ['apk', 'pacman'].includes(target) may be best? Due to the wide variety of targets, it's hard not to have ternary without a ton of refactoring into subtargets

case "deb":
case "rpm":
case "sh":
case "freebsd":
case "pacman":
case "apk":
case "p5p":
return require("./targets/FpmTarget").default

@m4rch3n1ng
Copy link
Contributor Author

alpine seems to be a lot more annoying than i thought and i literally cannot find any proper specs on their version format apart from this build script
image

i also need to figure out how flatpak does it which is currently annoying me because i can't get it to build for me (it just gives me a stackTrace=Error: flatpak failed with status code 1 and i don't know what the problem is) and i can literally not figure out how to even set a version while manually using flatpak-builder.

my concern with a ternary would be that it would have to be nested

"pacman" == target ? appInfo.version.replace(/-/g, "_") : target === "rpm" ? appInfo.version.replace(/-/g, "~") : appInfo.version

which is ugly and hard to read, so i thought about perhaps doing it in a seperate function with a switch statement? but i wasn't sure where

@m4rch3n1ng
Copy link
Contributor Author

tested some more with alpine and surprisingly it seems to. just work like that? i don't honestly know. can't execute the file because i do not have a gui / display server here and i have no idea what would happen if you were to want to publish it, though to be fair i think it's fair to assume you don't really want to publish your pre-release versions, but it installed correctly as testing-app instead of how pacman did it. it should probably be fine to just leave it as is?

image

@m4rch3n1ng
Copy link
Contributor Author

super unsure on what to do with solaris and flatpak, but i think it should be fine to just fix it for rpm and pacman for now perhaps. if it's just those two i could actually just use a ternary i guess, tho it's still not ideal.

@mmaietta
Copy link
Collaborator

Fantastic debugging work. Thank you

Okay, let's pull a helper function to LinuxTargetHelper.ts (we already leverage it for getDescription). Add this between getDescription and writeDesktopEntry.

  getSantitizedVersion(target: string) {
    const {
      appInfo: { version },
    } = this.packager
    switch (target) {
      case "pacman":
        return version.replace(/-/g, "_")
      case "rpm":
        return version.replace(/-/g, "~")
      default:
        return version
    }
  }

In FpmTarget.ts, called as.

      "--version",
      this.helper.getSantitizedVersion(target),

@m4rch3n1ng m4rch3n1ng changed the title fix(pacman): replace hyphens with underscores in version fix(linux): make semver pre-release versions valid for "pacman" and "rpm" target Jun 27, 2023
@m4rch3n1ng
Copy link
Contributor Author

done

@mmaietta mmaietta merged commit 37db080 into electron-userland:master Jun 27, 2023
13 checks passed
@mmaietta
Copy link
Collaborator

Many thanks for your contribution!

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

Successfully merging this pull request may close these issues.

invalid version for semver pre-releases when targeting "pacman"
2 participants