Skip to content

tools: remove bashisms from release script - #36123

Closed
aduh95 wants to merge 0 commit into
nodejs:masterfrom
aduh95:release-script-bashisms
Closed

tools: remove bashisms from release script#36123
aduh95 wants to merge 0 commit into
nodejs:masterfrom
aduh95:release-script-bashisms

Conversation

@aduh95

Copy link
Copy Markdown
Contributor

In preparation for #36099.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@aduh95
aduh95force-pushed the release-script-bashisms branch from b14fde0 to 2f9d621CompareNovember 14, 2020 18:52
@nodejs-github-botnodejs-github-bot added the tools Issues and PRs related to the tools directory. label Nov 14, 2020
@aduh95aduh95 mentioned this pull request Nov 14, 2020
8 tasks
Comment threadtools/release.sh Outdated
Comment threadtools/release.sh Outdated
Comment threadtools/release.sh Outdated
Comment threadtools/release.sh Outdated
Comment threadtools/release.sh Outdated
@benjamingr

Copy link
Copy Markdown
Member

@aduh95 note that shells are weird (feel free to ignore if you already know all this):

  • Shells decide how many arguments a command gets based on spaces - shells split the command based on spaces (assuming "IFS" is not defined) and then pass them as arguments. The reason stuff is usually put in double quotes is to prevent this. This is called word splitting.
  • Usually $foo and ${foo} mean the exact same thing. The reason you do "$foo" is to avoid the word-splitting mentioned above (so that it doesn't become several arguments if it contains a space). See parameter expansion. There are cases you need to do ${foo} e.g. arrays or if you want to do substitutions.
  • test and []s are just aliases and are called the classic test command, an if just looks at exit code so when you have a command returning an exit code it can be avoided. In general conditional expressions are better.

Personally I would avoid bash for pretty much anything and rewrite this code in Node or Python ^^

@aduh95

Copy link
Copy Markdown
ContributorAuthor

@codebytere may I ask you to use next week release as a test for those changes? I mean, if the code does look good to you of course.

@aduh95aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. review wanted PRs that need reviews. labels Dec 2, 2020
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 2, 2020
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

Copy link
Copy Markdown
ContributorAuthor

@nodejs/build just a heads up if anyone wants to review or block this before it lands, otherwise I'm planning to merge this later this week.

Comment threadtools/release.sh Outdated
Comment threadtools/release.sh Outdated
Comment threadtools/release.sh Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are integer expressions posix?

If they are (I think so) - this [ -z "${keynum##*[!0-9]*}" ] || [ "$keynum" -le 0 ] || [ "$keynum" -gt "$keycount" ] can probably be ((keynum > keycount)) (since keycount is known to be an int)

@aduh95aduh95Dec 2, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum are you sure? If keynum is not a number, it won't be true:

$ keycount = 3
$ keynum="test"
$ (( keynum > keycount ))&&echo"true"
$ (( keynum > keycount ))||echo"false"false

Also we have to take in consideration the case where the user provides 0 (the numbering starts at 1).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then probably just the first two bits can be ((keynum > 0)) ?

@aduh95aduh95Dec 3, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that the behaviour is kind of surprising if keynum is not digits-only:

$ sh -c "keynum=;((keynum > 0)) || echo 'false'"# false, as expectedfalse
$ sh -c "keynum=1;((keynum > 0)) || echo 'false'"# true, as expected
$ sh -c "keynum="12d";((keynum > 0)) || echo 'false'"# false, but prints a warning to stderrsh: ((: 12d: value too great for base (error token is "12d")false
$ sh -c "keynum="0xa";((keynum > 0)) || echo 'false'"# true, expected false

Comment threadtools/release.sh Outdated
@aduh95aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 3, 2020
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 3, 2020
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

aduh95 added a commit to aduh95/node that referenced this pull request Dec 4, 2020
PR-URL: nodejs#36123
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@aduh95aduh95 closed this Dec 4, 2020
@aduh95
aduh95force-pushed the release-script-bashisms branch from defaf0d to 1729ba7CompareDecember 4, 2020 22:55
@aduh95

Copy link
Copy Markdown
ContributorAuthor

Landed in 1729ba7

@aduh95
aduh95 deleted the release-script-bashisms branch December 4, 2020 22:56
danielleadams pushed a commit that referenced this pull request Dec 7, 2020
PR-URL: #36123
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@danielleadamsdanielleadams mentioned this pull request Dec 7, 2020
@BethGriggs

Copy link
Copy Markdown
Member

I think this PR has introduced some problems with the tools/release.sh script. I was unable to promote #36476 with this version of the script.

I run the script with ./tools/release.sh -i <key>, and I get the following output after selecting the key:

Select a key: 1
gpg: error reading key: No public key
<!--lint disable no-literal-urls-->
<p align="center">
<a href="https://nodejs.org/">
<img
alt="Node.js"
src="https://nodejs.org/static/images/logo-light.svg"
width="400"
/>
</a>
</p>
Node.js is an open-source, cross-platform, JavaScript runtime environment. It
executes JavaScript code outside of a browser. For more information on using
Node.js, see the [Node.js Website][].
... # Node.js README output continued
# Checking for releases ...
Warning: Identity file <key1> not accessible: No such file or directory.
no such identity: <key2>: No such file or directory
dist@direct.nodejs.org's password: 

I'll possibly open a revert PR prior to the next releases going out, but will hold off in case there's a quick/easy fix.

/cc @nodejs/releasers

@aduh95aduh95 mentioned this pull request Dec 16, 2020
2 tasks
@rvagg

Copy link
Copy Markdown
Member

+1 to revert. I've tried to look over 1729ba7 for obvious problems but it's far too heavy-handed for the brainpower I have available for this. This whole "remove bashisms" is silliness IMO and is primarily an exercise in introducing churn and risk (stability, security, and other) because the nature of Bash is to be obscure when terse, which you can see on display in 1729ba7.

@MylesBorins

Copy link
Copy Markdown
Contributor

@rvagg we have an open PR that seems to fix the problems. I think it might be reasonable to land that change, see if it fixes things, and then move to revert if we find other regressions

Thoughts?

nodejs-github-bot pushed a commit that referenced this pull request Dec 17, 2020
PR-URL: #36540
Refs: #36123
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
targos pushed a commit that referenced this pull request Dec 21, 2020
PR-URL: #36540
Refs: #36123
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
targos pushed a commit that referenced this pull request May 1, 2021
PR-URL: #36123
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
targos pushed a commit that referenced this pull request May 1, 2021
PR-URL: #36540
Refs: #36123
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
@danielleadamsdanielleadams mentioned this pull request May 3, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.review wantedPRs that need reviews.toolsIssues and PRs related to the tools directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@aduh95@benjamingr@nodejs-github-bot@BethGriggs@rvagg@MylesBorins@ExE-Boss