mirror of
https://github.com/docker/docs.git
synced 2026-03-27 14:28:47 +07:00
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>
97 lines
4.1 KiB
YAML
97 lines
4.1 KiB
YAML
# reusable workflow to validate docs from upstream repository for which pages are remotely fetched
|
|
# - module-name: the name of the module, without github.com prefix (e.g., docker/buildx)
|
|
# - data-files-id: id of the artifact (using actions/upload-artifact) containing the YAML data files to validate (optional)
|
|
# - data-files-folder: folder in _data containing the files to download and copy to (e.g., buildx)
|
|
# if changes are made in this workflow, please keep commit sha updated on downstream workflows:
|
|
# - https://github.com/docker/buildx/blob/master/.github/workflows/docs-upstream.yml
|
|
# - https://github.com/docker/compose/blob/main/.github/workflows/docs-upstream.yml
|
|
name: validate-upstream
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
module-name:
|
|
required: true
|
|
type: string
|
|
data-files-id:
|
|
required: false
|
|
type: string
|
|
data-files-folder:
|
|
required: false
|
|
type: string
|
|
create-placeholder-stubs:
|
|
type: boolean
|
|
required: false
|
|
|
|
jobs:
|
|
run:
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
-
|
|
name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: docker/docs
|
|
-
|
|
name: Download data files
|
|
uses: actions/download-artifact@v4
|
|
if: ${{ inputs.data-files-id != '' && inputs.data-files-folder != '' }}
|
|
with:
|
|
name: ${{ inputs.data-files-id }}
|
|
path: /tmp/data/${{ inputs.data-files-folder }}
|
|
-
|
|
# Copy data files from /tmp/data/${{ inputs.data-files-folder }} to
|
|
# 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 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);
|
|
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(/\.[^/.]+$/, '')}
|
|
title: ${yamlSrcFilename.replace(/\.[^/.]+$/, "").replaceAll('_', ' ')}
|
|
layout: cli
|
|
---`;
|
|
await core.group(`creating ${placeholderPath}`, async () => {
|
|
core.info(placeholderContent);
|
|
});
|
|
await fs.writeFileSync(placeholderPath, placeholderContent);
|
|
}
|
|
core.info(`${yamlSrcPath} => ${yamlDestPath}`);
|
|
await fs.copyFileSync(yamlSrcPath, yamlDestPath);
|
|
}
|
|
-
|
|
name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
-
|
|
name: Validate
|
|
uses: docker/bake-action@v4
|
|
with:
|
|
files: |
|
|
docker-bake.hcl
|
|
targets: validate-upstream
|
|
set: |
|
|
*.cache-from=type=gha,scope=docs-upstream
|
|
*.cache-to=type=gha,scope=docs-upstream
|
|
env:
|
|
UPSTREAM_MODULE_NAME: ${{ inputs.module-name }}
|
|
UPSTREAM_REPO: ${{ github.repository }}
|
|
UPSTREAM_COMMIT: ${{ github.sha }}
|