Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/workflows/validate-upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ on:
data-files-folder:
required: false
type: string
data-files-placeholder-folder:
create-placeholder-stubs:
type: boolean
required: false
type: string

jobs:
run:
Expand All @@ -41,24 +41,28 @@ jobs:
path: /tmp/data/${{ inputs.data-files-folder }}
-
# Copy data files from /tmp/data/${{ inputs.data-files-folder }} to
# data/${{ inputs.data-files-folder }}. If data-files-placeholder-folder
# is set, then check if a placeholder file exists for each data file in
# that folder. If not, then creates a placeholder file with the same
# name as the data file, but with a .md extension.
# data/${{ inputs.data-files-folder }}. If create-placeholder-stubs
# is set to true, then check if a placeholder file exists for each data file in
# that folder. If not, create a placeholder stub file for the data file.
name: Copy data files
if: ${{ inputs.data-files-id != '' && inputs.data-files-folder != '' }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const dataFilesPlaceholderFolder = `content/${{ inputs.data-files-placeholder-folder }}`;
const globber = await glob.create(`/tmp/data/${{ inputs.data-files-folder }}/*.yaml`);
for await (const yamlSrcPath of globber.globGenerator()) {
const yamlSrcFilename = path.basename(yamlSrcPath);
const yamlSrcNoExt = yamlSrcPath.replace(".yaml", "");
const hasSubCommands = (await (await glob.create(yamlSrcNoExt)).glob()).length > 1;
Comment on lines +57 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks if there are more than one data files with the same base name, indicating that the current data file has subcommands.

const yamlDestPath = path.join('data', `${{ inputs.data-files-folder }}`, yamlSrcFilename);
const placeholderPath = path.join(dataFilesPlaceholderFolder, yamlSrcFilename.replace(/^docker_/, '').replace(/\.yaml$/, '.md'));
if (dataFilesPlaceholderFolder !== '' && !fs.existsSync(placeholderPath)) {
let placeholderPath = path.join("content/reference/cli", yamlSrcFilename.replace('_', '/').replace(/\.yaml$/, '.md'));
if (hasSubCommands) {
placeholderPath = placeholderPath.replace('.md', '/_index.md');
};
Comment on lines +61 to +63
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this has subcommands, the stub filename should be content/reference/cli/docker/cmd/_index.md.

if (`${{ inputs.create-placeholder-stubs }}` && !fs.existsSync(placeholderPath)) {
fs.mkdirSync(path.dirname(placeholderPath), { recursive: true });
const placeholderContent = `---
datafolder: ${{ inputs.data-files-folder }}
datafile: ${yamlSrcFilename.replace(/\.[^/.]+$/, '')}
Expand Down