Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | set -e |
Hyang-Ah Hana Kim | 2dbccbe | 2020-05-14 01:33:09 -0400 | [diff] [blame] | 3 | |
| 4 | # Copyright (C) Microsoft Corporation. All rights reserved. |
Hana (Hyang-Ah) Kim | 85e647e | 2020-06-08 18:29:02 -0400 | [diff] [blame] | 5 | # Modification copyright 2020 The Go Authors. All rights reserved. |
Hyang-Ah Hana Kim | 2dbccbe | 2020-05-14 01:33:09 -0400 | [diff] [blame] | 6 | # Licensed under the MIT License. See LICENSE in the project root for license information. |
| 7 | |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 8 | usage() { |
| 9 | cat <<EOUSAGE |
| 10 | Usage: $0 [subcommand] |
| 11 | Available subcommands: |
| 12 | help - display this help message. |
Rebecca Stambler | 45540aa | 2020-06-15 02:32:24 -0400 | [diff] [blame] | 13 | test - build and test locally. Some tests may fail if vscode is already in use. |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 14 | testlocal - build and test in a locally built container. |
| 15 | ci - build and test with headless vscode. Requires Xvfb. |
| 16 | EOUSAGE |
| 17 | } |
| 18 | |
| 19 | # TODO(hyangah): commands for building docker container and running tests locally with docker run. |
| 20 | root_dir() { |
| 21 | local script_name=$(readlink -f "${0}") |
| 22 | local script_dir=$(dirname "${script_name}") |
| 23 | local parent_dir=$(dirname "${script_dir}") |
| 24 | echo "${parent_dir}" |
| 25 | } |
| 26 | |
| 27 | setup_virtual_display() { |
| 28 | echo "**** Set up virtual display ****" |
| 29 | # Start xvfb (an in-memory display server for UNIX-like operating system) |
| 30 | # so we can launch a headless vscode for testing. |
| 31 | /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & |
| 32 | trap 'kill "$(jobs -p)"' EXIT |
| 33 | export DISPLAY=:99 |
| 34 | sleep 3 # Wait for xvfb to be up. |
| 35 | } |
| 36 | |
| 37 | go_binaries_info() { |
| 38 | echo "**** Go version ****" |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 39 | go version |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 40 | df -h | grep shm |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 43 | run_doc_test() { |
Hana (Hyang-Ah) Kim | 1cd7544 | 2022-05-18 09:01:32 -0400 | [diff] [blame] | 44 | echo "**** Run settings generator ****" |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 45 | go run -C extension ./tools/generate.go -w=false -gopls=true |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | run_test() { |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 49 | pushd . |
| 50 | cd "$(root_dir)/extension" |
| 51 | echo "**** Test build ****" |
| 52 | npm ci |
| 53 | npm run compile |
| 54 | |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 55 | echo "**** Run Go tests ****" |
| 56 | go test ./... |
Hana (Hyang-Ah) Kim | 1cd7544 | 2022-05-18 09:01:32 -0400 | [diff] [blame] | 57 | |
| 58 | echo "**** Run test ****" |
| 59 | npm run unit-test |
| 60 | npm test --silent |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 61 | popd |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 64 | run_lint() { |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 65 | pushd . |
| 66 | cd "$(root_dir)/extension" |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 67 | echo "**** Run lint ****" |
| 68 | npm run lint |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 69 | popd |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 70 | } |
Hana (Hyang-Ah) Kim | 1cd7544 | 2022-05-18 09:01:32 -0400 | [diff] [blame] | 71 | |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 72 | run_test_in_docker() { |
| 73 | echo "**** Building the docker image ***" |
Hana | 8c699ae | 2021-02-13 22:00:24 -0500 | [diff] [blame] | 74 | docker build -t vscode-test-env ${GOVERSION:+ --build-arg GOVERSION="${GOVERSION}"} -f ./build/Dockerfile . |
| 75 | |
Hana | ad3a7d2 | 2021-01-28 16:41:59 -0500 | [diff] [blame] | 76 | # For debug tests, we need ptrace. |
Hana | e04eb10 | 2022-02-09 17:07:30 -0500 | [diff] [blame] | 77 | docker run --cap-add SYS_PTRACE --shm-size=8G --workdir=/workspace -v "$(pwd):/workspace" vscode-test-env ci |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 80 | prepare_nightly() { |
Hana (Hyang-Ah) Kim | 114da49 | 2020-03-19 22:08:43 +0000 | [diff] [blame] | 81 | # Version format: YYYY.MM.DDHH based on the latest commit timestamp. |
| 82 | # e.g. 2020.1.510 is the version built based on a commit that was made |
| 83 | # on 2020/01/05 10:00 |
| 84 | local VER=`git log -1 --format=%cd --date="format:%Y.%-m.%-d%H"` |
Hana (Hyang-Ah) Kim | d585479 | 2020-03-18 18:11:05 +0000 | [diff] [blame] | 85 | local COMMIT=`git log -1 --format=%H` |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 86 | echo "**** Preparing nightly release : ${VER} (${COMMIT}) ***" |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 87 | # Update package.json |
Hana (Hyang-Ah) Kim | dbc9084 | 2024-01-12 15:51:06 -0500 | [diff] [blame] | 88 | (cat extension/package.json | jq --arg VER "${VER}" ' |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 89 | .version=$VER | |
| 90 | .preview=true | |
| 91 | .name="go-nightly" | |
| 92 | .displayName="Go Nightly" | |
| 93 | .publisher="golang" | |
| 94 | .description="Rich Go language support for Visual Studio Code (Nightly)" | |
Hana | 5bfc2aa | 2022-01-21 11:05:07 -0500 | [diff] [blame] | 95 | .contributes.configuration.properties."go.delveConfig".properties.hideSystemGoroutines.default=true |
Hana (Hyang-Ah) Kim | dbc9084 | 2024-01-12 15:51:06 -0500 | [diff] [blame] | 96 | ') > /tmp/package.json && cp /tmp/package.json extension/package.json |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 97 | |
Hana (Hyang-Ah) Kim | da0c52a | 2020-06-17 21:22:08 +0000 | [diff] [blame] | 98 | # Replace CHANGELOG.md with CHANGELOG.md + Release commit info. |
Hana (Hyang-Ah) Kim | bd87b3a | 2024-01-17 16:27:48 -0500 | [diff] [blame] | 99 | printf "**Release ${VER} @ ${COMMIT}** \n\n" | cat - extension/CHANGELOG.md > /tmp/CHANGELOG.md.new && mv /tmp/CHANGELOG.md.new extension/CHANGELOG.md |
Hana (Hyang-Ah) Kim | 14161b8 | 2020-05-06 06:49:30 -0400 | [diff] [blame] | 100 | # Replace the heading of README.md with the heading for Go Nightly. |
Hana (Hyang-Ah) Kim | 15be937 | 2024-01-17 16:24:28 -0500 | [diff] [blame] | 101 | sed '/^# Go for Visual Studio Code$/d' README.md | cat build/nightly/README.md - > /tmp/README.md.new && mv /tmp/README.md.new README.md |
Hana (Hyang-Ah) Kim | da0c52a | 2020-06-17 21:22:08 +0000 | [diff] [blame] | 102 | # Replace src/const.ts with build/nightly/const.ts. |
Hana (Hyang-Ah) Kim | dbc9084 | 2024-01-12 15:51:06 -0500 | [diff] [blame] | 103 | cp build/nightly/const.ts extension/src/const.ts |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 106 | main() { |
Hana (Hyang-Ah) Kim | 690cf2e | 2024-01-05 09:52:33 -0500 | [diff] [blame] | 107 | cd "$(root_dir)" # always start to run from the extension source root. |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 108 | case "$1" in |
| 109 | "help"|"-h"|"--help") |
| 110 | usage |
| 111 | exit 0 |
| 112 | ;; |
| 113 | "test") |
| 114 | go_binaries_info |
| 115 | run_test |
| 116 | ;; |
| 117 | "testlocal") |
| 118 | run_test_in_docker |
| 119 | ;; |
| 120 | "ci") |
| 121 | go_binaries_info |
| 122 | setup_virtual_display |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 123 | run_doc_test |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 124 | run_test |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 125 | run_lint |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 126 | ;; |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 127 | "prepare_nightly") |
| 128 | prepare_nightly |
| 129 | ;; |
Hana (Hyang-Ah) Kim | db2b4c5 | 2023-07-17 17:02:52 -0400 | [diff] [blame] | 130 | "test_nightly") |
| 131 | setup_virtual_display |
| 132 | run_test |
| 133 | ;; |
Hyang-Ah Hana Kim | 73eee40 | 2020-01-26 23:44:42 -0500 | [diff] [blame] | 134 | *) |
| 135 | usage |
| 136 | exit 2 |
| 137 | esac |
| 138 | } |
Hana (Hyang-Ah) Kim | 2c09aca | 2020-03-18 14:51:09 +0000 | [diff] [blame] | 139 | main $@ |