Scripts to update gh-pages (#1739)

* Create update-gh-pages

* fix: pull from stable branch instead of main

* fix: make script executable

* fix: add scripts/ to CODEOWNERS file

* fix: option to choose upstream branch

* feat: completely refactor the script

* docs<CONTRIBUTING>: document the scripts

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
This commit is contained in:
Harsh Khandeparkar
2020-10-29 02:17:57 +05:30
committed by GitHub
parent 5408467800
commit 099e7e2e1d
4 changed files with 170 additions and 5 deletions

1
.github/CODEOWNERS vendored
View File

@@ -44,6 +44,7 @@
/*.lock @ubliclab/is-maintainers /*.lock @ubliclab/is-maintainers
/Gruntfile.js @publiclab/is-maintainers /Gruntfile.js @publiclab/is-maintainers
/.github/ @publiclab/is-maintainers /.github/ @publiclab/is-maintainers
/scripts/ @publiclab/is-maintainers
# <-- /COMMON TO ALL MAINTAINERS --> # <-- /COMMON TO ALL MAINTAINERS -->
# <-- SPECIFIC MAINTAINERS --> # <-- SPECIFIC MAINTAINERS -->

View File

@@ -17,6 +17,7 @@ Most contribution (we imagine) would be in the form of API-compatible modules, w
* [Ideas](#Contribution-ideas) * [Ideas](#Contribution-ideas)
* [Grunt Tasks](#grunt-tasks) * [Grunt Tasks](#grunt-tasks)
* [UI Helper Methods](#ui-helper-methods) * [UI Helper Methods](#ui-helper-methods)
* [Scripts](#scripts)
**** ****
@@ -374,7 +375,7 @@ module.exports =
We are now using `eslint` and `husky` to help lint and format our code each time we commit. Eslint defines coding standards and helps in cleaning up the code. To run eslint for checking errors globally or within a specific file run: We are now using `eslint` and `husky` to help lint and format our code each time we commit. Eslint defines coding standards and helps in cleaning up the code. To run eslint for checking errors globally or within a specific file run:
``` ```
npx eslint . npx eslint .
npx eslint <file path> npx eslint <file path>
``` ```
@@ -412,15 +413,15 @@ The following command is used for running the tasks: `grunt [task-name]`. Here `
The method returns a scoped `jQuery` object which only searches for elements inside a given scope (a DOM element). The method returns a scoped `jQuery` object which only searches for elements inside a given scope (a DOM element).
To use the method, To use the method,
* import the `scopeSelector` and `scopeSelectorAll` methods from `lib/scopeQuery.js` * import the `scopeSelector` and `scopeSelectorAll` methods from `lib/scopeQuery.js`
* call the methods with scope as a parameter * call the methods with scope as a parameter
```js ```js
var scopeQuery = require('./scopeQuery'); var scopeQuery = require('./scopeQuery');
var $step = scopeQuery.scopeSelector(scope), var $step = scopeQuery.scopeSelector(scope),
$stepAll = scopeQuery.scopeSelectorAll(scope); $stepAll = scopeQuery.scopeSelectorAll(scope);
``` ```
This will return an object with a constructor which returns a `jQuery` object (from inside the scope) but with new `elem` and `elemAll` methods. This will return an object with a constructor which returns a `jQuery` object (from inside the scope) but with new `elem` and `elemAll` methods.
@@ -433,7 +434,7 @@ This will return an object with a constructor which returns a `jQuery` object (f
#### Example #### Example
```js ```js
//The scope is a div element with id=“container“ and there are three divs in it //The scope is a div element with id=“container“ and there are three divs in it
//with ids „1“, „2“, and „3“, and all of them have a „child“ class attribute //with ids „1“, „2“, and „3“, and all of them have a „child“ class attribute
var $step = require('./scopeQuery').scopeSelector(document.getElementById('container')); var $step = require('./scopeQuery').scopeSelector(document.getElementById('container'));
@@ -458,3 +459,23 @@ The following code can be used
$step('query').show().hide(); $step('query').show().hide();
$stepAll('q2').show().hide(); $stepAll('q2').show().hide();
``` ```
## Scripts
The following shell scripts are present in the `scripts/` directory.
- `update-gh-pages`: This script can be used to update the `gh-pages` branch of this repo or a fork.
This script is not meant to be used directly as it runs in the current working directory.
If you run it on your primary local clone, it can **delete** the local changes. This script is made to be used in a github action
or in a temporary directory via another script, such as `update-demo`.
Arguments:
1. Repo(to use as upstream) url in the form username/repo (default: publiclab/image-sequencer) NOTE: Github only
2. Branch to pull from eg: main or stable (default: stable)
3. CNAME URL (default: none)
4. Set the fourth argument to anything to bypass the warning. You will have to set this argument if you want to run this script in another script without needing
user interaction, such as in a github action.
- `update-demo`: A safe, interactive script that can be used to update the `gh-pages` branch of any image-sequencer fork.
This script is safe to use directly because it separately clones the repo in a temporary directory.
Arguments: None since it is a an *interactive* script, ie it asks the user for input.

26
scripts/update-demo Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
scriptsDir=$(realpath $(dirname $0))
echo -ne "Enter the repo to push to in the form username/repo (required): "
read -e pushRepo
echo -ne "Enter repo URL to pull from (upstream) in the form username/repo (default: publiclab/image-sequencer): "
read -e repoInput
echo -ne "Enter branch name (default: stable): "
read -e branchInput
echo -ne "Enter CNAME URL(default: none): "
read -e cnameUrlInput
tempDir=$(mktemp -d)
pushd $tempDir > /dev/null
git clone https://github.com/$pushRepo
pushd image-sequencer > /dev/null
$scriptsDir/update-gh-pages "$repoInput" "$branchInput" "$cnameUrlInput" "no warn"
popd > /dev/null
popd > /dev/null

117
scripts/update-gh-pages Executable file
View File

@@ -0,0 +1,117 @@
#!/bin/bash
set -e # So that nothing wrong is published
warn() {
echo -e "\033[1;31m
------IMPORTANT------
THIS SCRIPT IS NOT MEANT TO BE USED DIRECTLY, PLEASE NEWLY CLONE THE REPO IN A SEPARATE DIRECTORY AND USE THE SCRIPT THERE.
USING THIS SCRIPT IN YOUR MAIN CLONE MAY DELETE YOUR LOCAL CHANGES.
This script is made to be reusable: If you want to manually update the demo, \
use the interactive script \`update-demo\`. This script can also be used in a github action.
You can set the 4th argument to anything to bypass this warning. \
Setting the 4th argument means that the first 3 arguments are also set which means that you know what you are doing (I assume).
------IMPORTANT------
\033[0m"
echo -ne "Do you still want to continue? [Y/n]: "
read -e yN
case $yN in
[yY][eE][sS] | [yY])
;;
*)
exit 0
;;
esac
}
# --- Constants ---
deps="jquery bootstrap imgareaselect gifshot downloadjs selectize font-awesome bootstrap-colorpicker jspdf opencv.js/opencv.js" # A list of node_module dependencies to force commit
# --- Constants ---
# --- Arguments ---
# $1: Repo(to use as upstream) url in the form username/repo (default: publiclab/image-sequencer) NOTE: Github only
# $2: Branch to pull from eg: main or stable (default: stable)
# $3: CNAME URL (default: none)
# $4: Set the fourth argument to anything to bypass the warning.
if [[ "$1" != "" ]];
then
repo=$1
else
repo="publiclab/image-sequencer"
fi
if [[ "$2" != "" ]];
then
branch=$2
else
branch="stable"
fi
if [[ "$3" != "" ]];
then
CNAMEURL=$3
else
CNAMEURL=""
fi
# --- Arguments ---
# --- Main Script ---
if [[ "$4" == "" ]]; # Set a 4th argument to anything to bypass this warning.
then
warn
fi
git checkout gh-pages
git remote add upstream https://github.com/$repo
git fetch upstream
git reset --hard upstream/$branch
echo -e "Running setup script."
npm run setup
echo -e "Building dist files."
grunt production
if [ ! -f CNAME ];
then
echo -e "Creating CNAME"
touch CNAME
fi
echo $CNAMEURL > CNAME
echo -e "Removing unnecessary files."
rm -R docs/
rm -R test/
rm CONTRIBUTING.md
rm index.js
echo -e "Copying important files from src/"
cp src/ui/prepareDynamic.js prepareDynamic.js
echo "Removing src/"
rm -R src/
mkdir -p src/ui/
mv prepareDynamic.js src/ui/prepareDynamic.js
echo -e "git add dist and node_modules dependencies."
git add .
for dep in $deps; # Force add node_modules dependencies
do
git add -f node_modules/$dep
done
git add -f dist/image-sequencer.js
git add -f dist/image-sequencer-ui.js
echo -e "committing and pusing."
git commit --no-verify -m "update"
git push -f
exit 0
# --- Main Script ---