diff --git a/AWSTemplate.sublime-syntax b/AWSTemplate.sublime-syntax new file mode 100644 index 0000000..3d8bf9a --- /dev/null +++ b/AWSTemplate.sublime-syntax @@ -0,0 +1,93 @@ +%YAML 1.2 +--- +name: AWS YAML Template +scope: source.yaml.pipeline.aws +version: 2 + +extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax + +file_extensions: + - cron.yaml + - fargate.yaml + - predeploy.yaml + +first_line_match: '^AWSTemplateFormatVersion:' + +variables: + variable_interpolation: |- + (?x)(?: + (\$\{)((?:AWS::)?\w+)(\}) + ) + + +contexts: + flow-scalar-plain-out-body: + - meta_prepend: true + - include: variable-interpolation + + flow-scalar-single-quoted-body: + - meta_prepend: true + - include: variable-interpolation + + flow-scalar-double-quoted-body: + - meta_prepend: true + - include: variable-interpolation + + variable-interpolation: + - match: '{{variable_interpolation}}' + captures: + 1: punctuation.section.interpolation.begin.aws + 2: variable.other.constant.aws + 3: punctuation.section.interpolation.end.aws + + node: + - meta_prepend: true + - match: ^(\s+)(Command)\s*(:)(?=\s|$) + captures: + 2: string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline + 3: punctuation.separator.key-value.yaml + push: script-block-sequence + + script-block-sequence: + - match: |- + (?x)^(\s+)(-)[ \t]+(?="CMD-SHELL"|'CMD-SHELL'|CMD-SHELL\b) + (["'])? + (CMD-SHELL) + (["'])? + captures: + 2: punctuation.definition.block.sequence.item.yaml + 3: punctuation.definition.string.begin.yaml + 4: variable.language.aws + 5: punctuation.definition.string.end.yaml + set: + - expect-script-block-node + - pop-at-bol + - include: expect-script-block-node + + pop-if-not-sequence-at-same-or-deeper-indentation: + - match: ^(?!\1\s*-) + pop: 1 + + pop-at-bol: + - match: ^ + pop: 1 + + expect-script-block-node: + - match: (-)[ \t]+(?=\S)(["'])? + captures: + 1: punctuation.definition.block.sequence.item.yaml + 2: punctuation.definition.string.begin.yaml + push: script-block-node + - include: pop-if-not-sequence-at-same-or-deeper-indentation + + script-block-node: + - meta_prepend: true + - include: flow-alias + - match: '{{_flow_scalar_end_plain_out}}' + pop: 1 + + embedded-bash: + - meta_include_prototype: false + - meta_scope: source.shell.bash.embedded + - include: scope:source.shell.bash.aws + diff --git a/Bash (AWS).sublime-syntax b/Bash (AWS).sublime-syntax new file mode 100644 index 0000000..9f806d6 --- /dev/null +++ b/Bash (AWS).sublime-syntax @@ -0,0 +1,26 @@ +%YAML 1.2 +--- +# See http://www.sublimetext.com/docs/3/syntax.html +scope: source.shell.bash.aws +version: 2 +hidden: true + +extends: Packages/ShellScript/Bash.sublime-syntax + +# NOTE: this syntax is designed to handle YAML sequence delimited Bash + +contexts: + prototype: + - meta_prepend: true + - match: ^\s*(-)[ \t]+(?=\S)(["'])? + captures: + 1: punctuation.definition.block.sequence.item.yaml + 2: punctuation.definition.string.begin.yaml + - match: (["'])$ + captures: + 1: punctuation.definition.string.end.yaml + +variables: + # lazy escaping from heredoc as shell maybe indented + no_indent: ^\s* + tab_indent: ^\s* diff --git a/README.md b/README.md index dc18fbc..b53d5cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Yaml Pipelines for Sublime Text -Syntax highlighting definitions for YAML pipeline files, like GitHub Actions and AzureDevops, Drone CI, GitLab CICD etc. +Syntax highlighting definitions for YAML pipeline files, like GitHub Actions and AzureDevops, Drone CI, GitLab CICD, AWS templates etc. Includes a small plugin to automatically apply the GitHub Actions filetype when loading or saving a YAML file in a `.github/workflows` folder. Why not just use the default YAML syntax definition? Because it doesn't highlight conditions, variables or embedded Bash or PowerShell scripts! diff --git a/tests/syntax_test_aws.fargate.yaml b/tests/syntax_test_aws.fargate.yaml new file mode 100644 index 0000000..32aee64 --- /dev/null +++ b/tests/syntax_test_aws.fargate.yaml @@ -0,0 +1,50 @@ +# SYNTAX TEST "Packages/YamlPipelines/AWSTemplate.sublime-syntax" + +Resources: + SomeTask: + Properties: + ContainerDefinitions: + - Name: "some_name" + Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/some_path:${DockerImageVersion}" +# ^^ meta.string.yaml string.quoted.double.yaml punctuation.section.interpolation.begin.aws +# ^^^^^^^^^^^^^^ meta.string.yaml string.quoted.double.yaml variable.other.constant.aws +# ^ meta.string.yaml string.quoted.double.yaml punctuation.section.interpolation.end.aws + Command: +# ^^^^^^^ string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline +# ^ punctuation.separator.key-value.yaml + - "bin/console" +# ^ meta.block.script.pipeline punctuation.definition.block.sequence.item.yaml +# ^ meta.block.script.pipeline punctuation.definition.string.begin.yaml - source.shell +# ^^^^^^^^^^^ source.shell.bash.embedded meta.function-call.identifier.shell variable.function.shell +# ^ source.shell.bash.embedded meta.function-call.identifier.shell punctuation.definition.string.end.yaml + - "messenger:consume" + - "--quiet" + - "--memory-limit=120M" + - "clearing-payouts-executed" + - "--no-debug" + Cpu: 128 + MemoryReservation: 256 + HealthCheck: + Command: +# ^^^^^^^ string.unquoted.plain.out.yaml keyword.control.flow.script.pipeline +# ^ punctuation.separator.key-value.yaml + - "CMD-SHELL" +# ^ punctuation.definition.block.sequence.item.yaml +# ^ punctuation.definition.string.begin.yaml +# ^^^^^^^^^ variable.language.aws +# ^ punctuation.definition.string.end.yaml + - "agent health || exit 1" +# ^ meta.block.script.pipeline punctuation.definition.block.sequence.item.yaml +# ^ meta.block.script.pipeline punctuation.definition.string.begin.yaml +# ^^^^^ source.shell.bash.embedded meta.function-call.identifier.shell variable.function.shell +# ^^^^^^ source.shell.bash.embedded meta.function-call.arguments.shell +# ^^ source.shell.bash.embedded keyword.operator.logical.shell +# ^^^^ source.shell.bash.embedded keyword.control.flow.exit.shell +# ^ source.shell.bash.embedded meta.number.integer.decimal.shell constant.numeric.value.shell +# ^ source.shell.bash.embedded punctuation.definition.string.end.yaml + Timeout: 5 +# ^^^^^^^ meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml - source.shell +# ^ meta.mapping.yaml punctuation.separator.key-value.mapping.yaml + Interval: 30 + StartPeriod: 15 + Retries: 3