Skip to content

Commit 21c7480

Browse files
authoredMar 15, 2022
chore: move Code to a submodule (#4990)
* Move Code to a submodule Closes #4901. * Base Code cache on hash and re-enable node_modules cache The current setup appears to only rebuild VS Code if the dependencies change but we need to rebuild it if anything changes. I also re-enabled the commented out node_modules caches. They look like they should work to me with the submodule method. I think the problem occurred because Code itself was being installed in the yarn step.
1 parent 184ef68 commit 21c7480

27 files changed

+171
-1738
lines changed
 

‎.github/workflows/ci.yaml

+63-54
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
steps:
3030
- name: Checkout repo
3131
uses: actions/checkout@v3
32+
with:
33+
fetch-depth: 0
34+
submodules: true
3235

3336
- name: Install Node.js v14
3437
uses: actions/setup-node@v3
@@ -38,21 +41,17 @@ jobs:
3841
- name: Install helm
3942
uses: azure/setup-helm@v1.1
4043

41-
# NOTE@jsjoeio
42-
# disabling this until we can audit the build process
43-
# and the usefulness of this step
44-
# See: https://github.com/coder/code-server/issues/4287
45-
# - name: Fetch dependencies from cache
46-
# id: cache-yarn
47-
# uses: actions/cache@v2
48-
# with:
49-
# path: "**/node_modules"
50-
# key: yarn-build-${{ hashFiles('**/yarn.lock') }}
51-
# restore-keys: |
52-
# yarn-build-
44+
- name: Fetch dependencies from cache
45+
id: cache-yarn
46+
uses: actions/cache@v2
47+
with:
48+
path: "**/node_modules"
49+
key: yarn-build-${{ hashFiles('**/yarn.lock') }}
50+
restore-keys: |
51+
yarn-build-
5352
5453
- name: Install dependencies
55-
# if: steps.cache-yarn.outputs.cache-hit != 'true'
54+
if: steps.cache-yarn.outputs.cache-hit != 'true'
5655
run: yarn --frozen-lockfile
5756

5857
- name: Run yarn fmt
@@ -71,6 +70,9 @@ jobs:
7170
steps:
7271
- name: Checkout repo
7372
uses: actions/checkout@v3
73+
with:
74+
fetch-depth: 0
75+
submodules: true
7476

7577
- name: Install Node.js v14
7678
uses: actions/setup-node@v3
@@ -102,56 +104,49 @@ jobs:
102104
env:
103105
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
104106
steps:
105-
- uses: actions/checkout@v3
107+
- name: Checkout repo
108+
uses: actions/checkout@v3
106109
with:
107110
fetch-depth: 0
111+
submodules: true
108112

109113
- name: Install Node.js v14
110114
uses: actions/setup-node@v3
111115
with:
112116
node-version: "14"
113117

114-
# TODO@Teffen investigate why this omits code-oss-dev/node_modules
115-
# - name: Fetch dependencies from cache
116-
# id: cache-yarn
117-
# uses: actions/cache@v2
118-
# with:
119-
# path: |
120-
# "**/node_modules"
121-
# "**/vendor/modules"
122-
# "**/vendor/modules/code-oss-dev/node_modules"
123-
# key: yarn-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/vendor/yarn.lock') }}
124-
# restore-keys: |
125-
# yarn-build-
118+
- name: Fetch dependencies from cache
119+
id: cache-yarn
120+
uses: actions/cache@v2
121+
with:
122+
path: "**/node_modules"
123+
key: yarn-build-${{ hashFiles('**/yarn.lock') }}
124+
restore-keys: |
125+
yarn-build-
126126
127127
- name: Install dependencies
128-
# if: steps.cache-yarn.outputs.cache-hit != 'true'
128+
if: steps.cache-yarn.outputs.cache-hit != 'true'
129129
run: yarn --frozen-lockfile
130130

131131
- name: Build code-server
132132
run: yarn build
133133

134-
# Parse the hash of the latest commit inside vendor/modules/code-oss-dev
135-
# use this to avoid rebuilding it if nothing changed
136-
# How it works: the `git log` command fetches the hash of the last commit
137-
# that changed a file inside `vendor/modules/code-oss-dev`. If a commit changes any file in there,
138-
# the hash returned will change, and we rebuild vscode. If the hash did not change,
139-
# (for example, a change to `src/` or `docs/`), we reuse the same build as last time.
140-
# This saves a lot of time in CI, as compiling VSCode can take anywhere from 5-10 minutes.
141-
- name: Get latest vendor/modules/code-oss-dev rev
134+
# Get Code's git hash. When this changes it means the content is
135+
# different and we need to rebuild. Use VSCODE_CACHE_VERSION to force a
136+
# rebuild.
137+
- name: Get latest lib/vscode rev
142138
id: vscode-rev
143-
run: echo "::set-output name=rev::$(jq -r '.devDependencies["code-oss-dev"]' vendor/package.json | sed -r 's|.*#(.*)$|\1|')"
139+
run: echo "::set-output name=rev::$(git rev-parse HEAD:./lib/vscode)"
144140

145-
- name: Attempt to fetch vscode build from cache
141+
- name: Fetch Code build from cache
146142
id: cache-vscode-2
147143
uses: actions/cache@v2
148144
with:
149145
path: |
150-
vendor/modules/code-oss-dev/.build
151-
vendor/modules/code-oss-dev/package.json
152-
vendor/modules/code-oss-dev/out-build
153-
vendor/modules/code-oss-dev/out-vscode-reh-web
154-
vendor/modules/code-oss-dev/out-vscode-reh-web-min
146+
lib/vscode/.build
147+
lib/vscode/out-build
148+
lib/vscode/out-vscode-reh-web
149+
lib/vscode/out-vscode-reh-web-min
155150
key: vscode-reh-build-${{ secrets.VSCODE_CACHE_VERSION }}-${{ steps.vscode-rev.outputs.rev }}
156151

157152
- name: Build vscode
@@ -197,7 +192,10 @@ jobs:
197192
if: github.event.pull_request.head.repo.full_name == github.repository
198193
runs-on: ubuntu-latest
199194
steps:
200-
- uses: actions/checkout@v3
195+
- name: Checkout repo
196+
uses: actions/checkout@v3
197+
with:
198+
fetch-depth: 0
201199

202200
- uses: actions/download-artifact@v3
203201
id: download
@@ -226,7 +224,10 @@ jobs:
226224
container: "centos:7"
227225

228226
steps:
229-
- uses: actions/checkout@v3
227+
- name: Checkout repo
228+
uses: actions/checkout@v3
229+
with:
230+
fetch-depth: 0
230231

231232
- name: Install Node.js v14
232233
uses: actions/setup-node@v3
@@ -315,7 +316,10 @@ jobs:
315316
NODE_VERSION: v14.17.4
316317

317318
steps:
318-
- uses: actions/checkout@v3
319+
- name: Checkout repo
320+
uses: actions/checkout@v3
321+
with:
322+
fetch-depth: 0
319323

320324
- name: Install Node.js v14
321325
uses: actions/setup-node@v3
@@ -364,7 +368,10 @@ jobs:
364368
runs-on: macos-latest
365369
timeout-minutes: 15
366370
steps:
367-
- uses: actions/checkout@v3
371+
- name: Checkout repo
372+
uses: actions/checkout@v3
373+
with:
374+
fetch-depth: 0
368375

369376
- name: Install Node.js v14
370377
uses: actions/setup-node@v3
@@ -409,7 +416,11 @@ jobs:
409416
# since VS Code will load faster due to the bundling.
410417
CODE_SERVER_TEST_ENTRY: "./release-packages/code-server-linux-amd64"
411418
steps:
412-
- uses: actions/checkout@v3
419+
- name: Checkout repo
420+
uses: actions/checkout@v3
421+
with:
422+
fetch-depth: 0
423+
submodules: true
413424

414425
- name: Install Node.js v14
415426
uses: actions/setup-node@v3
@@ -446,12 +457,6 @@ jobs:
446457
./test/node_modules/.bin/playwright install-deps
447458
./test/node_modules/.bin/playwright install
448459
449-
# TODO@jsjoeio - remove once we switch to submodules.
450-
- name: Create package.json for testing
451-
run: |
452-
mkdir -p ./vendor/modules/code-oss-dev
453-
echo '{ "version": "test" }' > ./vendor/modules/code-oss-dev/package.json
454-
455460
- name: Run end-to-end tests
456461
run: yarn test:e2e
457462

@@ -468,8 +473,11 @@ jobs:
468473
trivy-scan-repo:
469474
runs-on: ubuntu-20.04
470475
steps:
471-
- name: Checkout code
476+
- name: Checkout repo
472477
uses: actions/checkout@v3
478+
with:
479+
fetch-depth: 0
480+
473481
- name: Run Trivy vulnerability scanner in repo mode
474482
uses: aquasecurity/trivy-action@296212627a1e693efa09c00adc3e03b2ba8edf18
475483
with:
@@ -480,6 +488,7 @@ jobs:
480488
template: "@/contrib/sarif.tpl"
481489
output: "trivy-repo-results.sarif"
482490
severity: "HIGH,CRITICAL"
491+
483492
- name: Upload Trivy scan results to GitHub Security tab
484493
uses: github/codeql-action/upload-sarif@v1
485494
with:

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/vscode"]
2+
path = lib/vscode
3+
url = https://github.com/coder/vscode

‎.prettierrc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ useTabs: false
77

88
overrides:
99
# Attempt to keep VScode's existing code style intact.
10-
- files: "vendor/modules/code-oss-dev/**/*.ts"
10+
- files: "lib/vscode/**/*.ts"
1111
options:
1212
# No limit defined upstream.
1313
printWidth: 10000

‎.tours/contributing.tour

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"description": "Static images and the manifest live here in `src/browser/media` (see the explorer)."
144144
},
145145
{
146-
"directory": "vendor/modules/code-oss-dev",
146+
"directory": "lib/vscode",
147147
"line": 1,
148148
"description": "code-server makes use of VS Code's frontend web/remote support. Most of the modifications implement the remote server since that portion of the code is closed source and not released with VS Code.\n\nWe also have a few bug fixes and have added some features (like client-side extensions). See [https://github.com/coder/code-server/blob/master/docs/CONTRIBUTING.md#modifications-to-vs-code](https://github.com/coder/code-server/blob/master/docs/CONTRIBUTING.md#modifications-to-vs-code) for a list.\n\nWe make an effort to keep the modifications as few as possible."
149149
}

‎ci/build/build-release.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ main() {
1515

1616
source ./ci/lib.sh
1717

18-
VSCODE_SRC_PATH="vendor/modules/code-oss-dev"
19-
VSCODE_OUT_PATH="$RELEASE_PATH/vendor/modules/code-oss-dev"
18+
VSCODE_SRC_PATH="lib/vscode"
19+
VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode"
2020

2121
mkdir -p "$RELEASE_PATH"
2222

@@ -25,7 +25,7 @@ main() {
2525

2626
rsync ./docs/README.md "$RELEASE_PATH"
2727
rsync LICENSE.txt "$RELEASE_PATH"
28-
rsync ./vendor/modules/code-oss-dev/ThirdPartyNotices.txt "$RELEASE_PATH"
28+
rsync ./lib/vscode/ThirdPartyNotices.txt "$RELEASE_PATH"
2929
}
3030

3131
bundle_code_server() {

‎ci/build/build-standalone-release.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ main() {
3333
# HACK: the version of Typescript vscode 1.57 uses in extensions/
3434
# leaves a few stray symlinks. Clean them up so nfpm does not fail.
3535
# Remove this line when its no longer needed.
36-
37-
rm -fr "$RELEASE_PATH/vendor/modules/code-oss-dev/extensions/node_modules/.bin"
36+
rm -fr "$RELEASE_PATH/lib/vscode/extensions/node_modules/.bin"
3837
}
3938

4039
main "$@"

‎ci/build/build-vscode.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Builds vscode into vendor/modules/code-oss-dev/out-vscode.
4+
# Builds vscode into lib/vscode/out-vscode.
55

66
# MINIFY controls whether a minified version of vscode is built.
77
MINIFY=${MINIFY-true}
88

99
main() {
1010
cd "$(dirname "${0}")/../.."
1111

12-
cd vendor/modules/code-oss-dev
12+
cd lib/vscode
1313

1414
# Any platform works since we have our own packaging step (for now).
1515
yarn gulp "vscode-reh-web-linux-x64${MINIFY:+-min}"

‎ci/build/npm-postinstall.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ symlink_asar() {
9090
}
9191

9292
vscode_yarn() {
93-
echo 'Installing vendor dependencies...'
94-
cd vendor/modules/code-oss-dev
93+
echo 'Installing Code dependencies...'
94+
cd lib/vscode
9595
yarn --production --frozen-lockfile
9696

9797
symlink_asar

‎ci/dev/fmt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ main() {
1919
"*.sh"
2020
)
2121
prettier --write --loglevel=warn $(
22-
git ls-files "${prettierExts[@]}" | grep -v "lib/vscode" | grep -v "vendor/modules/code-oss-dev" | grep -v 'helm-chart'
22+
git ls-files "${prettierExts[@]}" | grep -v "lib/vscode" | grep -v 'helm-chart'
2323
)
2424

2525
doctoc --title '# FAQ' docs/FAQ.md > /dev/null

‎ci/dev/lint.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ set -euo pipefail
44
main() {
55
cd "$(dirname "$0")/../.."
66

7-
eslint --max-warnings=0 --fix $(git ls-files "*.ts" "*.tsx" "*.js" | grep -v "vendor/modules/code-oss-dev" | grep -v "lib/vscode")
8-
stylelint $(git ls-files "*.css" | grep -v "vendor/modules/code-oss-dev" | grep -v "lib/vscode")
7+
eslint --max-warnings=0 --fix $(git ls-files "*.ts" "*.tsx" "*.js" | grep -v "lib/vscode")
8+
stylelint $(git ls-files "*.css" | grep -v "lib/vscode")
99
tsc --noEmit --skipLibCheck
10-
shellcheck -e SC2046,SC2164,SC2154,SC1091,SC1090,SC2002 $(git ls-files "*.sh" | grep -v "vendor/modules/code-oss-dev" | grep -v "lib/vscode")
10+
shellcheck -e SC2046,SC2164,SC2154,SC1091,SC1090,SC2002 $(git ls-files "*.sh" | grep -v "lib/vscode")
1111
if command -v helm && helm kubeval --help > /dev/null; then
1212
helm kubeval ci/helm-chart
1313
fi

‎ci/dev/postinstall.sh

+17-35
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,32 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
main() {
5-
cd "$(dirname "$0")/../.."
6-
source ./ci/lib.sh
7-
8-
pushd test
9-
echo "Installing dependencies for $PWD"
10-
yarn install
11-
popd
12-
4+
# Install dependencies in $1.
5+
install-deps() {
136
local args=(install)
147
if [[ ${CI-} ]]; then
158
args+=(--frozen-lockfile)
169
fi
17-
18-
pushd test
19-
echo "Installing dependencies for $PWD"
20-
yarn "${args[@]}"
21-
popd
22-
23-
pushd test/e2e/extensions/test-extension
10+
# If there is no package.json then yarn will look upward and end up installing
11+
# from the root resulting in an infinite loop (this can happen if you have not
12+
# checked out the submodule yet for example).
13+
if [[ ! -f "$1/package.json" ]]; then
14+
echo "$1/package.json is missing; did you run git submodule update --init?"
15+
exit 1
16+
fi
17+
pushd "$1"
2418
echo "Installing dependencies for $PWD"
2519
yarn "${args[@]}"
2620
popd
21+
}
2722

28-
pushd vendor
29-
echo "Installing dependencies for $PWD"
30-
31-
# We install in 'modules' instead of 'node_modules' because VS Code's
32-
# extensions use a webpack config which cannot differentiate between its own
33-
# node_modules and itself being in a directory with the same name.
34-
args+=(--modules-folder modules)
35-
36-
# We ignore scripts because NPM/Yarn's default behavior is to assume that
37-
# devDependencies are not needed, and that even git repo based packages are
38-
# assumed to be compiled. Because the default behavior for VS Code's
39-
# `postinstall` assumes we're also compiled, this needs to be ignored.
40-
args+=(--ignore-scripts)
41-
42-
yarn "${args[@]}"
43-
44-
# Finally, run the vendor `postinstall`
45-
yarn run postinstall
23+
main() {
24+
cd "$(dirname "$0")/../.."
25+
source ./ci/lib.sh
4626

47-
popd
27+
install-deps test
28+
install-deps test/e2e/extensions/test-extension
29+
install-deps lib/vscode
4830
}
4931

5032
main "$@"

0 commit comments

Comments
 (0)
Failed to load comments.