Skip to content

refactor(ui-tests): add missing docs, rename variables, code cleanup #1254

refactor(ui-tests): add missing docs, rename variables, code cleanup

refactor(ui-tests): add missing docs, rename variables, code cleanup #1254

Workflow file for this run

name: Build and Test
on:
push:
branches:
- "**" # Trigger on all branches
pull_request:
branches:
- "**"
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest] # Test on multiple OS with [ubuntu-latest, windows-latest, macos-latest]
node-version: [20.x] # Test on multiple Node versions with [20.x, 18.x, 16.x]
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4
# Set up Node.js
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
# Install Node.js dependencies
- name: Install Dependencies
run: npm ci
# Run linting
- name: Lint Code
run: npm run lint
continue-on-error: true # Don't fail the build on lint errors
# Compile TypeScript
- name: Compile TypeScript
run: npm run compile
# Compile test files
- name: Compile Tests
run: npm run compile-tests
# Clean test environment
- name: Clean Test Environment
run: |
# Disable .vscode-test.mjs if it exists to prevent conflicts
if [ -f ".vscode-test.mjs" ]; then
mv .vscode-test.mjs .vscode-test.mjs.disabled || true
fi
# Remove test cache to ensure clean state
rm -rf .vscode-test || true
shell: bash
# Cache VS Code test instance to speed up tests
- name: Cache VS Code Test Instance
uses: actions/cache@v3
with:
path: .vscode-test
key: vscode-test-${{ runner.os }}-${{ hashFiles('package.json') }}
restore-keys: |
vscode-test-${{ runner.os }}-
# Run unit tests directly with Mocha
- name: Run Tests (Linux)
if: runner.os == 'Linux'
run: xvfb-run -a npm test
- name: Run Tests (Windows/macOS)
if: runner.os != 'Linux'
run: npm test
# Upload logs on failure
- name: Upload Logs on Failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: failure-logs-${{ matrix.os }}-node${{ matrix.node-version }}
path: |
.vscode-test/logs/
*.log
if-no-files-found: ignore
retention-days: 7 # Logs only kept for 7 days
compression-level: 9 # Max compression for logs
build:
name: Build VSIX
runs-on: ubuntu-latest
needs: test # Only build if tests pass
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4
# Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
check-latest: true
cache: "npm"
# Install Node.js dependencies
- name: Install Node.js Dependencies
run: npm ci
# Set up Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
# Install Python build tools
- name: Install Python Build Tools
run: |
python -m pip install pip==25.2
pip install pip-tools nox
# Prepare Python dependencies
- name: Clean previous bundled Python libs
run: |
rm -rf bundled/libs
mkdir -p bundled/libs
- name: Generate requirements.txt for Python
id: pip-compile
run: pip-compile --resolver=backtracking --output-file=requirements.txt pyproject.toml
continue-on-error: true
- name: Bundle Python Dependencies using Nox
id: nox-bundle
run: python -m nox --session bundle_dependencies
continue-on-error: true
# Validate version format before building
- name: Validate Version Format
run: |
# Get version from package.json
VERSION=$(node -p "require('./package.json').version")
echo "Current version: $VERSION"
# Validate semantic version format
if ! echo "$VERSION" | grep -qE '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'; then
echo "❌ Invalid version format: $VERSION"
echo "Version must follow semantic versioning: MAJOR.MINOR.PATCH"
exit 1
fi
echo "✅ Version format is valid"
# Compile the extension before packaging
- name: Compile Extension
run: npm run package
# Package the extension
- name: Build VSIX Package
run: npm run vsix-package
# Verify the VSIX file was created
- name: Verify VSIX was created
id: verify_vsix
run: |
VSIX_FILES=(*.vsix)
if [ ${#VSIX_FILES[@]} -eq 0 ]; then
echo "No .vsix file found!"
exit 1
elif [ ${#VSIX_FILES[@]} -gt 1 ]; then
echo "Multiple .vsix files found: ${VSIX_FILES[*]}"
# Clean up old VSIX files
rm -f *.vsix
npm run vsix-package
VSIX_FILES=(*.vsix)
fi
echo "VSIX_PATH=${VSIX_FILES[0]}" >> $GITHUB_OUTPUT
ls -l *.vsix
# Get version for artifact naming
- name: Get Version
id: get_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Determine artifact name based on the event
- name: Determine Artifact Name
id: artifact_name
run: |
VERSION="${{ steps.get_version.outputs.VERSION }}"
SHA_SHORT=$(echo "${{ github.sha }}" | cut -c1-7)
if [ "${{ github.event_name }}" == "pull_request" ]; then
BRANCH_NAME="${{ github.head_ref }}"
else
BRANCH_NAME="${{ github.ref_name }}"
fi
# Sanitize branch name for artifact compatibility
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g')
echo "NAME=testbench-extension-v$VERSION-$SANITIZED_BRANCH_NAME-$SHA_SHORT" >> $GITHUB_OUTPUT
# Upload the VSIX as an artifact
- name: Upload VSIX Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact_name.outputs.NAME }}
path: ${{ steps.verify_vsix.outputs.VSIX_PATH }}
if-no-files-found: error
overwrite: true
retention-days: 30 # Should be aligned with cleanup workflow (cleanup-artifacts.yml)
compression-level: 6 # (0-9, default is 6, 9 is max compression)
# Upload VSIX for release workflow (if on main branch)
- name: Upload VSIX for Release
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: testbench-extension-release
path: ${{ steps.verify_vsix.outputs.VSIX_PATH }}
if-no-files-found: error
overwrite: true
retention-days: 90