Skip to content

Commit 32e2d02

Browse files
authored
feat(setup-elementor-env): allow enabling svg upload [ED-18594] (#29)
1 parent 76d966b commit 32e2d02

File tree

5 files changed

+64
-29
lines changed

5 files changed

+64
-29
lines changed

.github/workflows/test-actions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
uses: ./actions/setup-elementor-env
3636
with:
3737
env: 'testing'
38+
enable-svg-upload: true
3839
experiments: |-
3940
pages_panel:true
4041
editor_v2:false

actions/setup-elementor-env/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ inputs:
66
description: Which wp-env environment to use (allowed values are `development` or `testing`)
77
required: false
88
default: 'testing'
9+
enable-svg-upload:
10+
required: false
11+
description: Whether to enable SVG and JSON uploads or not
12+
default: 'false'
913
templates:
1014
required: false
1115
description: Paths to the Elementor templates directory, separated by new lines (e.g. `./path/to/elementor-templates \n ./another/path/to/elementor-templates`)

actions/setup-elementor-env/dist/index.js

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/setup-elementor-env/main.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import {
55
getArrayInput,
66
getMapInput,
77
getStringInput,
8+
getBooleanInput,
89
} from '@elementor-editor-github-actions/utils';
910

1011
export async function run() {
1112
try {
12-
const { container, experiments, templates } = await core.group(
13-
'Parsing inputs',
14-
parseInputs,
15-
);
13+
const { container, experiments, templates, wpOptions } =
14+
await core.group('Parsing inputs', parseInputs);
1615

1716
await core.group('Validating wp-env installation', async () => {
1817
await runOnContainer({
@@ -30,6 +29,16 @@ export async function run() {
3029
});
3130
});
3231

32+
await core.group('Setting WP Options', async () => {
33+
for (const { key, value } of wpOptions) {
34+
await runOnContainer({
35+
container,
36+
command: ['wp', 'option', 'update', key, value],
37+
error: `Failed to set option: ${key} to ${value}`,
38+
});
39+
}
40+
});
41+
3342
if (experiments.on.length > 0) {
3443
await core.group('Activating Experiments', async () => {
3544
await runOnContainer({
@@ -114,11 +123,13 @@ async function parseInputs() {
114123
z.string().regex(/^[a-z0-9-_]+$/),
115124
z.union([z.literal('true'), z.literal('false')]),
116125
),
126+
enableSvgUpload: z.boolean(),
117127
})
118128
.parse({
119129
env: getStringInput('env'),
120130
templates: getArrayInput('templates'),
121131
experiments: getMapInput('experiments'),
132+
enableSvgUpload: getBooleanInput('enable-svg-upload'),
122133
});
123134

124135
const experimentsEntries = Object.entries(parsed.experiments);
@@ -129,6 +140,9 @@ async function parseInputs() {
129140
? ('cli' as const)
130141
: ('tests-cli' as const),
131142
templates: parsed.templates,
143+
wpOptions: normalizeWpOptions({
144+
enableSvgUpload: parsed.enableSvgUpload,
145+
}),
132146
experiments: {
133147
on: experimentsEntries
134148
.filter(([, value]) => value === 'true')
@@ -151,6 +165,22 @@ async function parseInputs() {
151165
}
152166
}
153167

168+
function normalizeWpOptions({ enableSvgUpload }: { enableSvgUpload: boolean }) {
169+
const wpOptions: {
170+
key: string;
171+
value: string;
172+
}[] = [];
173+
174+
if (enableSvgUpload) {
175+
wpOptions.push({
176+
key: 'elementor_unfiltered_files_upload',
177+
value: '1',
178+
});
179+
}
180+
181+
return wpOptions;
182+
}
183+
154184
async function runOnContainer({
155185
container,
156186
command,

stubs/elementor-templates/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@
8585
"elType": "container"
8686
}
8787
],
88-
"settings": { "template": "elementor_canvas" }
88+
"page_settings": { "template": "elementor_canvas" }
8989
}

0 commit comments

Comments
 (0)