|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Description: This is a script to make the release process easier |
| 3 | +# Run it with `yarn release:prep` and it will do the following: |
| 4 | +# 1. Check that you have a $GITHUB_TOKEN set and hub installed |
| 5 | +# 2. Update the version of code-server (package.json, docs, etc.) |
| 6 | +# 3. Update the code coverage badge in the README |
| 7 | +# 4. Open a draft PR using the release_template.md and view in browser |
| 8 | +# If you want to perform a dry run of this script run DRY_RUN=1 yarn release:prep |
| 9 | + |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +main() { |
| 13 | + if [ "${DRY_RUN-}" = 1 ]; then |
| 14 | + echo "Performing a dry run..." |
| 15 | + CMD="echo" |
| 16 | + else |
| 17 | + CMD='' |
| 18 | + fi |
| 19 | + |
| 20 | + cd "$(dirname "$0")/../.." |
| 21 | + |
| 22 | + # Check that $GITHUB_TOKEN is set |
| 23 | + if [[ -z ${GITHUB_TOKEN-} ]]; then |
| 24 | + echo "We couldn't find an environment variable under GITHUB_TOKEN." |
| 25 | + echo "This is needed for our scripts that use hub." |
| 26 | + echo -e "See docs regarding GITHUB_TOKEN here under 'GitHub OAuth authentication': https://hub.github.com/hub.1.html" |
| 27 | + exit |
| 28 | + fi |
| 29 | + |
| 30 | + # Check that hub is installed |
| 31 | + if ! command -v hub &>/dev/null; then |
| 32 | + echo "hub could not be found." |
| 33 | + echo "We use this with the release-github-draft.sh and release-github-assets.sh scripts." |
| 34 | + echo -e "See docs here: https://github.com/github/hub#installation" |
| 35 | + exit |
| 36 | + fi |
| 37 | + |
| 38 | + # Check that they have jq installed |
| 39 | + if ! command -v jq &>/dev/null; then |
| 40 | + echo "jq could not be found." |
| 41 | + echo "We use this to parse the package.json and grab the current version of code-server." |
| 42 | + echo -e "See docs here: https://stedolan.github.io/jq/download/" |
| 43 | + exit |
| 44 | + fi |
| 45 | + |
| 46 | + # Check that they have rg installed |
| 47 | + if ! command -v rg &>/dev/null; then |
| 48 | + echo "rg could not be found." |
| 49 | + echo "We use this when updating files across the codebase." |
| 50 | + echo -e "See docs here: https://github.com/BurntSushi/ripgrep#installation" |
| 51 | + exit |
| 52 | + fi |
| 53 | + |
| 54 | + # Check that they have sd installed |
| 55 | + if ! command -v sd &>/dev/null; then |
| 56 | + echo "sd could not be found." |
| 57 | + echo "We use this when updating files across the codebase." |
| 58 | + echo -e "See docs here: https://github.com/chmln/sd#installation" |
| 59 | + exit |
| 60 | + fi |
| 61 | + |
| 62 | + # Check that they have node installed |
| 63 | + if ! command -v node &>/dev/null; then |
| 64 | + echo "node could not be found." |
| 65 | + echo "That's surprising..." |
| 66 | + echo "We use it in this script for getting the package.json version" |
| 67 | + echo -e "See docs here: https://nodejs.org/en/download/" |
| 68 | + exit |
| 69 | + fi |
| 70 | + |
| 71 | + # credit to jakwuh for this solution |
| 72 | + # https://gist.github.com/DarrenN/8c6a5b969481725a4413#gistcomment-1971123 |
| 73 | + CODE_SERVER_CURRENT_VERSION=$(node -pe "require('./package.json').version") |
| 74 | + # Ask which version we should update to |
| 75 | + # In the future, we'll automate this and determine the latest version automatically |
| 76 | + echo "Current version: ${CODE_SERVER_CURRENT_VERSION}" |
| 77 | + # The $'\n' adds a line break. See: https://stackoverflow.com/a/39581815/3015595 |
| 78 | + read -r -p "What version of code-server do you want to update to?"$'\n' CODE_SERVER_VERSION_TO_UPDATE |
| 79 | + |
| 80 | + echo -e "Great! We'll prep a PR for updating to $CODE_SERVER_VERSION_TO_UPDATE\n" |
| 81 | + $CMD rg -g '!yarn.lock' -g '!*.svg' --files-with-matches --fixed-strings "${CODE_SERVER_CURRENT_VERSION}" | $CMD xargs sd "$CODE_SERVER_CURRENT_VERSION" "$CODE_SERVER_VERSION_TO_UPDATE" |
| 82 | + |
| 83 | + # Ensure the tests are passing and code coverage is up-to-date |
| 84 | + echo -e "Running unit tests and updating code coverage...\n" |
| 85 | + $CMD yarn test:unit |
| 86 | + # Updates the Lines badge in the README |
| 87 | + $CMD yarn badges |
| 88 | + # Updates the svg to be green for the badge |
| 89 | + $CMD sd "red.svg" "green.svg" ../../README.md |
| 90 | + |
| 91 | + $CMD git commit -am "chore(release): bump version to $CODE_SERVER_VERSION_TO_UPDATE" |
| 92 | + |
| 93 | + # Note: we need to set upstream as well or the gh pr create step will fail |
| 94 | + # See: https://github.com/cli/cli/issues/575 |
| 95 | + CURRENT_BRANCH=$(git branch | grep '\*' | cut -d' ' -f2-) |
| 96 | + if [[ -z $(git config "branch.${CURRENT_BRANCH}.remote") ]]; then |
| 97 | + echo "Doesn't look like you've pushed this branch to remote" |
| 98 | + echo -e "Pushing now using: git push origin $CURRENT_BRANCH\n" |
| 99 | + # Note: we need to set upstream as well or the gh pr create step will fail |
| 100 | + # See: https://github.com/cli/cli/issues/575 |
| 101 | + echo "Please set the upstream and re-run the script" |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + |
| 105 | + # This runs from the root so that's why we use this path vs. ../../ |
| 106 | + RELEASE_TEMPLATE_STRING=$(cat ./.github/PULL_REQUEST_TEMPLATE/release_template.md) |
| 107 | + |
| 108 | + echo -e "\nOpening a draft PR on GitHub" |
| 109 | + # To read about these flags, visit the docs: https://cli.github.com/manual/gh_pr_create |
| 110 | + $CMD gh pr create --base main --title "release: $CODE_SERVER_VERSION_TO_UPDATE" --body "$RELEASE_TEMPLATE_STRING" --reviewer @cdr/code-server-reviewers --repo cdr/code-server --draft |
| 111 | + |
| 112 | + # Open PR in browser |
| 113 | + $CMD gh pr view --web |
| 114 | +} |
| 115 | + |
| 116 | +main "$@" |
0 commit comments