mirror of https://github.com/docker/docs.git
125 lines
4.9 KiB
YAML
125 lines
4.9 KiB
YAML
# reusable workflow to validate docs from upstream repository for which pages are remotely fetched
|
|
# - repo: repository to handle from fetch-remote in _config.yml (e.g., https://github.com/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)
|
|
name: validate-upstream
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
repo:
|
|
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-latest
|
|
steps:
|
|
-
|
|
name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
repository: docker/docs
|
|
-
|
|
name: Install js-yaml
|
|
run: npm install js-yaml
|
|
-
|
|
name: Set correct ref to fetch remote resources
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
const fs = require('fs');
|
|
const yaml = require('js-yaml');
|
|
|
|
const configFile = '_config.yml'
|
|
const config = yaml.load(fs.readFileSync(configFile, 'utf8'));
|
|
for (const remote of config['fetch-remote']) {
|
|
if (remote['repo'] != '${{ inputs.repo }}') {
|
|
continue;
|
|
}
|
|
if ("${{ github.event_name }}" == "pull_request") {
|
|
remote['repo'] = "${{ github.event.pull_request.head.repo.html_url }}";
|
|
remote['ref'] = "${{ github.event.pull_request.head.ref }}"
|
|
} else {
|
|
remote['ref'] = "${{ github.ref_name }}";
|
|
}
|
|
}
|
|
|
|
try {
|
|
fs.writeFileSync(configFile, yaml.dump(config), 'utf8')
|
|
} catch (err) {
|
|
console.error(err.message)
|
|
process.exit(1)
|
|
}
|
|
-
|
|
name: Prepare
|
|
run: |
|
|
# print docs jekyll config updated in previous step
|
|
yq _config.yml
|
|
# cleanup js-yaml module and data files
|
|
rm -rf ./node_modules
|
|
if [ -n "./_data/${{ inputs.data-files-folder }}" ]; then
|
|
rm -rf ./_data/${{ inputs.data-files-folder }}/*
|
|
fi
|
|
-
|
|
name: Download data files
|
|
uses: actions/download-artifact@v3
|
|
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@v6
|
|
with:
|
|
script: |
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const dataFilesPlaceholderFolder = `${{ 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('_', ' ')}
|
|
---
|
|
{% include cli.md datafolder=page.datafolder datafile=page.datafile %}`;
|
|
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@v2
|
|
-
|
|
name: Validate
|
|
uses: docker/bake-action@v2
|
|
with:
|
|
targets: validate
|
|
set: |
|
|
*.cache-from=type=gha,scope=docs-upstream
|
|
*.cache-to=type=gha,scope=docs-upstream,mode=max
|