From 6282cd7e7b84c4de32c7a38f68ee9db208e35a71 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Fri, 8 May 2020 00:34:20 -0400 Subject: [PATCH] Simplify packaging and improve scripts Much better test now as well. --- .dockerignore | 2 +- .github/workflows/ci.yaml | 31 +++++----- .gitignore | 2 +- ci/README.md | 11 ++-- ci/build/archive-static-release.sh | 41 ------------- ci/build/build-packages.sh | 59 +++++++++++++++++++ ci/build/build-release.sh | 5 +- ci/build/build-static-pkgs.sh | 24 -------- ci/build/lib.sh | 0 ci/build/test-static-release.sh | 17 ++++-- ci/release-container/Dockerfile | 2 +- .../{static-release.sh => release-static.sh} | 6 +- package.json | 2 +- 13 files changed, 100 insertions(+), 102 deletions(-) delete mode 100755 ci/build/archive-static-release.sh create mode 100755 ci/build/build-packages.sh delete mode 100755 ci/build/build-static-pkgs.sh mode change 100644 => 100755 ci/build/lib.sh rename ci/steps/{static-release.sh => release-static.sh} (61%) mode change 100644 => 100755 diff --git a/.dockerignore b/.dockerignore index b8940df7..9bcce7a8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ ** -!release-github +!release-packages !ci diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c6413922..411f5e9d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,18 +32,19 @@ jobs: steps: - uses: actions/checkout@v1 - name: Download npm package - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v2 with: name: npm-package - - name: Run ./ci/steps/static-release.sh + path: ./release + - name: Run ./ci/steps/release-static.sh uses: ./ci/container with: - args: ./ci/steps/static-release.sh + args: ./ci/steps/release-static.sh - name: Upload release artifacts uses: actions/upload-artifact@v2 with: - name: release-github - path: ./release-github/* + name: release-packages + path: ./release-packages linux-arm64: needs: release @@ -51,18 +52,19 @@ jobs: steps: - uses: actions/checkout@v1 - name: Download npm package - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v2 with: name: npm-package - - name: Run ./ci/steps/static-release.sh + path: ./release + - name: Run ./ci/steps/release-static.sh uses: ./ci/container with: - args: ./ci/steps/static-release.sh + args: ./ci/steps/release-static.sh - name: Upload release artifacts uses: actions/upload-artifact@v2 with: - name: release-github - path: ./release-github/* + name: release-packages + path: ./release-packages macos: needs: release @@ -70,17 +72,18 @@ jobs: steps: - uses: actions/checkout@v1 - name: Download npm package - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v2 with: name: npm-package + path: ./release - run: brew unlink node@12 - run: brew install node - - run: ./ci/steps/static-release.sh + - run: ./ci/steps/release-static.sh env: # Otherwise we get rate limited when fetching the ripgrep binary. GITHUB_TOKEN: ${{ secrets.github_token }} - name: Upload release artifacts uses: actions/upload-artifact@v2 with: - name: release-github - path: ./release-github/* + name: release-packages + path: ./release-packages diff --git a/.gitignore b/.gitignore index 86557de4..35daca8b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,6 @@ dist* out* release/ release-static/ -release-github/ +release-packages/ release-gcp/ node_modules diff --git a/ci/README.md b/ci/README.md index a5397f59..bf9e1875 100644 --- a/ci/README.md +++ b/ci/README.md @@ -32,6 +32,7 @@ This directory contains scripts used for the development of code-server. ## build This directory contains the scripts used to build code-server. +You can disable minification by setting `MINIFY=`. - [./lib.sh](./lib.sh) - Contains code duplicated across these scripts. @@ -50,12 +51,11 @@ This directory contains the scripts used to build code-server. - Useful to do a clean build. - [./build/code-server.sh](./build/code-server.sh) - Copied into static releases to run code-server with the bundled node binary. -- [./build/archive-static-release.sh](./build/archive-static-release.sh) - - Archives `./release-static` into a tar/zip for CI with the proper directory name scheme - [./build/test-release.sh](./build/test-static-release.sh) - Ensures code-server in the `./release-static` directory runs -- [./build/build-static-pkgs.sh](./build/build-static-pkgs.sh) (`yarn pkg`) - - Uses [nfpm](https://github.com/goreleaser/nfpm) to generate .deb and .rpm from a static release +- [./build/build-packages.sh](./build/build-static-pkgs.sh) (`yarn package`) + - Packages `./release-static` into an archive in `./release-packages` + - If on linux, [nfpm](https://github.com/goreleaser/nfpm) is used to generate .deb and .rpm - [./build/nfpm.yaml](./build/nfpm.yaml) - Used to configure [nfpm](https://github.com/goreleaser/nfpm) to generate .deb and .rpm - [./build/code-server-nfpm.sh](./build/code-server-nfpm.sh) @@ -80,5 +80,4 @@ Just helps avoid clobbering .travis.yml. - 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. + - Takes the output of the previous script and generates a static release and packages diff --git a/ci/build/archive-static-release.sh b/ci/build/archive-static-release.sh deleted file mode 100755 index 37a85617..00000000 --- a/ci/build/archive-static-release.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Generates static code-server releases for CI. -# This script assumes that a static release is built already. - -main() { - cd "$(dirname "${0}")/../.." - source ./ci/lib.sh - - VERSION="$(pkg_json_version)" - - local OS - OS="$(os)" - - local ARCH - ARCH="$(arch)" - - local archive_name="code-server-$VERSION-$OS-$ARCH" - mkdir -p release-github - - local ext - if [[ $OS == "linux" ]]; then - ext=".tar.gz" - tar -czf "release-github/$archive_name$ext" --transform "s/^\.\/release-static/$archive_name/" ./release-static - else - mv ./release-static "./$archive_name" - ext=".zip" - zip -r "release-github/$archive_name$ext" "./$archive_name" - mv "./$archive_name" ./release-static - fi - - echo "done (release-github/$archive_name)" - - mkdir -p "release-gcp/$VERSION" - cp "release-github/$archive_name$ext" "./release-gcp/$VERSION/$OS-$ARCH$ext" - mkdir -p "release-gcp/latest" - cp "./release-github/$archive_name$ext" "./release-gcp/latest/$OS-$ARCH$ext" -} - -main "$@" diff --git a/ci/build/build-packages.sh b/ci/build/build-packages.sh new file mode 100755 index 00000000..7dc65df0 --- /dev/null +++ b/ci/build/build-packages.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Packages code-server for the current OS and architecture into ./release-packages. +# This script assumes that a static release is built already into ./release-static. + +main() { + cd "$(dirname "${0}")/../.." + source ./ci/lib.sh + + export VERSION + VERSION="$(pkg_json_version)" + + local OS + OS="$(os)" + + export ARCH + ARCH="$(arch)" + + local archive_name="code-server-$VERSION-$OS-$ARCH" + mkdir -p release-packages + + local ext + if [[ $OS == "linux" ]]; then + ext=".tar.gz" + tar -czf "release-packages/$archive_name$ext" --transform "s/^\.\/release-static/$archive_name/" ./release-static + else + mv ./release-static "./$archive_name" + ext=".zip" + zip -r "release-packages/$archive_name$ext" "./$archive_name" + mv "./$archive_name" ./release-static + fi + + echo "done (release-packages/$archive_name)" + + release_gcp + + if [[ $OSTYPE == linux* ]]; then + release_nfpm + fi +} + +release_gcp() { + mkdir -p "release-gcp/$VERSION" + cp "release-packages/$archive_name$ext" "./release-gcp/$VERSION/$OS-$ARCH$ext" + mkdir -p "release-gcp/latest" + cp "./release-packages/$archive_name$ext" "./release-gcp/latest/$OS-$ARCH$ext" +} + +# Generates deb and rpm packages. +release_nfpm() { + local nfpm_config + nfpm_config=$(envsubst < ./ci/build/nfpm.yaml) + + nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server-"$VERSION-$ARCH.deb" + nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server-"$VERSION-$ARCH.rpm" +} + +main "$@" diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 0205488d..d96a466d 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash set -euo pipefail -# This script requires code-server and vscode to be built with matching MINIFY. +# This script requires 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 controls whether minified vscode is bundled. MINIFY="${MINIFY-true}" main() { diff --git a/ci/build/build-static-pkgs.sh b/ci/build/build-static-pkgs.sh deleted file mode 100755 index 659039ae..00000000 --- a/ci/build/build-static-pkgs.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Generates deb and rpm packages for CI. -# Assumes a static release has already been built. - -main() { - cd "$(dirname "${0}")/../.." - source ./ci/lib.sh - - VERSION="$(pkg_json_version)" - export VERSION - - ARCH="$(arch)" - export ARCH - - local nfpm_config - nfpm_config=$(envsubst < ./ci/build/nfpm.yaml) - - nfpm pkg -f <(echo "$nfpm_config") --target release-github/code-server-"$VERSION-$ARCH.deb" - nfpm pkg -f <(echo "$nfpm_config") --target release-github/code-server-"$VERSION-$ARCH.rpm" -} - -main "$@" diff --git a/ci/build/lib.sh b/ci/build/lib.sh old mode 100644 new mode 100755 diff --git a/ci/build/test-static-release.sh b/ci/build/test-static-release.sh index 02177fe3..93d9e991 100755 --- a/ci/build/test-static-release.sh +++ b/ci/build/test-static-release.sh @@ -7,14 +7,21 @@ set -euo pipefail main() { cd "$(dirname "${0}")/../.." - local output - output=$(./release-static/bin/code-server --list-extensions 2>&1) - if echo "$output" | grep 'was compiled against a different Node.js version'; then - echo "$output" + local EXTENSIONS_DIR + EXTENSIONS_DIR="$(mktemp -d)" + + echo "Testing static release" + + ./release-static/bin/code-server --extensions-dir "$EXTENSIONS_DIR" --install-extension ms-python.python + local installed_extensions + installed_extensions="$(./release-static/bin/code-server --extensions-dir "$EXTENSIONS_DIR" --list-extensions 2>&1)" + if [[ $installed_extensions != "ms-python.python" ]]; then + echo "Unexpected output from listing extensions:" + echo "$installed_extensions" exit 1 fi - echo "Build ran successfully" + echo "Static release works correctly" } main "$@" diff --git a/ci/release-container/Dockerfile b/ci/release-container/Dockerfile index cafcea28..a0f20936 100644 --- a/ci/release-container/Dockerfile +++ b/ci/release-container/Dockerfile @@ -34,7 +34,7 @@ RUN ARCH="$(dpkg --print-architecture)" && \ mkdir -p /etc/fixuid && \ printf "user: coder\ngroup: coder\n" > /etc/fixuid/config.yml -COPY release-github/code-server*.deb /tmp/ +COPY release-packages/code-server*.deb /tmp/ RUN dpkg -i /tmp/code-server*.deb && rm /tmp/code-server*.deb EXPOSE 8080 diff --git a/ci/steps/static-release.sh b/ci/steps/release-static.sh old mode 100644 new mode 100755 similarity index 61% rename from ci/steps/static-release.sh rename to ci/steps/release-static.sh index 62c5e8be..6d565421 --- a/ci/steps/static-release.sh +++ b/ci/steps/release-static.sh @@ -6,11 +6,7 @@ main() { yarn release:static ./ci/build/test-static-release.sh - ./ci/build/archive-static-release.sh - - if [[ $OSTYPE == linux* ]]; then - yarn pkg - fi + yarn package } main "$@" diff --git a/package.json b/package.json index 461e42a0..b6a311c6 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "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", + "package": "./ci/build/build-packages.sh", "_____": "", "fmt": "./ci/dev/fmt.sh", "lint": "./ci/dev/lint.sh",