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

tools: remove bashisms from release script #36123

Closed
wants to merge 0 commits into from

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Nov 14, 2020

In preparation for #36099.

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

@aduh95 aduh95 force-pushed the release-script-bashisms branch from b14fde0 to 2f9d621 Compare November 14, 2020 18:52
@nodejs-github-bot nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Nov 14, 2020
@aduh95 aduh95 mentioned this pull request Nov 14, 2020
8 tasks
tools/release.sh Outdated Show resolved Hide resolved
tools/release.sh Outdated Show resolved Hide resolved
tools/release.sh Outdated Show resolved Hide resolved
tools/release.sh Outdated Show resolved Hide resolved
tools/release.sh Outdated Show resolved Hide resolved
@benjamingr
Copy link
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
Contributor Author

aduh95 commented Nov 19, 2020

@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.

@aduh95 aduh95 requested a review from benjamingr December 2, 2020 18:31
@aduh95 aduh95 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-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 2, 2020
@nodejs-github-bot
Copy link
Collaborator

@aduh95
Copy link
Contributor Author

aduh95 commented Dec 2, 2020

@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.

tools/release.sh Outdated Show resolved Hide resolved
tools/release.sh Outdated Show resolved Hide resolved
tools/release.sh Outdated
fi
fi
keynum=
while [ -z "${keynum##*[!0-9]*}" ] || [ "$keynum" -le 0 ] || [ "$keynum" -gt "$keycount" ]; do
Copy link
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)

Copy link
Contributor Author

@aduh95 aduh95 Dec 2, 2020

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
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)) ?

Copy link
Contributor Author

@aduh95 aduh95 Dec 3, 2020

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 expected
false
$ 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 stderr
sh: ((: 12d: value too great for base (error token is "12d")
false
$ sh -c "keynum="0xa";((keynum > 0)) || echo 'false'" # true, expected false

tools/release.sh Outdated Show resolved Hide resolved
@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 3, 2020
@github-actions github-actions bot 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
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
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>
@aduh95 aduh95 closed this Dec 4, 2020
@aduh95 aduh95 force-pushed the release-script-bashisms branch from defaf0d to 1729ba7 Compare December 4, 2020 22:55
@aduh95
Copy link
Contributor Author

aduh95 commented Dec 4, 2020

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>
@danielleadams danielleadams mentioned this pull request Dec 7, 2020
cjihrig pushed a commit to cjihrig/node that referenced this pull request Dec 8, 2020
PR-URL: nodejs#36123
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@BethGriggs
Copy link
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

@aduh95 aduh95 mentioned this pull request Dec 16, 2020
2 tasks
@rvagg
Copy link
Member

rvagg commented Dec 17, 2020

+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
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>
@danielleadams danielleadams mentioned this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. review wanted PRs that need reviews. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants