From 945137496f57fea0e1db48b296bd1a1180848731 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Wed, 21 Feb 2024 22:44:24 +0100 Subject: [PATCH] ci: fix validate upstream workflow Moving the CLI reference files caused the upstream validation workflow to break. This changes the logic in how placeholder files are created in the validation workflow, to match the new filesystem structure for markdown stubs. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- .github/workflows/validate-upstream.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/validate-upstream.yml b/.github/workflows/validate-upstream.yml index ee63593151ad..14525d9a35f9 100644 --- a/.github/workflows/validate-upstream.yml +++ b/.github/workflows/validate-upstream.yml @@ -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: @@ -41,10 +41,9 @@ 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 @@ -52,13 +51,18 @@ jobs: 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; 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'); + }; + 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(/\.[^/.]+$/, '')}