Skip to content

Make installer work on any os/arch and add installer tests #3712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: Build

on:
push:
Expand All @@ -16,7 +16,7 @@ on:

jobs:
prebuild:
name: Pre-Build checks
name: Pre-build checks
runs-on: ubuntu-latest
timeout-minutes: 5
env:
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/installer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Installer integration

on:
push:
branches:
- main
paths:
- "installer.sh"
pull_request:
branches:
- main

jobs:
ubuntu:
name: Test installer on Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install code-server
run: ./install.sh

- name: Test code-server
run: yarn test:standalone-release code-server

alpine:
name: Test installer on Alpine
runs-on: ubuntu-latest
container: "alpine:3.14"
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install curl
run: apk add curl

- name: Add user
run: adduser coder --disabled-password

# Standalone should work without root.
- name: Test standalone to a non-existent prefix
run: su coder -c "./install.sh --method standalone --prefix /tmp/does/not/yet/exist"

macos:
name: Test installer on macOS
runs-on: macos-latest

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install code-server
run: ./install.sh

- name: Test code-server
run: yarn test:standalone-release code-server
30 changes: 30 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Script unit tests

on:
push:
branches:
- main
paths:
- "installer.sh"
pull_request:
branches:
- main

jobs:
test:
name: Run script unit tests
runs-on: ubuntu-latest
# This runs on Alpine to make sure we're testing with actual sh.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, doesn't the script force things to run as bash due to the shebang? Also, Ubuntu should include Bourne shell (e.g. dash) too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installer shebang is #!/bin/sh but since that's often a symlink to bash/dash/etc I've used Alpine to make sure it's really using sh to catch any bashisms that might sneak in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Good point, I was looking at test-scripts.sh, which uses bash explicitly: #!/usr/bin/env bash

This makes sense then. I think Ubuntu should be using dash for /bin/sh by default, though I'm not sure if GitHub Actions does some customization to the environment:

$ docker run --rm -it ubuntu:latest
root@081f1b5d886d:/# which sh
/usr/bin/sh
root@081f1b5d886d:/# ls -al /usr/bin/sh
lrwxrwxrwx 1 root root 4 Jul 18  2019 /usr/bin/sh -> dash

There's also a handy checkbashisms script in devscripts (install it with apt) that you may find useful. I use it in my dotfiles build: https://github.com/jawnsy/dotfiles/blob/0a27557f15aba599056171abc5ff936e7b530d13/.github/workflows/build.yml#L49

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's dope! I'll definitely add that.

container: "alpine:3.14"
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install test utilities
run: apk add bats checkbashisms

- name: Check Bashisms
run: checkbashisms ./install.sh

- name: Run script unit tests
run: ./ci/dev/test-scripts.sh
14 changes: 9 additions & 5 deletions ci/build/test-standalone-release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

# Makes sure the release works.
# Make sure a code-server release works. You can pass in the path otherwise it
# will use release-standalone in the current directory.
#
# This is to make sure we don't have Node version errors or any other
# compilation-related errors.
main() {
Expand All @@ -10,12 +12,14 @@ main() {
local EXTENSIONS_DIR
EXTENSIONS_DIR="$(mktemp -d)"

echo "Testing standalone release."
local path=${1:-./release-standalone/bin/code-server}

# Note: using a basic theme extension because it doesn't update often and is more reliable for testing
./release-standalone/bin/code-server --extensions-dir "$EXTENSIONS_DIR" --install-extension wesbos.theme-cobalt2
echo "Testing standalone release in $path."

# NOTE: using a basic theme extension because it doesn't update often and is more reliable for testing
"$path" --extensions-dir "$EXTENSIONS_DIR" --install-extension wesbos.theme-cobalt2
local installed_extensions
installed_extensions="$(./release-standalone/bin/code-server --extensions-dir "$EXTENSIONS_DIR" --list-extensions 2>&1)"
installed_extensions="$("$path" --extensions-dir "$EXTENSIONS_DIR" --list-extensions 2>&1)"
# We use grep as wesbos.theme-cobalt2 may have dependency extensions that change.
if ! echo "$installed_extensions" | grep -q "wesbos.theme-cobalt2"; then
echo "Unexpected output from listing extensions:"
Expand Down
9 changes: 9 additions & 0 deletions ci/dev/test-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

main() {
cd "$(dirname "$0")/../.."
bats ./test/scripts
}

main "$@"
2 changes: 2 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Here is what is needed:
- Get this by running `apt-get install -y build-essential`
- `rsync` and `unzip`
- Used for code-server releases
- `bats`
- Used to run script unit tests

## Creating pull requests

Expand Down
Loading