-
Notifications
You must be signed in to change notification settings - Fork 7.4k
105 lines (102 loc) · 4.41 KB
/
validate-upstream.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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@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
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
-
name: Validate
uses: docker/bake-action@v6
with:
source: .
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 }}