Skip to main content

Github Actions expressions grammar for tree-sitter

Project description

tree-sitter-gh-actions-expressions

CI discord matrix crates npm pypi

Tree-sitter grammar for Github Actions expressions

[!IMPORTANT] ABI version: 15

Parser requirements

  • gitignore (optional): for hashFiles() function
  • json (optional): for fromJSON() function
  • yaml: injection to its block_mapping_pair node. Check the yaml injection section for more information

Usage in Editors

Neovim

  • gh-actions.nvim: plugin that integrates this grammar to your Neovim configuration

Helix

WIP

Emacs

WIP

In General

You can get the built files from the release branch. If you have specific instructions for your editor, PR's are welcome.

Injection for yaml parser

Use the following query:

((block_mapping_pair
  key: (flow_node) @_key
  value: [
    (block_node
      (block_scalar) @_value)
    (flow_node
      [
        (plain_scalar
          (string_scalar) @_value)
        (double_quote_scalar) @_value
      ])
  ]
  (#match? @_value "${{")) @injection.content
  (#is-gh-actions-file? "") ; NOTE: NEW PREDICATE
  (#set! injection.language "gh_actions_expressions")
  (#set! injection.include-children))

((block_mapping_pair
  key: (flow_node) @_key
  (#eq? @_key "if")
  value: (flow_node
    (plain_scalar
      (string_scalar) @_value)
    (#not-match? @_value "${{"))) @injection.content
  (#is-gh-actions-file? "") ; NOTE: NEW PREDICATE
  (#set! injection.language "gh_actions_expressions")
  (#set! injection.include-children))

is-gh-actions-file predicate

To avoid injecting this grammar to files other than github actions, is recommended to create a predicate named is-gh-actions-file.

[!NOTE] The creation of this directive varies for each editor

This predicate will be the responsible to allow injection to files that matches the name pattern .github/workflows/*.ya?ml.

Implementations

gh-actions.nvim

Troubleshooting

AST errors within bash injections when using run key

AST error within bash injection

To avoid these errors, is recommended to surround the expression within a raw_string node, string with single quotes ', i.e.:

jobs:
  dry-run:
    name: dry-run
    runs-on: ubuntu-latest
    steps:
      - name: dry-run
        run: ./script.sh '${{ inputs.mode }}' --dry-run

Correct bash AST by using raw_string

What if I need it within a variable expansion?

AST error within variable expansion

Because variable expansion is done by using $ prefix, the ${{ and }} nodes will cause an AST error. To avoid, this declare an auxiliary bash variable or an environment variable:

jobs:
  dry-run:
    name: dry-run
    runs-on: ubuntu-latest
    steps:
      - name: dry-run
        run: |
          auxiliary_var='${{ inputs.mode }}'
          ./script.sh "$MY_VAR and $MODE" --dry-run
          ./script.sh "$MY_VAR and $auxiliary_var" --dry-run
        env:
          MODE: ${{ inputs.mode }}

Correct bash AST by using auxiliary variables

References

Thanks

Thanks to @disrupted for creating tree-sitter-github-actions grammar, which is the base I used to create this grammar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_gh_actions_expressions-0.5.1.tar.gz (22.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-win_arm64.whl (17.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-win_amd64.whl (18.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl (27.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl (29.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (30.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (28.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-macosx_11_0_arm64.whl (16.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-macosx_10_9_x86_64.whl (16.3 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1.tar.gz.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1.tar.gz
Algorithm Hash digest
SHA256 c888edf90a0209cf55ae12b3bd5b5f507a1ee088cae7e0603aac86d4b83d1624
MD5 2bffe75492bc23e0456347589d899e87
BLAKE2b-256 5449048b241a36c2b72040cd7c58e0bc290a470d8c2c1924bca0734aca8eee6a

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cec59c855019f06e02535bb4b567349e0642b05706b711b0c03629d964fe6333
MD5 f845fd0545bb9b4c5cbdb2a824e1aa2c
BLAKE2b-256 40bce904df75375faf6b6e17604345c6b15bb9aff59b4549dd744031c800f0d8

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 52d4944bc5d14fa6fe2a2fb5765aa8dc558d6e3aeeb4296842fca4e98a2b5760
MD5 71d6aa61bf0e45610680712b7d637aa4
BLAKE2b-256 2b1f4aba36634745bfd40d23bbef3956ddbd6bfa02c1884f0b5219840fd1be4b

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8c2f571737626b9ab43a06a7ddff2d14e231a6c3df1efe6485f54eb58995b384
MD5 d859f245dc149f348604d23573d0a64b
BLAKE2b-256 c24975ca4898f042c60f1b657011a05d587f241b043c0fef2cb6037fa88d1b91

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4945da4497baf562d361430b66d38da53fcaeab1d2050019503ea3aecbd44f13
MD5 3afec547575771d3e87cce31a6d1bf0b
BLAKE2b-256 eb672b0a7718d14c326366439049afc2851ef0df9edde8b35c1bf461605b950e

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9a30d2973d3cc03728885078f4f798dd1676b6aaf1041368957521cba2d64f2f
MD5 aa386dd78d6c88484882429c50d366f9
BLAKE2b-256 b28db44381a6d15259a1b9ea71efd3aa025e7c16e19c6b953b85bd03da33d0b1

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 15567be8479ce7bd57d93a6e64217b8bd2ea832eb476551ce8f469dd02004365
MD5 bcbb392287921fbaa927ce9c51d5d828
BLAKE2b-256 05732c3a0970be80490ab072a0505e3c7a5c21fbb2d4e20f379ea82e94fedb1c

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 187b1b07b42661c136699ae8481a47bce11a10805bbd30920ee2e42322755614
MD5 896a36bbabe345e5635e7d54d1ef7c3f
BLAKE2b-256 2fdba5b74cf0b08521cc1f5fe15a1f3cb845bf277422054d024f4ec7596d7df1

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ca5a91ad9ce059486482e9376e527815845c0f619040f6b0a4b0028ecf4a2e30
MD5 6be326567bf8eb68590d9a25d1923cb7
BLAKE2b-256 a7afe947c282794e03e783067ff8388daa9a69269bf1c786b6d6461636ec22fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page