|
1 | 1 | #!/bin/bash |
2 | | -set -euo pipefail |
3 | | - |
4 | | -function docker-build() { |
5 | | - local target="${TARGET:-}" |
6 | | - local image="codercom/nbin-${target}" |
7 | | - local token="${GITHUB_TOKEN:-}" |
8 | | - local minify="${MINIFY:-}" |
9 | | - if [[ "${target}" == "linux" ]] ; then |
10 | | - image="codercom/nbin-centos" |
11 | | - fi |
12 | | - |
13 | | - local containerId |
14 | | - # Use a mount so we can cache the results. |
15 | | - containerId=$(docker create --network=host --rm -it -v "$(pwd)":/src "${image}") |
16 | | - docker start "${containerId}" |
17 | | - |
18 | | - # TODO: Might be better to move these dependencies to the images or create new |
19 | | - # ones on top of these. |
20 | | - if [[ "${image}" == "codercom/nbin-alpine" ]] ; then |
21 | | - docker exec "${containerId}" apk add libxkbfile-dev libsecret-dev |
22 | | - else |
23 | | - docker exec "${containerId}" yum install -y libxkbfile-devel libsecret-devel git |
24 | | - fi |
| 2 | +# ci.bash -- Build code-server in the CI. |
25 | 3 |
|
26 | | - function docker-exec() { |
27 | | - local command="${1}" ; shift |
28 | | - local args="'${vscodeVersion}' '${codeServerVersion}'" |
29 | | - docker exec "${containerId}" \ |
30 | | - bash -c "cd /src && CI=true GITHUB_TOKEN=${token} MINIFY=${minify} yarn ${command} ${args}" |
31 | | - } |
32 | | - |
33 | | - docker-exec build |
34 | | - if [[ -n "${package}" ]] ; then |
35 | | - docker-exec binary |
36 | | - docker-exec package |
37 | | - fi |
38 | | - |
39 | | - docker kill "${containerId}" |
40 | | -} |
41 | | - |
42 | | -function local-build() { |
43 | | - function local-exec() { |
44 | | - local command="${1}" ; shift |
45 | | - CI=true yarn "${command}" "${vscodeVersion}" "${codeServerVersion}" |
46 | | - } |
47 | | - |
48 | | - local-exec build |
49 | | - if [[ -n "${package}" ]] ; then |
50 | | - local-exec binary |
51 | | - local-exec package |
52 | | - fi |
53 | | -} |
| 4 | +set -euo pipefail |
54 | 5 |
|
55 | | -# Build code-server in the CI. |
56 | 6 | function main() { |
57 | 7 | cd "$(dirname "${0}")/.." |
58 | 8 |
|
59 | | - local codeServerVersion="${VERSION:-}" |
60 | | - local vscodeVersion="${VSCODE_VERSION:-1.41.1}" |
61 | | - local ostype="${OSTYPE:-}" |
62 | | - local package="${PACKAGE:-}" |
| 9 | + # Get the version information. If a specific version wasn't set, generate it |
| 10 | + # from the tag and VS Code version. |
| 11 | + local vscode_version=${VSCODE_VERSION:-1.41.1} |
| 12 | + local code_server_version=${VERSION:-2.${TRAVIS_TAG:-${DRONE_TAG:-daily}}-vsc$vscode_version} |
63 | 13 |
|
64 | | - if [[ -z "${codeServerVersion}" ]] ; then |
65 | | - codeServerVersion="2.${TRAVIS_TAG:-${DRONE_TAG:-daily}}" |
| 14 | + # Remove everything that isn't the current VS Code source for caching |
| 15 | + # (otherwise the cache will contain old versions). |
| 16 | + if [[ -d "source/vscode-$vscode_version-source" ]] ; then |
| 17 | + mv "source/vscode-$vscode_version-source" "vscode-$vscode_version-source" |
| 18 | + fi |
| 19 | + rm -rf source/vscode-*-source |
| 20 | + if [[ -d "vscode-$vscode_version-source" ]] ; then |
| 21 | + mv "vscode-$vscode_version-source" "source/vscode-$vscode_version-source" |
66 | 22 | fi |
67 | 23 |
|
68 | | - local branch="${TRAVIS_BRANCH:-DRONE_BRANCH}" |
69 | | - if [[ $branch == "master" ]] ; then |
| 24 | + # Only minify and package on tags since that's when releases are pushed. |
| 25 | + if [[ -n ${DRONE_TAG:-} || -n ${TRAVIS_TAG:-} ]] ; then |
70 | 26 | export MINIFY="true" |
71 | 27 | export PACKAGE="true" |
72 | 28 | fi |
73 | 29 |
|
74 | | - if [[ "${ostype}" == "darwin"* ]]; then |
75 | | - local-build |
76 | | - else |
77 | | - docker-build |
78 | | - fi |
| 30 | + function run-yarn() { |
| 31 | + yarn "$1" "$vscode_version" "$code_server_version" |
| 32 | + } |
| 33 | + |
| 34 | + run-yarn build |
| 35 | + [[ -n ${PACKAGE:-} || -n ${BINARY:-} ]] && run-yarn binary |
| 36 | + [[ -n ${PACKAGE:-} ]] && run-yarn package |
79 | 37 | } |
80 | 38 |
|
81 | 39 | main "$@" |
0 commit comments