mirror of
https://github.com/docker/docs.git
synced 2026-03-27 06:18:55 +07:00
All mutable action tags replaced with verified commit SHAs to prevent supply-chain attacks via tag mutation. package.json ^ ranges replaced with exact versions from package-lock.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
104 lines
4.5 KiB
YAML
104 lines
4.5 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
|
|
|
|
env:
|
|
# Use edge release of buildx (latest RC, fallback to latest stable)
|
|
SETUP_BUILDX_VERSION: edge
|
|
SETUP_BUILDKIT_IMAGE: "moby/buildkit:latest"
|
|
|
|
jobs:
|
|
run:
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
-
|
|
name: Checkout
|
|
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
|
with:
|
|
repository: docker/docs
|
|
-
|
|
name: Download data files
|
|
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
|
|
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@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
|
|
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', 'cli', `${{ 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@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
|
|
with:
|
|
version: ${{ env.SETUP_BUILDX_VERSION }}
|
|
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
|
|
-
|
|
name: Validate
|
|
uses: docker/bake-action@82490499d2e5613fcead7e128237ef0b0ea210f7 # v7
|
|
with:
|
|
source: .
|
|
files: |
|
|
docker-bake.hcl
|
|
targets: validate-upstream
|
|
provenance: false
|
|
env:
|
|
UPSTREAM_MODULE_NAME: ${{ inputs.module-name }}
|
|
UPSTREAM_REPO: ${{ github.repository }}
|
|
UPSTREAM_COMMIT: ${{ github.sha }}
|