Skip to content

Commit 51677f0

Browse files
authored
feat(ci): refactor build workflow (#5572)
* refactor: remove stylelint * refactor: move shellcheck to separate job * refactor: add helm script and job * refactor: add eslint job and yarn script * fix(test/tsconfig): exclude test-plugin * refactor: delete lint, add typecheck job * refactor: remove prebuild * wip: add notes about unit test refactor * refactor: delete buggy socket test This test was really added to in get cover specific lines but it's buggy and only passes sometimes locally. I think it's okay to remove because: - it's an implementation detail (not user facing) - not preventing any specific regressions * refactor: move test-plugin to integration suite This seems more appropriate given this tests how a plugin might work within code-server. * wip * wip: refactor vscode integration tests * refactor: move unit tests to separate job * fix: formatting * Revert "wip: refactor vscode integration tests" This reverts commit 13286bf. * Revert "refactor: move unit tests to separate job" This reverts commit 6c87b54. * feat: collect codecov integration tests * fixup! feat: collect codecov integration tests * fixup! feat: collect codecov integration tests * fixup!: move helm step * fixup!: update ids for caching * trigger ci * trigger ci * chore: clean up names in security.yaml * fixup!: remove .tsx * fixup!: change to src/**" * fixup!: move helm cmd to yaml * fixup!: always build test plugin * fixup!: fix plugin typings * fixup! add back flakey test * fixup!: only install helm deps if changes * fixup!: revert node mod caching * dont keep, test for asher * fixup!: add make to centos * refactor: add test:native This adds a new script to run native tests (i.e. --help which should run in ci on all platforms). * try updating glibc * try 2.25 * Revert "refactor: move test-plugin to integration suite" This reverts commit bc02005. I couldn't get past some GLIBC errors in CI so moving back to unit tests. * Revert "try updating glibc" This reverts commit 02ed560. * fixup! * asher: again * try this for ts changes * fixup * refactor: scripts.yml -> scripts.yaml * fixup!: move lint-sh to scripts.yaml * fixup!: use apk for lint scripts * fixup! fixup!: use apk for lint scripts * fixup!: remove typecheck step * fix: pattern for lint ts files * test: lint should fail * fixup! fixup!: use apk for lint scripts * Revert "test: lint should fail" This reverts commit 158c64d. * fixup!: skip cancel workflow on forks Looks like the cancel action workflow can't run on forks due to secrets. See andymckay/cancel-action#4 * fixup: remove cancel-workflow * fixup! fixup! fixup!: use apk for lint scripts * fixup! fixup! fixup!: use apk for lint scripts * fixup!: fix yarn key * fixup!: add fetch-depth 0
1 parent 4223cf6 commit 51677f0

File tree

11 files changed

+183
-1065
lines changed

11 files changed

+183
-1065
lines changed

.github/workflows/build.yaml

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ concurrency:
2222
# will skip running `yarn install` if it successfully fetched from cache
2323

2424
jobs:
25-
prebuild:
26-
name: Pre-build checks
25+
fmt:
26+
name: Format with Prettier
2727
runs-on: ubuntu-latest
28-
timeout-minutes: 20
28+
timeout-minutes: 5
2929
steps:
3030
- name: Checkout repo
3131
uses: actions/checkout@v3
@@ -35,15 +35,81 @@ jobs:
3535
with:
3636
node-version: "16"
3737

38+
- name: Fetch dependencies from cache
39+
id: cache-node-modules
40+
uses: actions/cache@v3
41+
with:
42+
path: "**/node_modules"
43+
key: yarn-build-${{ hashFiles('**/yarn.lock') }}
44+
restore-keys: |
45+
yarn-build-
46+
47+
- name: Install dependencies
48+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
49+
run: SKIP_SUBMODULE_DEPS=1 yarn --frozen-lockfile
50+
51+
- name: Format files with Prettier
52+
run: yarn fmt
53+
54+
lint-helm:
55+
name: Lint Helm chart
56+
runs-on: ubuntu-latest
57+
timeout-minutes: 5
58+
steps:
59+
- name: Checkout repo
60+
uses: actions/checkout@v3
61+
with:
62+
fetch-depth: 2
63+
64+
- name: Get changed files
65+
id: changed-files
66+
uses: tj-actions/[email protected]
67+
with:
68+
files: |
69+
ci/helm-chart/**
70+
3871
- name: Install helm
72+
if: steps.changed-files.outputs.any_changed == 'true'
3973
uses: azure/[email protected]
4074
with:
4175
token: ${{ secrets.GITHUB_TOKEN }}
4276

4377
- name: Install helm kubeval plugin
78+
if: steps.changed-files.outputs.any_changed == 'true'
4479
run: helm plugin install https://github.com/instrumenta/helm-kubeval
4580

81+
- name: Lint Helm chart
82+
if: steps.changed-files.outputs.any_changed == 'true'
83+
run: helm kubeval ci/helm-chart
84+
85+
lint-ts:
86+
name: Lint TypeScript files
87+
runs-on: ubuntu-latest
88+
timeout-minutes: 5
89+
steps:
90+
- name: Checkout repo
91+
uses: actions/checkout@v3
92+
with:
93+
fetch-depth: 2
94+
95+
- name: Get changed files
96+
id: changed-files
97+
uses: tj-actions/[email protected]
98+
with:
99+
files: |
100+
**/*.ts
101+
**/*.js
102+
files_ignore: |
103+
lib/vscode/**
104+
105+
- name: Install Node.js v16
106+
if: steps.changed-files.outputs.any_changed == 'true'
107+
uses: actions/setup-node@v3
108+
with:
109+
node-version: "16"
110+
46111
- name: Fetch dependencies from cache
112+
if: steps.changed-files.outputs.any_changed == 'true'
47113
id: cache-node-modules
48114
uses: actions/cache@v3
49115
with:
@@ -53,20 +119,15 @@ jobs:
53119
yarn-build-
54120
55121
- name: Install dependencies
56-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
122+
if: steps.changed-files.outputs.any_changed == 'true' && steps.cache-node-modules.outputs.cache-hit != 'true'
57123
run: SKIP_SUBMODULE_DEPS=1 yarn --frozen-lockfile
58124

59-
- name: Run yarn fmt
60-
run: yarn fmt
61-
if: success()
62-
63-
- name: Run yarn lint
64-
run: yarn lint
65-
if: success()
125+
- name: Lint TypeScript files
126+
if: steps.changed-files.outputs.any_changed == 'true'
127+
run: yarn lint:ts
66128

67129
build:
68130
name: Build
69-
needs: prebuild
70131
runs-on: ubuntu-latest
71132
timeout-minutes: 30
72133
env:
@@ -222,6 +283,8 @@ jobs:
222283
runs-on: ubuntu-latest
223284
timeout-minutes: 15
224285
container: "centos:7"
286+
env:
287+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
225288

226289
steps:
227290
- name: Checkout repo
@@ -234,7 +297,7 @@ jobs:
234297

235298
- name: Install development tools
236299
run: |
237-
yum install -y epel-release centos-release-scl
300+
yum install -y epel-release centos-release-scl make
238301
yum install -y devtoolset-9-{make,gcc,gcc-c++} jq rsync python3
239302
240303
- name: Install nfpm and envsubst
@@ -278,6 +341,12 @@ jobs:
278341
- name: Run integration tests on standalone release
279342
run: yarn test:integration
280343

344+
- name: Upload coverage report to Codecov
345+
uses: codecov/codecov-action@v3
346+
with:
347+
token: ${{ secrets.CODECOV_TOKEN }}
348+
if: success()
349+
281350
- name: Build packages with nfpm
282351
run: yarn package
283352

@@ -417,8 +486,8 @@ jobs:
417486
if: steps.cache-node-modules.outputs.cache-hit != 'true'
418487
run: SKIP_SUBMODULE_DEPS=1 yarn install
419488

420-
- name: Run integration tests on standalone release
421-
run: yarn test:integration
489+
- name: Run native module tests on standalone release
490+
run: yarn test:native
422491

423492
- name: Build packages with nfpm
424493
run: yarn package

.github/workflows/scripts.yml renamed to .github/workflows/scripts.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ jobs:
5151

5252
- name: Run script unit tests
5353
run: ./ci/dev/test-scripts.sh
54+
55+
lint:
56+
name: Lint shell files
57+
runs-on: ubuntu-latest
58+
timeout-minutes: 5
59+
steps:
60+
- name: Checkout repo
61+
uses: actions/checkout@v3
62+
63+
- name: Install lint utilities
64+
run: sudo apt install shellcheck
65+
66+
- name: Lint shell files
67+
run: ./ci/dev/lint-scripts.sh

.github/workflows/security.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Security Scanning"
1+
name: Security
22

33
on:
44
push:
@@ -19,7 +19,7 @@ concurrency:
1919

2020
jobs:
2121
audit-ci:
22-
name: Run audit-ci
22+
name: Audit node modules
2323
runs-on: ubuntu-latest
2424
timeout-minutes: 15
2525
steps:
@@ -51,6 +51,7 @@ jobs:
5151
if: success()
5252

5353
trivy-scan-repo:
54+
name: Scan repo with Trivy
5455
permissions:
5556
contents: read # for actions/checkout to fetch code
5657
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
@@ -82,7 +83,7 @@ jobs:
8283
actions: read # for github/codeql-action/init to get workflow details
8384
contents: read # for actions/checkout to fetch code
8485
security-events: write # for github/codeql-action/autobuild to send a status report
85-
name: Analyze
86+
name: Analyze with CodeQL
8687
runs-on: ubuntu-20.04
8788

8889
steps:

.stylelintrc.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

ci/dev/lint-scripts.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
cd "$(dirname "$0")/../.."
6+
shellcheck -e SC2046,SC2164,SC2154,SC1091,SC1090,SC2002 $(git ls-files '*.sh' | grep -v 'lib/vscode')
7+
}
8+
9+
main "$@"

ci/dev/lint.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

ci/dev/test-native.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
help() {
5+
echo >&2 " You can build the standalone release with 'yarn release:standalone'"
6+
echo >&2 " Or you can pass in a custom path."
7+
echo >&2 " CODE_SERVER_PATH='/var/tmp/coder/code-server/bin/code-server' yarn test:integration"
8+
}
9+
10+
# Make sure a code-server release works. You can pass in the path otherwise it
11+
# will look for release-standalone in the current directory.
12+
#
13+
# This is to make sure we don't have Node version errors or any other
14+
# compilation-related errors.
15+
main() {
16+
cd "$(dirname "$0")/../.."
17+
18+
source ./ci/lib.sh
19+
20+
local path="$RELEASE_PATH-standalone/bin/code-server"
21+
if [[ ! ${CODE_SERVER_PATH-} ]]; then
22+
echo "Set CODE_SERVER_PATH to test another build of code-server"
23+
else
24+
path="$CODE_SERVER_PATH"
25+
fi
26+
27+
echo "Running tests with code-server binary: '$path'"
28+
29+
if [[ ! -f $path ]]; then
30+
echo >&2 "No code-server build detected"
31+
echo >&2 "Looked in $path"
32+
help
33+
exit 1
34+
fi
35+
36+
CODE_SERVER_PATH="$path" ./test/node_modules/.bin/jest "$@" --coverage=false --testRegex "./test/integration/help.test.ts"
37+
}
38+
39+
main "$@"

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
"test:e2e:proxy": "USE_PROXY=1 ./ci/dev/test-e2e.sh",
2020
"test:unit": "./ci/dev/test-unit.sh --forceExit --detectOpenHandles",
2121
"test:integration": "./ci/dev/test-integration.sh",
22+
"test:native": "./ci/dev/test-native.sh",
2223
"test:scripts": "./ci/dev/test-scripts.sh",
2324
"package": "./ci/build/build-packages.sh",
2425
"postinstall": "./ci/dev/postinstall.sh",
2526
"publish:npm": "./ci/steps/publish-npm.sh",
2627
"publish:docker": "./ci/steps/docker-buildx-push.sh",
2728
"_audit": "./ci/dev/audit.sh",
2829
"fmt": "./ci/dev/fmt.sh",
29-
"lint": "./ci/dev/lint.sh",
30+
"lint:scripts": "./ci/dev/lint-scripts.sh",
31+
"lint:ts": "eslint --max-warnings=0 --fix $(git ls-files '*.ts' '*.js' | grep -v 'lib/vscode')",
3032
"test": "echo 'Run yarn test:unit or yarn test:e2e' && exit 1",
3133
"ci": "./ci/dev/ci.sh",
3234
"watch": "VSCODE_DEV=1 VSCODE_IPC_HOOK_CLI= NODE_OPTIONS='--max_old_space_size=32384 --trace-warnings' ts-node ./ci/dev/watch.ts",
@@ -53,15 +55,12 @@
5355
"audit-ci": "^6.0.0",
5456
"doctoc": "^2.0.0",
5557
"eslint": "^7.7.0",
56-
"eslint-config-prettier": "^8.1.0",
58+
"eslint-config-prettier": "^8.5.0",
5759
"eslint-import-resolver-typescript": "^2.5.0",
5860
"eslint-plugin-import": "^2.18.2",
5961
"eslint-plugin-prettier": "^4.0.0",
6062
"prettier": "^2.2.1",
6163
"prettier-plugin-sh": "^0.12.0",
62-
"shellcheck": "^1.0.0",
63-
"stylelint": "^13.0.0",
64-
"stylelint-config-recommended": "^5.0.0",
6564
"ts-node": "^10.0.0",
6665
"typescript": "^4.6.2"
6766
},

test/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"extends": "../tsconfig.json",
3-
"include": ["./**/*.ts"]
3+
"include": ["./**/*.ts"],
4+
"exclude": ["./unit/node/test-plugin"]
45
}

test/unit/node/routes/vscode.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { clean, tmpdir } from "../../../utils/helpers"
44
import * as httpserver from "../../../utils/httpserver"
55
import * as integration from "../../../utils/integration"
66

7+
// TODO@jsjoeio - move these to integration tests since they rely on Code
8+
// to be built
79
describe("vscode", () => {
810
let codeServer: httpserver.HttpServer | undefined
911

0 commit comments

Comments
 (0)