blob: f9f3ce83c076407a650f7e875d3783176c50cf26 [file] [log] [blame]
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -04001#!/usr/bin/env bash
2set -e
Hyang-Ah Hana Kim2dbccbe2020-05-14 01:33:09 -04003
4# Copyright (C) Microsoft Corporation. All rights reserved.
Hana (Hyang-Ah) Kim85e647e2020-06-08 18:29:02 -04005# Modification copyright 2020 The Go Authors. All rights reserved.
Hyang-Ah Hana Kim2dbccbe2020-05-14 01:33:09 -04006# Licensed under the MIT License. See LICENSE in the project root for license information.
7
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -05008usage() {
9 cat <<EOUSAGE
10Usage: $0 [subcommand]
11Available subcommands:
12 help - display this help message.
Rebecca Stambler45540aa2020-06-15 02:32:24 -040013 test - build and test locally. Some tests may fail if vscode is already in use.
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -050014 testlocal - build and test in a locally built container.
15 ci - build and test with headless vscode. Requires Xvfb.
16EOUSAGE
17}
18
19# TODO(hyangah): commands for building docker container and running tests locally with docker run.
20root_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
27setup_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
37go_binaries_info() {
38 echo "**** Go version ****"
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -050039 go version
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -050040 df -h | grep shm
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -050041}
42
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040043run_doc_test() {
Hana (Hyang-Ah) Kim1cd75442022-05-18 09:01:32 -040044 echo "**** Run settings generator ****"
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -050045 go run -C extension ./tools/generate.go -w=false -gopls=true
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040046}
47
48run_test() {
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -050049 pushd .
50 cd "$(root_dir)/extension"
51 echo "**** Test build ****"
52 npm ci
53 npm run compile
54
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040055 echo "**** Run Go tests ****"
56 go test ./...
Hana (Hyang-Ah) Kim1cd75442022-05-18 09:01:32 -040057
58 echo "**** Run test ****"
59 npm run unit-test
60 npm test --silent
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -050061 popd
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -050062}
63
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040064run_lint() {
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -050065 pushd .
66 cd "$(root_dir)/extension"
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040067 echo "**** Run lint ****"
68 npm run lint
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -050069 popd
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040070}
Hana (Hyang-Ah) Kim1cd75442022-05-18 09:01:32 -040071
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -050072run_test_in_docker() {
73 echo "**** Building the docker image ***"
Hana8c699ae2021-02-13 22:00:24 -050074 docker build -t vscode-test-env ${GOVERSION:+ --build-arg GOVERSION="${GOVERSION}"} -f ./build/Dockerfile .
75
Hanaad3a7d22021-01-28 16:41:59 -050076 # For debug tests, we need ptrace.
Hanae04eb102022-02-09 17:07:30 -050077 docker run --cap-add SYS_PTRACE --shm-size=8G --workdir=/workspace -v "$(pwd):/workspace" vscode-test-env ci
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -050078}
79
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +000080prepare_nightly() {
Hana (Hyang-Ah) Kim114da492020-03-19 22:08:43 +000081 # 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) Kimd5854792020-03-18 18:11:05 +000085 local COMMIT=`git log -1 --format=%H`
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -040086 echo "**** Preparing nightly release : ${VER} (${COMMIT}) ***"
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +000087 # Update package.json
Hana (Hyang-Ah) Kimdbc90842024-01-12 15:51:06 -050088 (cat extension/package.json | jq --arg VER "${VER}" '
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +000089.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)" |
Hana5bfc2aa2022-01-21 11:05:07 -050095.contributes.configuration.properties."go.delveConfig".properties.hideSystemGoroutines.default=true
Hana (Hyang-Ah) Kimdbc90842024-01-12 15:51:06 -050096') > /tmp/package.json && cp /tmp/package.json extension/package.json
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +000097
Hana (Hyang-Ah) Kimda0c52a2020-06-17 21:22:08 +000098 # Replace CHANGELOG.md with CHANGELOG.md + Release commit info.
Hana (Hyang-Ah) Kimbd87b3a2024-01-17 16:27:48 -050099 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) Kim14161b82020-05-06 06:49:30 -0400100 # Replace the heading of README.md with the heading for Go Nightly.
Hana (Hyang-Ah) Kim15be9372024-01-17 16:24:28 -0500101 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) Kimda0c52a2020-06-17 21:22:08 +0000102 # Replace src/const.ts with build/nightly/const.ts.
Hana (Hyang-Ah) Kimdbc90842024-01-12 15:51:06 -0500103 cp build/nightly/const.ts extension/src/const.ts
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +0000104}
105
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -0500106main() {
Hana (Hyang-Ah) Kim690cf2e2024-01-05 09:52:33 -0500107 cd "$(root_dir)" # always start to run from the extension source root.
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -0500108 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) Kimdb2b4c52023-07-17 17:02:52 -0400123 run_doc_test
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -0500124 run_test
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -0400125 run_lint
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -0500126 ;;
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +0000127 "prepare_nightly")
128 prepare_nightly
129 ;;
Hana (Hyang-Ah) Kimdb2b4c52023-07-17 17:02:52 -0400130 "test_nightly")
131 setup_virtual_display
132 run_test
133 ;;
Hyang-Ah Hana Kim73eee402020-01-26 23:44:42 -0500134 *)
135 usage
136 exit 2
137 esac
138}
Hana (Hyang-Ah) Kim2c09aca2020-03-18 14:51:09 +0000139main $@