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

Improve publish script #570

Merged
merged 2 commits into from
Jan 28, 2021
Merged

Improve publish script #570

merged 2 commits into from
Jan 28, 2021

Conversation

pradeepnschrodinger
Copy link
Collaborator

We make use of a shell script (publishPackage.sh) for publishing fixed data table to npm.
The script also bumps up the package version and releases new tags prior to publishing.

I saw a few problems while working on them:

  • Currently, the script always overwrites the latest tag. This'll mean that attempting to publish a new release under v1.0.x using the
    script will lead to the latest tag being overwritten. This should be forbidden since we have v1.1.x.
    Let's fix this by having an option flag passed to the script that overwrites the latest.

  • Entering the next package version exits the script if the version is invalid. Let's re-prompt the user instead.

  • The script does multiple operations that might require authentication. If user fails at authentication, the script just exits, and it becomes difficult to know at which step it had failed. To keep track of it, let's log before such operations.

  • The script for building internal doesn't clear up the internal directory if it already exists. This means, it's possible for the user to publish stale files which might have came up from a previous build, but is no longer needed.

also fix cleaning previous internals directory
@pradeepnschrodinger pradeepnschrodinger changed the title improve publish script with extra flags and logging Improve publish script Jan 5, 2021
@@ -5,12 +5,12 @@
var glob = require('glob');
var path = require('path');
var fs = require('fs');
var rimraf = require('rimraf');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The node file system (fs) package doesn't seem to have a dedicated API to remove non-empty directories (see SO entry).

So let's add rimraf as a dev package which should do the same thing as rm -rf.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we have legal ticket?

set -e

# Defaults that can be overridden in the CLI (except the cookie file)
export BETA=0
export BETA=false
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's make this a boolean flag and avoid passing a value for the flag.
i.e, instead of --beta 1 we can simply use --beta

set -e

# Defaults that can be overridden in the CLI (except the cookie file)
export BETA=0
export BETA=false
export LATEST=false
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If LATEST is true, the script will update and publish the latest tag.

* ) # Invalid flag
echo "Invalid flag: $opt"
exit 192
;;
esac
done

current_version=$(node -p "require('./package').version")
# branch name is required
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Earlier we always pushed under master.
Now that we might run the script from multiple branches like v1.0.x or v.1.1.x, let's have the user specify the upstream branch.

exit 1
fi
# prompt next version
while [ true ]; do
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re-prompt if user enters invalid version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the current behaviour is better. May be we can at max provide couple of more attempts in case of incorrect input but not an infinite retry.

npm publish

echo "Publishing latest tag"
npm publish --tag latest
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not passing --tag defaults it to latest. But I feel passing it explicitly is clearer.

@@ -1,35 +1,70 @@
#!/bin/bash
# example usages:
# ./publishPackage.sh --branch=v1.0.x
# ./publishPackage.sh --branch=v1.1.x --latest
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To run the script through npm, user will have to do:
npm run publish-package -- --branch v1.1.x --latest

The -- immediately after the script name is used for separating the params passed to the npm command itself with the params passed to publishPackage.sh

@wcjordan
Copy link
Member

wcjordan commented Jan 6, 2021

@somavara @mycrobe who should be primary here?

@somavara
Copy link
Collaborator

somavara commented Jan 8, 2021

@somavara @mycrobe who should be primary here?

@wcjordan - I can take this.

@wcjordan
Copy link
Member

wcjordan commented Jan 8, 2021

Great, thank you @somavara !

--branch)
if [ -z $VALUE ] ; then
echo "Please specify branch name"
exit 192
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you review the exit code?

if (!fs.existsSync(internalPath)) {
fs.mkdirSync(internalPath);
}
rimraf.sync(internalPath); // remove older entries
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you check why the file extension ".sh" instead of ".js"?

@pradeepnschrodinger pradeepnschrodinger merged commit 3bd5087 into v1.1.x Jan 28, 2021
@pradeepnschrodinger pradeepnschrodinger deleted the improve-publish-script branch January 28, 2021 08:36
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

Successfully merging this pull request may close these issues.

3 participants