Skip to content

Commit

Permalink
Fix VSCode script issues with added CI/CD tests
Browse files Browse the repository at this point in the history
- Correct incorrect attribute in `configure_vscode.py`.
- Introduce CI tests for early error detection in the script.
- Replace emojis with ASCII in CI logs to avoid Windows encoding issues.
  • Loading branch information
undergroundwires committed May 6, 2024
1 parent c75df1c commit 1d7cafc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/checks.scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,31 @@ jobs:
-
name: Run install-deps
run: ${{ matrix.install-command }}

configure-vscode:
runs-on: ${{ matrix.os.name }}-latest
strategy:
matrix:
os:
- name: macos
install-vscode-command: brew install --cask visual-studio-code
- name: ubuntu
install-vscode-command: sudo snap install code --classic
- name: windows
install-vscode-command: choco install vscode
fail-fast: false # Still interested to see results from other combinations
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
-
name: Install VSCode
run: ${{ matrix.os.install-vscode-command }}
-
name: Configure VSCode
run: python3 ./scripts/configure_vscode.py
20 changes: 12 additions & 8 deletions scripts/configure_vscode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""
This script configures project-level VSCode settings in '.vscode/settings.json' for
development and installs recommended extensions from '.vscode/extensions.json'.
Description:
This script configures project-level VSCode settings in '.vscode/settings.json' for
development and installs recommended extensions from '.vscode/extensions.json'.
Usage:
python3 ./scripts/configure_vscode.py
"""
# pylint: disable=missing-function-docstring

Expand Down Expand Up @@ -40,7 +44,7 @@ def ensure_setting_file_exists() -> None:
print_success(f"Created empty {VSCODE_SETTINGS_JSON_FILE}")
except IOError as error:
print_error(f"Error creating file {VSCODE_SETTINGS_JSON_FILE}: {error}")
print(f"📄 Created empty {VSCODE_SETTINGS_JSON_FILE}")
print_success(f"Created empty {VSCODE_SETTINGS_JSON_FILE}")

def add_or_update_settings() -> None:
configure_setting_key('eslint.validate', ['vue', 'javascript', 'typescript'])
Expand Down Expand Up @@ -110,7 +114,7 @@ def remove_json_comments(json_like: str) -> str:
pattern: str = r'(?:"(?:\\.|[^"\\])*"|/\*[\s\S]*?\*/|//.*)|([^:]//.*$)'
return re.sub(
pattern,
lambda m: '' if m.group(1) else m.agroup(0), json_like, flags=re.MULTILINE,
lambda m: '' if m.group(1) else m.group(0), json_like, flags=re.MULTILINE,
)

def install_vscode_extensions(vscode_cli_path: str, extensions: list[str]) -> None:
Expand Down Expand Up @@ -167,16 +171,16 @@ def print_installation_results(successful_installations: int, total_extensions:
print_error("Failed to install any of the recommended extensions.")

def print_error(message: str) -> None:
print(f"💀 Error: {message}", file=sys.stderr)
print(f"[ERROR] {message}", file=sys.stderr)

def print_success(message: str) -> None:
print(f"✅ Success: {message}")
print(f"[SUCCESS] {message}")

def print_skip(message: str) -> None:
print(f"⏩ Skipped: {message}")
print(f"[SKIPPED] {message}")

def print_warning(message: str) -> None:
print(f"⚠️ Warning: {message}", file=sys.stderr)
print(f"[WARNING] {message}", file=sys.stderr)

if __name__ == "__main__":
main()

0 comments on commit 1d7cafc

Please sign in to comment.