Skip to content
Open
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ Choosing one replaces the other. The choice is saved in `gitlabComponentHelper.v

</details>

### Scripts checked with ShellCheck

Install [ShellCheck](https://www.shellcheck.net/) (`brew install shellcheck`, `apt install shellcheck` or `winget install koalaman.shellcheck`) and job scripts are checked as you edit. Findings appear in the Problems panel, each linked to its wiki page. Without ShellCheck you get one message, and linting is skipped.

The checks follow how GitLab runs jobs, so you don't get noise:

- Only job-level script keys are checked, not a component input named `script`.
- A job's `before_script` and `script` run in one shell, so variables set in `before_script` count. That's its own `before_script`, or one inherited through `extends`, from `default:` or the global one.
- Variables from `variables:`, `rules: variables:` and `parallel: matrix:` aren't reported as unassigned. List project or group CI/CD variables in `gitlabComponentHelper.shellcheck.knownVariables`.
- Comparing or testing an input, as in `if [ "$[[ inputs.mode ]]" == "fast" ]`, isn't reported, since GitLab fills the value in per pipeline.
- `!reference` tags and aliases are checked where they're defined.

To silence a finding, use the Quick Fix (`Ctrl+.` / `Cmd+.`). **Disable SC#### for this command** adds a `# shellcheck disable=` line above it, inside `|` blocks. **Ignore SC#### in workspace settings** adds the code to `gitlabComponentHelper.shellcheck.exclude`. Set `gitlabComponentHelper.shellcheck.shell` to match your job images (default `bash`).

### Private components

Add a private project or group with **GitLab CI: Add Component Project/Group**. You enter a token once per GitLab instance, and it's reused for everything on that instance.
Expand Down Expand Up @@ -237,6 +251,12 @@ Every setting is also editable from the Settings UI under **GitLab Component Hel
| `gitlabComponentHelper.versionCheck.severity` | string | `warning` | Severity of the "newer version available" diagnostic. One of `warning`, `information`. |
| `gitlabComponentHelper.mcp.enabled` | boolean | `false` | Offer the bundled [MCP server](https://github.com/eFAILution/gitlab-component-helper/blob/main/docs/mcp.md) to Copilot Chat and other in-editor AI clients. When one starts it, it gets your workspace folders and the tokens for your user-level instances. Application scope only. |
| `gitlabComponentHelper.versionPreferences` | object | `{}` | Version offered per component, keyed by `<instance>/<project path>/<component>`: a version, or `~latest` for the highest stable version. Set via **Set as Default Version** or **Always Use Latest** in the Component Browser. |
| `gitlabComponentHelper.shellcheck.enabled` | boolean | `true` | Lint CI script blocks with ShellCheck. Skipped when ShellCheck isn't installed. |
| `gitlabComponentHelper.shellcheck.path` | string | `""` | Path to the `shellcheck` binary; empty uses `PATH`. User or machine settings only. |
| `gitlabComponentHelper.shellcheck.shell` | string | `bash` | Dialect to check against. One of `sh`, `bash`, `dash`, `ksh`, `busybox`. |
| `gitlabComponentHelper.shellcheck.severity` | string | `warning` | Minimum severity reported. One of `error`, `warning`, `info`, `style`. |
| `gitlabComponentHelper.shellcheck.exclude` | array | `[]` | ShellCheck codes to ignore, e.g. `["SC2086"]`. |
| `gitlabComponentHelper.shellcheck.knownVariables` | array | `[]` | Variables set outside the file (project/group settings), as names or globs, e.g. `["deploy_*"]`. |
| `gitlabComponentHelper.cacheTime` | number | `3600` | Component cache lifetime, in seconds. |
| `gitlabComponentHelper.logLevel` | string | `ERROR` | Logging level. One of `DEBUG`, `INFO`, `WARN`, `ERROR`. |
| `gitlabComponentHelper.autoShowOutput` | boolean | `false` | Show the output channel automatically when the log level changes. |
Expand Down Expand Up @@ -321,3 +341,5 @@ A programmatic API for other extensions is planned but not exposed yet. [docs/ap
## License

[MIT](https://github.com/eFAILution/gitlab-component-helper/blob/main/LICENSE)

Script linting is inspired by [YAML with Script](https://gitlab.com/matthiesen-technology/yaml-with-script) by Matthiesen Technology (MIT).
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,57 @@
},
"default": {},
"markdownDescription": "Version that completion and the Component Browser offer for a component, keyed by `<instance>/<project path>/<component>`, for example `gitlab.com/components/opentofu/full-pipeline`. The value is a version, or `~latest` for the highest stable version available when you insert. Set from the Component Browser by right-clicking a version dropdown and choosing **Set as Default Version** or **Always Use Latest**."
},
"gitlabComponentHelper.shellcheck.enabled": {
"type": "boolean",
"default": true,
"description": "Lint before_script, script and after_script blocks in GitLab CI files with ShellCheck. Needs the shellcheck binary; linting is skipped when it is not installed."
},
"gitlabComponentHelper.shellcheck.path": {
"type": "string",
"default": "",
"scope": "machine",
"description": "Path to the shellcheck binary. Leave empty to use shellcheck from PATH."
},
"gitlabComponentHelper.shellcheck.shell": {
"type": "string",
"enum": [
"sh",
"bash",
"dash",
"ksh",
"busybox"
],
"default": "bash",
"description": "Shell dialect ShellCheck checks script blocks against. Match the shell of your job images."
},
"gitlabComponentHelper.shellcheck.severity": {
"type": "string",
"enum": [
"error",
"warning",
"info",
"style"
],
"default": "warning",
"description": "Minimum ShellCheck severity to report."
},
"gitlabComponentHelper.shellcheck.exclude": {
"type": "array",
"items": {
"type": "string",
"pattern": "^(SC)?\\d{4}$"
},
"default": [],
"description": "ShellCheck codes to ignore, e.g. [\"SC2086\"]."
},
"gitlabComponentHelper.shellcheck.knownVariables": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "CI/CD variables set outside the file (project or group settings), so ShellCheck doesn't report them as unassigned. Names or globs, e.g. [\"deploy_*\"]. Variables defined in the file's variables:, rules: and parallel:matrix are detected automatically."
}
}
},
Expand Down
12 changes: 12 additions & 0 deletions src/core/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export interface ConfigValues {
'versionCheck.severity': 'warning' | 'information';
versionPreferences: Record<string, string>;
'mcp.enabled': boolean;
'shellcheck.enabled': boolean;
'shellcheck.path': string;
'shellcheck.shell': 'sh' | 'bash' | 'dash' | 'ksh' | 'busybox';
'shellcheck.severity': 'error' | 'warning' | 'info' | 'style';
'shellcheck.exclude': string[];
'shellcheck.knownVariables': string[];
}

/** A setting name without the `gitlabComponentHelper.` prefix. */
Expand Down Expand Up @@ -69,4 +75,10 @@ export const CONFIG_DEFAULTS: Readonly<ConfigValues> = Object.freeze({
'versionCheck.severity': 'warning',
versionPreferences: {},
'mcp.enabled': false,
'shellcheck.enabled': true,
'shellcheck.path': '',
'shellcheck.shell': 'bash',
'shellcheck.severity': 'warning',
'shellcheck.exclude': [],
'shellcheck.knownVariables': [],
});
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getComponentCacheManager, ComponentCacheManager } from './services/cach
import { assetRoots } from './webview/webviewHtml';
import { Logger } from './utils/logger';
import { ValidationProvider } from './providers/validationProvider';
import { ShellCheckProvider } from './providers/shellCheckProvider';
import type { CachedComponent } from './types/cache';
import type { GitLabYamlFragment } from './types/gitlab-catalog';
import { DETACH_HOVER_COMMAND, type HoverContext } from './providers/hoverContentBuilder';
Expand Down Expand Up @@ -502,6 +503,7 @@ export function activate(context: vscode.ExtensionContext) {

// Initialize the validation provider
const validationProvider = new ValidationProvider(context);
new ShellCheckProvider(context);

// Register command to update every outdated component in the active file to its latest stable version.
logger.debug('[Extension] Registering updateAllComponentVersions command...', 'Extension');
Expand Down
Loading
Loading