From bc453b5f0d62135d221264379eaba7933c3eebff Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 7 May 2020 23:48:49 -0400 Subject: [PATCH] Switch to a single job to build the npm package The architecture specific jobs pull it in and then build releases. Much faster! --- .github/workflows/ci.yaml | 44 +++++++++++++++++++------ ci/README.md | 16 ++++++--- ci/build/build-release.sh | 56 ++++---------------------------- ci/build/build-static-release.sh | 25 ++++++++++++++ ci/build/lib.sh | 10 ++++++ ci/steps/release.sh | 8 +---- ci/steps/static-release.sh | 16 +++++++++ package.json | 1 + 8 files changed, 104 insertions(+), 72 deletions(-) create mode 100755 ci/build/build-static-release.sh create mode 100644 ci/build/lib.sh create mode 100644 ci/steps/static-release.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c0a107acb..c64139229 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: with: args: ./ci/steps/test.sh - linux-amd64: + release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 @@ -20,25 +20,44 @@ jobs: uses: ./ci/container with: args: ./ci/steps/release.sh - - name: Upload release artifacts - uses: actions/upload-artifact@v2 - with: - name: release-github - path: ./release-github/* - name: Upload npm package artifact uses: actions/upload-artifact@v2 with: name: npm-package path: ./release + linux-amd64: + needs: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Download npm package + uses: actions/download-artifact@v1 + with: + name: npm-package + - name: Run ./ci/steps/static-release.sh + uses: ./ci/container + with: + args: ./ci/steps/static-release.sh + - name: Upload release artifacts + uses: actions/upload-artifact@v2 + with: + name: release-github + path: ./release-github/* + linux-arm64: + needs: release runs-on: ubuntu-arm64-latest steps: - uses: actions/checkout@v1 - - name: Run ./ci/steps/release.sh + - name: Download npm package + uses: actions/download-artifact@v1 + with: + name: npm-package + - name: Run ./ci/steps/static-release.sh uses: ./ci/container with: - args: ./ci/steps/release.sh + args: ./ci/steps/static-release.sh - name: Upload release artifacts uses: actions/upload-artifact@v2 with: @@ -46,14 +65,19 @@ jobs: path: ./release-github/* macos: + needs: release runs-on: macos-latest steps: - uses: actions/checkout@v1 + - name: Download npm package + uses: actions/download-artifact@v1 + with: + name: npm-package - run: brew unlink node@12 - run: brew install node - - run: ./ci/steps/release.sh + - run: ./ci/steps/static-release.sh env: - # Otherwise we get a rate limited when fetching the ripgrep binary. + # Otherwise we get rate limited when fetching the ripgrep binary. GITHUB_TOKEN: ${{ secrets.github_token }} - name: Upload release artifacts uses: actions/upload-artifact@v2 diff --git a/ci/README.md b/ci/README.md index 0c5617423..a5397f592 100644 --- a/ci/README.md +++ b/ci/README.md @@ -33,14 +33,17 @@ This directory contains scripts used for the development of code-server. This directory contains the scripts used to build code-server. +- [./lib.sh](./lib.sh) + - Contains code duplicated across these scripts. - [./build/build-code-server.sh](./build/build-code-server.sh) (`yarn build`) - Builds code-server into ./out and bundles the frontend into ./dist. - [./build/build-vscode.sh](./build/build-vscode.sh) (`yarn build:vscode`) - Builds vscode into ./lib/vscode/out-vscode. - [./build/build-release.sh](./build/build-release.sh) (`yarn release`) - - Bundles the output of the above two scripts into a single node module at ./release. - - Will build a static release with node/node_modules into `./release-static` - if `STATIC=1` is set. + - Bundles the output of the above two scripts into a single node module at `./release`. +- [./build/build-static-release.sh](./build/build-static-release.sh) (`yarn release:static`) + - Requires a release already built in `./release`. + - Will build a static release with node and node_modules into `./release-static` - [./build/clean.sh](./build/clean.sh) (`yarn clean`) - Removes all git ignored files like build artifacts. - Will also `git reset --hard lib/vscode` @@ -74,5 +77,8 @@ Just helps avoid clobbering .travis.yml. - [./steps/test.sh](./steps/test.sh) - Runs `yarn ci` after ensuring VS Code is patched - [./steps/release.sh](./steps/release.sh) - - Runs the full static build process for CI - - Packages the release into a .deb and .rpm for linux + - Runs the full release process + - Generates the npm package at `./release` +- [./steps/static-release.sh](./steps/static-release.sh) + - Takes the output of the previous script and bundles it into a self-contained archive into `./github-release` + - Also outputs .deb/.rpm if on linux. diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 4a86874c8..0205488dc 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -1,28 +1,18 @@ #!/usr/bin/env bash set -euo pipefail -# This script requires code-server and vscode to be built with -# matching MINIFY. - -# RELEASE_PATH is the destination directory for the release from the root. -# Defaults to release -RELEASE_PATH="${RELEASE_PATH-release}" - -# STATIC controls whether node and node_modules are packaged into the release. -# Disabled by default. -STATIC="${STATIC-}" +# This script requires code-server and vscode to be built with matching MINIFY. # MINIFY controls whether minified vscode is bundled and whether # any included node_modules are pruned for production. MINIFY="${MINIFY-true}" -VSCODE_SRC_PATH="lib/vscode" - -VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode" - main() { cd "$(dirname "${0}")/../.." - source ./ci/lib.sh + source ./ci/build/lib.sh + + VSCODE_SRC_PATH="lib/vscode" + VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode" mkdir -p "$RELEASE_PATH" @@ -32,20 +22,6 @@ main() { rsync README.md "$RELEASE_PATH" rsync LICENSE.txt "$RELEASE_PATH" rsync ./lib/vscode/ThirdPartyNotices.txt "$RELEASE_PATH" - - if [[ $STATIC ]]; then - rsync "$RELEASE_PATH/" "$RELEASE_PATH-static" - RELEASE_PATH+=-static - VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode" - - bundle_node - else - rm -Rf "$VSCODE_OUT_PATH/extensions/node_modules" - fi -} - -rsync() { - command rsync -a --del "$@" } bundle_code_server() { @@ -76,6 +52,7 @@ bundle_vscode() { mkdir -p "$VSCODE_OUT_PATH" rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out" rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions" + rm -Rf "$VSCODE_OUT_PATH/extensions/node_modules" rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions" rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions" rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions" @@ -103,25 +80,4 @@ EOF jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json" } -bundle_node() { - # We cannot find the path to node from $PATH because yarn shims a script to ensure - # we use the same version it's using so we instead run a script with yarn that - # will print the path to node. - local node_path - node_path="$(yarn -s node <<< 'console.info(process.execPath)')" - - mkdir -p "$RELEASE_PATH/bin" - rsync ./ci/build/code-server.sh "$RELEASE_PATH/bin/code-server" - rsync "$node_path" "$RELEASE_PATH/lib/node" - - rsync node_modules "$RELEASE_PATH" - rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH" - - if [[ $MINIFY ]]; then - pushd "$RELEASE_PATH" - yarn --production - popd - fi -} - main "$@" diff --git a/ci/build/build-static-release.sh b/ci/build/build-static-release.sh new file mode 100755 index 000000000..f2e28fa3d --- /dev/null +++ b/ci/build/build-static-release.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "${0}")/../.." + source ./ci/build/lib.sh + + rsync "$RELEASE_PATH/" "$RELEASE_PATH-static" + RELEASE_PATH+=-static + + # We cannot find the path to node from $PATH because yarn shims a script to ensure + # we use the same version it's using so we instead run a script with yarn that + # will print the path to node. + local node_path + node_path="$(yarn -s node <<< 'console.info(process.execPath)')" + + mkdir -p "$RELEASE_PATH/bin" + rsync ./ci/build/code-server.sh "$RELEASE_PATH/bin/code-server" + rsync "$node_path" "$RELEASE_PATH/lib/node" + + cd "$RELEASE_PATH" + yarn --production +} + +main "$@" diff --git a/ci/build/lib.sh b/ci/build/lib.sh new file mode 100644 index 000000000..f263adb85 --- /dev/null +++ b/ci/build/lib.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +source ./ci/lib.sh + +# RELEASE_PATH is the destination directory for the release from the root. +# Defaults to release +RELEASE_PATH="${RELEASE_PATH-release}" + +rsync() { + command rsync -a --del "$@" +} diff --git a/ci/steps/release.sh b/ci/steps/release.sh index b8ac7202c..5c9355221 100755 --- a/ci/steps/release.sh +++ b/ci/steps/release.sh @@ -8,13 +8,7 @@ main() { yarn vscode yarn build yarn build:vscode - STATIC=1 yarn release - ./ci/build/test-static-release.sh - ./ci/build/archive-static-release.sh - - if [[ $OSTYPE == linux* ]]; then - yarn pkg - fi + yarn release } main "$@" diff --git a/ci/steps/static-release.sh b/ci/steps/static-release.sh new file mode 100644 index 000000000..62c5e8be7 --- /dev/null +++ b/ci/steps/static-release.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + + yarn release:static + ./ci/build/test-static-release.sh + ./ci/build/archive-static-release.sh + + if [[ $OSTYPE == linux* ]]; then + yarn pkg + fi +} + +main "$@" diff --git a/package.json b/package.json index 975f3be2d..461e42a0b 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build": "./ci/build/build-code-server.sh", "build:vscode": "./ci/build/build-vscode.sh", "release": "./ci/build/build-release.sh", + "release:static": "./ci/build/build-static-release.sh", "pkg": "./ci/build/build-static-pkgs.sh", "_____": "", "fmt": "./ci/dev/fmt.sh",