Skip to content

Commit

Permalink
Improvements to GitLab CICD pipeline highlighting
Browse files Browse the repository at this point in the history
- support multi-line scripts
- support before and after scripts
- support job names containing spaces
  • Loading branch information
keith-hall committed Jul 12, 2023
1 parent b7f3086 commit 0968d9b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Gitlab CICD.sublime-syntax
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
# https://docs.gitlab.com/ee/ci/yaml/
scope: source.yaml.pipeline.gitlab
version: 2

Expand All @@ -12,12 +12,12 @@ file_extensions:
contexts:
node:
- meta_prepend: true
- match: ^\s+(script)\s*(:)(?=\s|$)
- match: ^\s+(script|before_script|after_script)\s*(:)(?=\s|$)
captures:
1: string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline
2: punctuation.separator.key-value.yaml
push: script-block-sequence
- match: ^([-\w]+)\s*(:)$
- match: ^([-\w ]+)\s*(:)$
captures:
1: entity.name.label.gitlab
2: punctuation.separator.key-value.yaml
Expand All @@ -26,7 +26,13 @@ contexts:
- match: (-)[ \t]+(?=\S)
captures:
1: punctuation.definition.block.sequence.item.yaml
embed: scope:source.shell.bash
escape: '{{_flow_scalar_end_plain_out}}'
push: script-block-node
- match: ^(?=[ ]{2}\w)
pop: 1
- match: (?=\S)
pop: 1

embedded-bash:
- meta_append: true
- match: ''
push: scope:source.shell.bash
55 changes: 55 additions & 0 deletions tests/syntax_test_gitlab_cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ build-job:
# ^ punctuation.separator.key-value
- echo "Hello, $GITLAB_USER_LOGIN!"
# ^ punctuation.definition.block.sequence.item
# ^^^^ source.shell meta.function-call.identifier support.function.echo
after_script:
# ^^^^^^^^^^^^ string.unquoted.plain.out keyword.control.flow.script
# ^ punctuation.separator.key-value
- echo "Execute this command after the `script` section completes."
# ^ punctuation.definition.block.sequence.item
# ^^^^ source.shell meta.function-call.identifier support.function.echo
before_script:
# ^^^^^^^^^^^^^ string.unquoted.plain.out keyword.control.flow.script
# ^ punctuation.separator.key-value
- echo "Execute this `before_script` in all jobs by default."
# ^ punctuation.definition.block.sequence.item
# ^^^^ source.shell meta.function-call.identifier support.function.echo

# <- - source.shell
Expand All @@ -23,8 +35,17 @@ test-job1:
# ^ punctuation.definition.block.sequence.item
#^^^ - punctuation
# ^ - punctuation
- |
# ^ meta.block.script punctuation.definition.block.sequence.item
# ^ meta.block.script keyword.control.flow.block-scalar.literal
echo "First command line."
#^^^ meta.function-call.identifier support.function.echo
echo "Second command line."
#^^^ meta.function-call.identifier support.function.echo
echo "Third command line."

test-job2:
# <- - source.shell
stage: test
script:
- echo "This job tests something, but takes more time than test-job1."
Expand All @@ -37,3 +58,37 @@ deploy-prod:
script:
- echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
environment: production


build osx:
stage: build
script: make build:osx
artifacts:
paths:
- binaries/

build linux:
# ^^^^^^^^^ entity.name.label
# ^ punctuation.separator.key-value
stage: build
script: make build:linux
artifacts:
paths:
- binaries/

test osx:
stage: test
script: make test:osx
dependencies:
- build osx

test linux:
stage: test
script: make test:linux
dependencies:
- build linux

deploy:
stage: deploy
script: make deploy
environment: production

0 comments on commit 0968d9b

Please sign in to comment.