Skip to content

Commit f5ea254

Browse files
committed
ci: create placeholder file for new commands before validation
Signed-off-by: CrazyMax <[email protected]>
1 parent 618b9c0 commit f5ea254

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

.github/workflows/validate-upstream.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ on:
1616
data-files-folder:
1717
required: false
1818
type: string
19+
data-files-placeholder-folder:
20+
required: false
21+
type: string
1922

2023
jobs:
2124
run:
@@ -73,7 +76,41 @@ jobs:
7376
if: ${{ inputs.data-files-id != '' && inputs.data-files-folder != '' }}
7477
with:
7578
name: ${{ inputs.data-files-id }}
76-
path: ./_data/${{ inputs.data-files-folder }}
79+
path: /tmp/_data/${{ inputs.data-files-folder }}
80+
-
81+
# Copy data files from /tmp/_data/${{ inputs.data-files-folder }} to
82+
# _data/${{ inputs.data-files-folder }}. If data-files-placeholder-folder
83+
# is set, then check if a placeholder file exists for each data file in
84+
# that folder. If not, then creates a placeholder file with the same
85+
# name as the data file, but with a .md extension.
86+
name: Copy data files
87+
if: ${{ inputs.data-files-id != '' && inputs.data-files-folder != '' }}
88+
uses: actions/github-script@v6
89+
with:
90+
script: |
91+
const fs = require('fs');
92+
const path = require('path');
93+
const dataFilesPlaceholderFolder = `${{ inputs.data-files-placeholder-folder }}`;
94+
const globber = await glob.create(`/tmp/_data/${{ inputs.data-files-folder }}/*.yaml`);
95+
for await (const yamlSrcPath of globber.globGenerator()) {
96+
const yamlSrcFilename = path.basename(yamlSrcPath);
97+
const yamlDestPath = path.join('_data', `${{ inputs.data-files-folder }}`, yamlSrcFilename);
98+
const placeholderPath = path.join(dataFilesPlaceholderFolder, yamlSrcFilename.replace(/^docker_/, '').replace(/\.yaml$/, '.md'));
99+
if (dataFilesPlaceholderFolder !== '' && !fs.existsSync(placeholderPath)) {
100+
const placeholderContent = `---
101+
datafolder: ${{ inputs.data-files-folder }}
102+
datafile: ${yamlSrcFilename.replace(/\.[^/.]+$/, '')}
103+
title: ${yamlSrcFilename.replace(/\.[^/.]+$/, "").replaceAll('_', ' ')}
104+
---
105+
{% include cli.md datafolder=page.datafolder datafile=page.datafile %}`;
106+
await core.group(`creating ${placeholderPath}`, async () => {
107+
core.info(placeholderContent);
108+
});
109+
await fs.writeFileSync(placeholderPath, placeholderContent);
110+
}
111+
core.info(`${yamlSrcPath} => ${yamlDestPath}`);
112+
await fs.copyFileSync(yamlSrcPath, yamlDestPath);
113+
}
77114
-
78115
name: Set up Docker Buildx
79116
uses: docker/setup-buildx-action@v2

0 commit comments

Comments
 (0)