|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | +set +x |
| 4 | + |
| 5 | +trap "cd $(pwd -P)" EXIT |
| 6 | +cd "$(dirname $0)" |
| 7 | + |
| 8 | +if [[ $1 == "--help" ]]; then |
| 9 | + echo "usage: $(basename $0) [--release|--tip-of-tree]" |
| 10 | + echo |
| 11 | + echo "Publishes all packages." |
| 12 | + echo |
| 13 | + echo "--release publish @latest version of all packages" |
| 14 | + echo "--tip-of-tree publish @next version of all packages" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +if [[ $# < 1 ]]; then |
| 19 | + echo "Please specify either --release or --tip-of-tree" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]]; then |
| 24 | + echo "ERROR: Cannot publish from branch other then 'master'" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +if ! command -v npm >/dev/null; then |
| 29 | + echo "ERROR: NPM is not found" |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +if [[ (-n $CI) && (-n $NPM_AUTH_TOKEN) && (! -f $HOME/.npmrc) ]]; then |
| 34 | + echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > $HOME/.npmrc |
| 35 | +fi |
| 36 | + |
| 37 | +if ! npm whoami >/dev/null 2>&1; then |
| 38 | + echo "ERROR: NPM failed to log in" |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +UPSTREAM_SHA=$(git ls-remote https://github.com/microsoft/playwright --tags master | cut -f1) |
| 43 | +CURRENT_SHA=$(git rev-parse HEAD) |
| 44 | + |
| 45 | +if [[ "${UPSTREAM_SHA}" != "${CURRENT_SHA}" ]]; then |
| 46 | + echo "REFUSING TO PUBLISH: this is not tip-of-tree" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +cd .. |
| 51 | + |
| 52 | +if [[ $1 == "--release" ]]; then |
| 53 | + if [[ -n $CI ]]; then |
| 54 | + echo "Found \$CI env - cannot publish real release from CI" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + if [[ -n $(git status -s) ]]; then |
| 58 | + echo "ERROR: git status is dirty; some uncommitted changes or untracked files" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + VERSION=$(node -e 'console.log(require("./package.json").version)') |
| 62 | + echo -n "Publish Playwright v${VERSION} (y/N)? " |
| 63 | + read ANSWER |
| 64 | + if [[ "$ANSWER" != "y" ]]; then |
| 65 | + echo "Bailing out." |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + |
| 69 | + npm run clean |
| 70 | + npm publish . |
| 71 | + npm publish packages/playwright-firefox |
| 72 | + npm publish packages/playwright-webkit |
| 73 | + npm publish packages/playwright-chromium |
| 74 | + npm publish packages/playwright |
| 75 | + echo "Done." |
| 76 | +elif [[ $1 == "--tip-of-tree" ]]; then |
| 77 | + if [[ -z $CI ]]; then |
| 78 | + echo "Did not find \$CI env - cannot publish tip-of-tree release not from CI" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + npm run clean |
| 82 | + npm publish . --tag="next" |
| 83 | + npm publish packages/playwright-firefox --tag="next" |
| 84 | + npm publish packages/playwright-webkit --tag="next" |
| 85 | + npm publish packages/playwright-chromium --tag="next" |
| 86 | + npm publish packages/playwright --tag="next" |
| 87 | + echo "Done." |
| 88 | +else |
| 89 | + echo "unknown argument - '$1'" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
0 commit comments