Skip to content

Latest commit

 

History

History
190 lines (144 loc) · 6.38 KB

SETUP.md

File metadata and controls

190 lines (144 loc) · 6.38 KB

Cloning manubot-rootstock to create a new manuscript

The process to create a new Manubot manuscript is a bit challenging, because it requires a few steps that are difficult to automate. However, you will only have to perform these steps once for each manuscript. These steps should be performed in a terminal, starting in the directory where you want the manuscript folder be created. Setup is supported on Linux and macOS, but not on Windows.

Configuration

First, you must configure two environment variables (OWNER and REPO). These variables specify the GitHub repository for the manuscript (i.e. https://github.com/OWNER/REPO). Make sure that the case of OWNER matches how your username is displayed on GitHub. In general, assume that all commands in this setup are case-sensitive. Edit the following commands with your manuscript's information:

# GitHub username (change from greenelab)
OWNER=greenelab
# Repository name (change from manubot-rootstock)
REPO=manubot-rootstock

Create repository

Execute the remaining commands verbatim. They do not need to be edited (if the setup works as intended).

Next you must clone greenelab/manubot-rootstock and configure its branches and remotes:

# Clone greenelab/manubot-rootstock
git clone https://github.com/greenelab/manubot-rootstock.git $REPO
cd $REPO

# Configure remotes and branches
git remote add rootstock https://github.com/greenelab/manubot-rootstock.git
git checkout --orphan gh-pages
git rm -r --force .
git commit --allow-empty \
  --message "Initialize empty branch" \
  --message "[ci skip]"
git checkout -b output
git checkout master

# Option A: Set origin URL using its web address
git remote set-url origin https://github.com/$OWNER/$REPO.git
# Option B: If GitHub SSH key access is enabled for OWNER, run the following command instead
git remote set-url origin git@github.com:$OWNER/$REPO.git

Next, you must manually create an empty GitHub repository at https://github.com/new. Make sure to use the same "Owner" and "Repository name" specified above. Do not initialize the repository, other than optionally adding a Description. Next, push your cloned manuscript:

git push --set-upstream origin master
git push --set-upstream origin gh-pages
git push --set-upstream origin output

Continuous integration

Now you must manually enable Travis CI for the new repository at https://travis-ci.org. Click the + sign to "Add New Repository". If you don't see your repository listed, push the "Sync account" button. Finally, flick the repository's switch to enable CI.

Deploy key

Generate a deploy key so Travis CI can write to the repository.

cd ci
ssh-keygen \
  -t rsa \
  -b 4096 \
  -C "travis@travis-ci.com" \
  -N "" \
  -f deploy.key

# For convenience, print the URL to add the public key to GitHub
echo https://github.com/$OWNER/$REPO/settings/keys

Manually add the text of deploy.key.pub (with write access) to GitHub under the repository's deploy key settings (the URL echoed above). Give the key a descriptive title, such as "Travis CI Manubot".

For the next step, you need the Travis command line client installed. This program is a Ruby gem: install it with gem install travis (not apt install travis, which is a different program). After the install, you will need to provide your credentials to login to travis with travis login --org.

travis encrypt-file \
  --repo=$OWNER/$REPO \
  --force \
  deploy.key > travis-encrypt-file.log

ci/travis-encrypt-file.log will contain a line such as:

openssl aes-256-cbc -K $encrypted_8cc93e35fb85_key -iv $encrypted_8cc93e35fb85_iv -in test.key.enc -out test.key -d

ci/deploy.sh must be updated with the random string from this line (i.e. 8cc93e35fb85). The following command automates this substitution.

# Edit ci/deploy.sh with travis secure env variables generated by travis encrypt-file
TRAVIS_ENCRYPT_ID=`python -c "import re; \
  text = open('travis-encrypt-file.log').read(); \
  print(re.search('encrypted_([a-f0-9]+)_key', text).group(1))"`
sed "s/f2f00aaf6402/$TRAVIS_ENCRYPT_ID/g" deploy.sh > tmp && mv -f tmp deploy.sh

Next, limit concurrent Travis CI jobs to ensure previous builds deploy before subsequent ones begin:

travis settings \
  --repo=$OWNER/$REPO \
  maximum_number_of_builds --set 1

The continuous integration configuration is now complete. Clean up:

# Optionally remove untracked files
rm deploy.key
rm travis-encrypt-file.log

# CRITICAL: navigate back to the repository's root directory
cd ..

README updates

Now update README.md files to reference the new repository:

# Perform substitutions
sed "s/greenelab/$OWNER/g" README.md > tmp && mv -f tmp README.md
sed "s/manubot-rootstock/$REPO/g" README.md > tmp && mv -f tmp README.md

# Remove deletable content file
git rm content/02.delete-me.md

Finalize

Run git status or git diff --color-words to check that the following files have unstaged changes:

  • README.md
  • ci/deploy.key.enc
  • ci/deploy.key.pub
  • ci/deploy.sh

If the changes look okay, commit and push:

git add --update
git commit --message "Brand repo to $OWNER/$REPO"
git push origin master

You should be good to go now. A good first step is to modify content/metadata.yaml with the relevant information for your manuscript.

Merging upstream manubot-rootstock changes

This section will describe how to incorporate changes to manubot-rootstock that occurred since initializing your manuscript. You will want to do this if there are new enhancements or bugfixes that you want to incorporate. This process can be difficult, especially if conflicts have arisen, and is recommended only for advanced git users.

First, pull the new commits from manubot-rootstock, but do not automerge:

git pull --no-ff --no-commit rootstock master

If all goes well, there won't be any conflicts. However, if there are conflicts, follow the suggested commands to resolve them.

You can add the changes incrementally using git add --patch. This is helpful to see each upstream change. You may notice changes that effect how items in content are processed. If so, you should edit and stage content files as needed. When there are no longer any unstaged changes, then do git commit.