# reusable workflow to validate docs from upstream repository for which pages are remotely fetched # - repo: upstream repository (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: 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@v4 with: repository: docker/docs - 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 = `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@v2 - name: Validate uses: docker/bake-action@v3 with: files: | docker-bake.hcl targets: validate set: | *.args.REPO="github.com/${{ github.repository }}" *.args.HUGO_MODULE_REPLACEMENTS="github.com/${{ github.repository }} -> github.com/${{ github.repository}} ${{ github.ref }}" *.cache-from=type=gha,scope=docs-upstream *.cache-to=type=gha,scope=docs-upstream,mode=max