Files
docker-docs/.github/workflows/validate-upstream.yml
David Karlsson aa2726dfd5 ci: use ubuntu-22.04
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
2024-02-16 09:44:45 +01:00

93 lines
3.9 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
data-files-placeholder-folder:
required: false
type: string
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 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.
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 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)) {
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 }}