|
| 1 | +# Workflow name |
| 2 | +name: Build |
| 3 | + |
| 4 | +# This workflow is triggered on pushes and pull requests to the main branch. |
| 5 | +on: |
| 6 | + push: |
| 7 | + #branches: |
| 8 | + #- main |
| 9 | + pull_request: |
| 10 | + #branches: |
| 11 | + #- main |
| 12 | + |
| 13 | +# Concurrency settings to cancel in-progress runs for the same PR or branch |
| 14 | +# This prevents wasting resources on outdated commits. |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 17 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + # Run unit tests before building the application |
| 21 | + |
| 22 | + run-unit-tests: |
| 23 | + name: Run unit tests |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + # Checkout repository code |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + # Verify CSP line exists in target TypeScript file |
| 31 | + - name: Check CSP configuration in webClientServer.ts |
| 32 | + run: | |
| 33 | + TARGET_FILE="patched-vscode/src/vs/server/node/webClientServer.ts" |
| 34 | + REQUIRED_TEXT="'connect-src \'self\' ws: wss: https://main.vscode-cdn.net http://localhost:* https://localhost:* https://login.microsoftonline.com/ https://update.code.visualstudio.com https://*.vscode-unpkg.net/ https://default.exp-tas.com/vscode/ab https://vscode-sync.trafficmanager.net https://vscode-sync-insiders.trafficmanager.net https://*.gallerycdn.vsassets.io https://marketplace.visualstudio.com https://openvsxorg.blob.core.windows.net https://az764295.vo.msecnd.net https://code.visualstudio.com https://*.gallery.vsassets.io https://*.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com https://*.servicebus.windows.net/ https://vscode.blob.core.windows.net https://vscode.search.windows.net https://vsmarketplacebadges.dev https://vscode.download.prss.microsoft.com https://download.visualstudio.microsoft.com https://*.vscode-unpkg.net https://open-vsx.org;'" |
| 35 | +
|
| 36 | + if [ ! -f "$TARGET_FILE" ]; then |
| 37 | + echo "❌ FAIL: Target file $TARGET_FILE does not exist." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + if grep -F "$REQUIRED_TEXT" "$TARGET_FILE" > /dev/null; then |
| 42 | + echo "✅ PASS: Required CSP text exists." |
| 43 | + else |
| 44 | + echo "❌ FAIL: Required CSP text NOT found in $TARGET_FILE" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | +
|
| 49 | +
|
| 50 | + # The main job for building the application |
| 51 | + build: |
| 52 | + name: Build sagemaker-code-editor |
| 53 | + runs-on: ubuntu-latest |
| 54 | + # Ensure unit tests pass before building |
| 55 | + needs: run-unit-tests |
| 56 | + timeout-minutes: 180 |
| 57 | + env: |
| 58 | + # Environment variable to optimize the build process |
| 59 | + DISABLE_V8_COMPILE_CACHE: 1 |
| 60 | + |
| 61 | + steps: |
| 62 | + # Step 1: Check out the repository code, including its submodules. |
| 63 | + - name: Checkout repo with submodules |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + submodules: recursive |
| 67 | + |
| 68 | + # Step 2: Install system-level dependencies required for the build. |
| 69 | + - name: Install system dependencies |
| 70 | + run: | |
| 71 | + sudo apt-get update |
| 72 | + sudo apt-get install -y make gcc g++ libx11-dev xorg-dev libxkbfile-dev libsecret-1-dev libkrb5-dev python3 jq perl gettext automake autoconf quilt |
| 73 | +
|
| 74 | + # Step 3: Set up the Node.js environment. Version 20 is specified. |
| 75 | + - name: Set up Node.js |
| 76 | + uses: actions/setup-node@v4 |
| 77 | + with: |
| 78 | + node-version: 20 |
| 79 | + |
| 80 | + # Step 4: Cache Yarn dependencies to speed up subsequent builds. |
| 81 | + - name: Cache Yarn dependencies |
| 82 | + uses: actions/cache@v4 |
| 83 | + with: |
| 84 | + path: | |
| 85 | + vscode/node_modules |
| 86 | + key: ${{ runner.os }}-node20-${{ hashFiles('vscode/package.json', 'vscode/yarn.lock') }} |
| 87 | + |
| 88 | + # Step 5: Apply patches from the 'patches' directory if it exists. |
| 89 | + - name: Apply patches (if any) |
| 90 | + run: | |
| 91 | + if [ -d patches ] && [ "$(ls -A patches)" ]; then |
| 92 | + quilt push -a || true |
| 93 | + fi |
| 94 | +
|
| 95 | + # Step 6: Generate a version string for this specific build. |
| 96 | + # It's based on the commit SHA to create a unique identifier. |
| 97 | + - name: Set Development Version |
| 98 | + id: version |
| 99 | + run: | |
| 100 | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) |
| 101 | + VERSION="0.0.0-dev-${SHORT_SHA}" |
| 102 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 103 | + echo "Generated version for this build: $VERSION" |
| 104 | +
|
| 105 | + # Step 7: The main build process for vscode. |
| 106 | + - name: Build vscode |
| 107 | + run: | |
| 108 | + cd vscode |
| 109 | + export DISABLE_V8_COMPILE_CACHE=1 |
| 110 | + export UV_THREADPOOL_SIZE=4 |
| 111 | + npm i -g node-gyp |
| 112 | + yarn install --network-concurrency 1 |
| 113 | + |
| 114 | + # Remove and re-add ripgrep |
| 115 | + VSCODE_RIPGREP_VERSION=$(jq -r '.dependencies."@vscode/ripgrep"' package.json) |
| 116 | + mv package.json package.json.orig |
| 117 | + jq 'del(.dependencies."@vscode/ripgrep")' package.json.orig > package.json |
| 118 | + |
| 119 | + # Re-run install to remove ripgrep |
| 120 | + yarn install |
| 121 | + |
| 122 | + # Add ripgrep back |
| 123 | + yarn add --ignore-scripts "@vscode/ripgrep@${VSCODE_RIPGREP_VERSION}" |
| 124 | + |
| 125 | + ARCH_ALIAS=linux-x64 |
| 126 | + # Run the gulp build task |
| 127 | + yarn gulp vscode-reh-web-${ARCH_ALIAS}-min |
| 128 | +
|
| 129 | + # Step 8: Find the exact path of the original build output directory. |
| 130 | + - name: Find build output |
| 131 | + id: find_output |
| 132 | + run: | |
| 133 | + BUILD_PATH=$(find . -name "vscode-reh-web-linux-x64" -type d | head -n 1) |
| 134 | + if [ -z "$BUILD_PATH" ]; then |
| 135 | + echo "::error::Build output directory 'vscode-reh-web-linux-x64' not found!" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | + echo "Build output found at: $BUILD_PATH" |
| 139 | + echo "build_path=$BUILD_PATH" >> $GITHUB_OUTPUT |
| 140 | + |
| 141 | + # Step 9: Rename the build output directory to sagemaker-code-editor |
| 142 | + - name: Rename build output directory |
| 143 | + id: rename_output |
| 144 | + run: | |
| 145 | + ORIG_PATH="${{ steps.find_output.outputs.build_path }}" |
| 146 | + PARENT_DIR=$(dirname "$ORIG_PATH") |
| 147 | + mv "$ORIG_PATH" "$PARENT_DIR/sagemaker-code-editor" |
| 148 | + echo "Renamed build output directory to: $PARENT_DIR/sagemaker-code-editor" |
| 149 | + echo "build_path=$PARENT_DIR/sagemaker-code-editor" >> $GITHUB_OUTPUT |
| 150 | + |
| 151 | + # Step 10: Create a compressed tarball of the renamed build output. |
| 152 | + - name: Create tarball archive |
| 153 | + run: | |
| 154 | + TARBALL="sagemaker-code-editor-${{ env.VERSION }}.tar.gz" |
| 155 | + BUILD_DIR_PATH="${{ steps.rename_output.outputs.build_path }}" |
| 156 | + PARENT_DIR=$(dirname "$BUILD_DIR_PATH") |
| 157 | + BUILD_DIR_NAME=$(basename "$BUILD_DIR_PATH") |
| 158 | + echo "Creating '$TARBALL' from '$BUILD_DIR_NAME' in '$PARENT_DIR'" |
| 159 | + tar czf $TARBALL -C "$PARENT_DIR" "$BUILD_DIR_NAME" |
| 160 | + |
| 161 | + # Step 11: Upload the tarball as a build artifact. |
| 162 | + - name: Upload build artifact |
| 163 | + uses: actions/upload-artifact@v4 |
| 164 | + with: |
| 165 | + name: npm-package |
| 166 | + path: sagemaker-code-editor-${{ env.VERSION }}.tar.gz |
| 167 | + # Run end-to-end tests after the build is complete |
| 168 | + run-e2e-tests: |
| 169 | + name: Run e2e tests |
| 170 | + runs-on: ubuntu-latest |
| 171 | + needs: build # Ensure e2e tests run after build |
| 172 | + steps: |
| 173 | + # Checkout repository code |
| 174 | + - name: Checkout code |
| 175 | + uses: actions/checkout@v4 |
| 176 | + |
| 177 | + # Output placeholder message for e2e tests |
| 178 | + - name: Test of e2e test |
| 179 | + run: echo "Test of e2e test" |
0 commit comments