Skip to content

Commit 24281e8

Browse files
committed
Add embedded syntax highlighting for github-script and run blocks
1 parent d43c37c commit 24281e8

File tree

8 files changed

+441
-0
lines changed

8 files changed

+441
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "GitHub Actions github-script embedded JavaScript",
4+
"scopeName": "source.github-actions-workflow.github-script-embedded",
5+
"injectionSelector": "L:source.github-actions-workflow - meta.github-actions.github-script.context",
6+
"patterns": [
7+
{
8+
"name": "meta.github-actions.github-script.context",
9+
"begin": "^(\\s*(?:-\\s+)?)(uses)(\\s*:\\s*)((?:\\\"actions\\/github-script(?:\\@[A-Za-z0-9._-]+)?\\\")|(?:'actions\\/github-script(?:\\@[A-Za-z0-9._-]+)?')|(?:actions\\/github-script(?:\\@[A-Za-z0-9._-]+)?))(\\s*(?:#.*)?)$",
10+
"beginCaptures": {
11+
"2": {
12+
"name": "entity.name.tag.yaml"
13+
},
14+
"3": {
15+
"name": "punctuation.separator.key-value.mapping.yaml"
16+
},
17+
"4": {
18+
"name": "string.unquoted.plain.out.yaml"
19+
}
20+
},
21+
"end": "^(?=\\s*-\\s|\\S|\\z)",
22+
"patterns": [
23+
{
24+
"contentName": "meta.embedded.block.javascript",
25+
"begin": "^(\\s+)(script)(\\s*:\\s*)([>|][-+0-9\\s]*\\s*)(?:#.*)?$",
26+
"beginCaptures": {
27+
"2": {
28+
"name": "entity.name.tag.yaml"
29+
},
30+
"3": {
31+
"name": "punctuation.separator.key-value.mapping.yaml"
32+
},
33+
"4": {
34+
"name": "string.unquoted.block.yaml"
35+
}
36+
},
37+
"end": "^(?!(?:\\1\\s+|\\s*$))",
38+
"patterns": [
39+
{
40+
"include": "source.js"
41+
}
42+
]
43+
},
44+
{
45+
"include": "source.github-actions-workflow"
46+
}
47+
]
48+
}
49+
],
50+
"repository": {}
51+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "GitHub Actions run+shell embedded syntax",
4+
"scopeName": "source.github-actions-workflow.run-shell-embedded",
5+
"injectionSelector": "L:source.github-actions-workflow - meta.github-actions.run-shell.context",
6+
"patterns": [
7+
{
8+
"include": "#shell-bash"
9+
},
10+
{
11+
"include": "#shell-powershell"
12+
},
13+
{
14+
"include": "#shell-cmd"
15+
},
16+
{
17+
"include": "#shell-python"
18+
},
19+
{
20+
"include": "#shell-node"
21+
}
22+
],
23+
"repository": {
24+
"base-fallback": {
25+
"patterns": [
26+
{
27+
"include": "source.github-actions-workflow"
28+
}
29+
]
30+
},
31+
"shell-bash": {
32+
"name": "meta.github-actions.run-shell.context",
33+
"begin": "^(?=\\s*(?:-\\s+)?shell\\s*:\\s*(?:['\\\"])?(?:bash|sh)(?:['\\\"])?\\s*(?:#.*)?$)",
34+
"end": "^(?=\\s*-\\s|\\S|\\z)",
35+
"patterns": [
36+
{
37+
"contentName": "meta.embedded.block.shellscript",
38+
"begin": "^(\\s+)(run)(\\s*:\\s*)([>|][-+0-9\\s]*\\s*)(?:#.*)?$",
39+
"beginCaptures": {
40+
"2": {
41+
"name": "entity.name.tag.yaml"
42+
},
43+
"3": {
44+
"name": "punctuation.separator.key-value.mapping.yaml"
45+
},
46+
"4": {
47+
"name": "string.unquoted.block.yaml"
48+
}
49+
},
50+
"end": "^(?!(?:\\1\\s+|\\s*$))",
51+
"patterns": [
52+
{
53+
"include": "source.shell"
54+
}
55+
]
56+
},
57+
{
58+
"include": "#base-fallback"
59+
}
60+
]
61+
},
62+
"shell-powershell": {
63+
"name": "meta.github-actions.run-shell.context",
64+
"begin": "^(?=\\s*(?:-\\s+)?shell\\s*:\\s*(?:['\\\"])?(?:pwsh|powershell)(?:['\\\"])?\\s*(?:#.*)?$)",
65+
"end": "^(?=\\s*-\\s|\\S|\\z)",
66+
"patterns": [
67+
{
68+
"contentName": "meta.embedded.block.powershell",
69+
"begin": "^(\\s+)(run)(\\s*:\\s*)([>|][-+0-9\\s]*\\s*)(?:#.*)?$",
70+
"beginCaptures": {
71+
"2": {
72+
"name": "entity.name.tag.yaml"
73+
},
74+
"3": {
75+
"name": "punctuation.separator.key-value.mapping.yaml"
76+
},
77+
"4": {
78+
"name": "string.unquoted.block.yaml"
79+
}
80+
},
81+
"end": "^(?!(?:\\1\\s+|\\s*$))",
82+
"patterns": [
83+
{
84+
"include": "source.powershell"
85+
}
86+
]
87+
},
88+
{
89+
"include": "#base-fallback"
90+
}
91+
]
92+
},
93+
"shell-cmd": {
94+
"name": "meta.github-actions.run-shell.context",
95+
"begin": "^(?=\\s*(?:-\\s+)?shell\\s*:\\s*(?:['\\\"])?cmd(?:['\\\"])?\\s*(?:#.*)?$)",
96+
"end": "^(?=\\s*-\\s|\\S|\\z)",
97+
"patterns": [
98+
{
99+
"contentName": "meta.embedded.block.bat",
100+
"begin": "^(\\s+)(run)(\\s*:\\s*)([>|][-+0-9\\s]*\\s*)(?:#.*)?$",
101+
"beginCaptures": {
102+
"2": {
103+
"name": "entity.name.tag.yaml"
104+
},
105+
"3": {
106+
"name": "punctuation.separator.key-value.mapping.yaml"
107+
},
108+
"4": {
109+
"name": "string.unquoted.block.yaml"
110+
}
111+
},
112+
"end": "^(?!(?:\\1\\s+|\\s*$))",
113+
"patterns": [
114+
{
115+
"include": "source.batchfile"
116+
}
117+
]
118+
},
119+
{
120+
"include": "#base-fallback"
121+
}
122+
]
123+
},
124+
"shell-python": {
125+
"name": "meta.github-actions.run-shell.context",
126+
"begin": "^(?=\\s*(?:-\\s+)?shell\\s*:\\s*(?:['\\\"])?python(?:['\\\"])?\\s*(?:#.*)?$)",
127+
"end": "^(?=\\s*-\\s|\\S|\\z)",
128+
"patterns": [
129+
{
130+
"contentName": "meta.embedded.block.python",
131+
"begin": "^(\\s+)(run)(\\s*:\\s*)([>|][-+0-9\\s]*\\s*)(?:#.*)?$",
132+
"beginCaptures": {
133+
"2": {
134+
"name": "entity.name.tag.yaml"
135+
},
136+
"3": {
137+
"name": "punctuation.separator.key-value.mapping.yaml"
138+
},
139+
"4": {
140+
"name": "string.unquoted.block.yaml"
141+
}
142+
},
143+
"end": "^(?!(?:\\1\\s+|\\s*$))",
144+
"patterns": [
145+
{
146+
"include": "source.python"
147+
}
148+
]
149+
},
150+
{
151+
"include": "#base-fallback"
152+
}
153+
]
154+
},
155+
"shell-node": {
156+
"name": "meta.github-actions.run-shell.context",
157+
"begin": "^(?=\\s*(?:-\\s+)?shell\\s*:\\s*(?:['\\\"])?node(?:['\\\"])?\\s*(?:#.*)?$)",
158+
"end": "^(?=\\s*-\\s|\\S|\\z)",
159+
"patterns": [
160+
{
161+
"contentName": "meta.embedded.block.javascript",
162+
"begin": "^(\\s+)(run)(\\s*:\\s*)([>|][-+0-9\\s]*\\s*)(?:#.*)?$",
163+
"beginCaptures": {
164+
"2": {
165+
"name": "entity.name.tag.yaml"
166+
},
167+
"3": {
168+
"name": "punctuation.separator.key-value.mapping.yaml"
169+
},
170+
"4": {
171+
"name": "string.unquoted.block.yaml"
172+
}
173+
},
174+
"end": "^(?!(?:\\1\\s+|\\s*$))",
175+
"patterns": [
176+
{
177+
"include": "source.js"
178+
}
179+
]
180+
},
181+
{
182+
"include": "#base-fallback"
183+
}
184+
]
185+
}
186+
}
187+
}

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@
6161
"injectTo": [
6262
"source.github-actions-workflow"
6363
]
64+
},
65+
{
66+
"scopeName": "source.github-actions-workflow.github-script-embedded",
67+
"path": "./language/syntaxes/github-script-embedded.tmLanguage.json",
68+
"injectTo": [
69+
"source.github-actions-workflow"
70+
],
71+
"embeddedLanguages": {
72+
"meta.embedded.block.javascript": "javascript"
73+
}
74+
},
75+
{
76+
"scopeName": "source.github-actions-workflow.run-shell-embedded",
77+
"path": "./language/syntaxes/run-shell-embedded.tmLanguage.json",
78+
"injectTo": [
79+
"source.github-actions-workflow"
80+
],
81+
"embeddedLanguages": {
82+
"meta.embedded.block.shellscript": "shellscript",
83+
"meta.embedded.block.powershell": "powershell",
84+
"meta.embedded.block.bat": "bat",
85+
"meta.embedded.block.python": "python",
86+
"meta.embedded.block.javascript": "javascript"
87+
}
6488
}
6589
],
6690
"configuration": {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
demo:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/github-script@v8 # unquoted uses comment
10+
with:
11+
script: | # comment on script header (unquoted uses)
12+
const unquoted = true;
13+
- uses: "actions/github-script@v8" # quoted uses comment
14+
with:
15+
script: | # comment on script header (quoted uses)
16+
const quoted = true;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
demo:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: actions/github-script@v8
11+
with:
12+
script: |
13+
const issue = context.issue;
14+
await github.rest.issues.createComment({
15+
...issue,
16+
body: "hello"
17+
});
18+
retries: 2
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
demo:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: quoted shell with comment
10+
shell: "pwsh" # explicit shell
11+
run: |
12+
Write-Host "hi"
13+
14+
- name: non-block run should not embed
15+
shell: bash
16+
run: echo "hi"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: test
2+
3+
jobs:
4+
demo:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: pwsh example
8+
shell: pwsh
9+
env:
10+
FOO: bar
11+
run: |
12+
Write-Host "hello"
13+
14+
- name: bash example
15+
shell: bash
16+
working-directory: tools
17+
run: >
18+
echo hi
19+
20+
- name: shell after run (documented non-match)
21+
run: |
22+
echo "no dynamic shell highlighting"
23+
shell: python
24+
25+
- name: quoted node shell
26+
shell: "node"
27+
run: |
28+
console.log("hi")
29+
30+
- name: unknown shell
31+
shell: ruby
32+
run: |
33+
puts "hi"

0 commit comments

Comments
 (0)