|
16 | 16 | data-files-folder: |
17 | 17 | required: false |
18 | 18 | type: string |
| 19 | + data-files-placeholder-folder: |
| 20 | + required: false |
| 21 | + type: string |
19 | 22 |
|
20 | 23 | jobs: |
21 | 24 | run: |
|
73 | 76 | if: ${{ inputs.data-files-id != '' && inputs.data-files-folder != '' }} |
74 | 77 | with: |
75 | 78 | name: ${{ inputs.data-files-id }} |
76 | | - path: ./_data/${{ inputs.data-files-folder }} |
| 79 | + path: /tmp/_data/${{ inputs.data-files-folder }} |
| 80 | + - |
| 81 | + # Copy data files from /tmp/_data/${{ inputs.data-files-folder }} to |
| 82 | + # _data/${{ inputs.data-files-folder }}. If data-files-placeholder-folder |
| 83 | + # is set, then check if a placeholder file exists for each data file in |
| 84 | + # that folder. If not, then creates a placeholder file with the same |
| 85 | + # name as the data file, but with a .md extension. |
| 86 | + name: Copy data files |
| 87 | + if: ${{ inputs.data-files-id != '' && inputs.data-files-folder != '' }} |
| 88 | + uses: actions/github-script@v6 |
| 89 | + with: |
| 90 | + script: | |
| 91 | + const fs = require('fs'); |
| 92 | + const path = require('path'); |
| 93 | + const dataFilesPlaceholderFolder = `${{ inputs.data-files-placeholder-folder }}`; |
| 94 | + const globber = await glob.create(`/tmp/_data/${{ inputs.data-files-folder }}/*.yaml`); |
| 95 | + for await (const yamlSrcPath of globber.globGenerator()) { |
| 96 | + const yamlSrcFilename = path.basename(yamlSrcPath); |
| 97 | + const yamlDestPath = path.join('_data', `${{ inputs.data-files-folder }}`, yamlSrcFilename); |
| 98 | + const placeholderPath = path.join(dataFilesPlaceholderFolder, yamlSrcFilename.replace(/^docker_/, '').replace(/\.yaml$/, '.md')); |
| 99 | + if (dataFilesPlaceholderFolder !== '' && !fs.existsSync(placeholderPath)) { |
| 100 | + const placeholderContent = `--- |
| 101 | + datafolder: ${{ inputs.data-files-folder }} |
| 102 | + datafile: ${yamlSrcFilename.replace(/\.[^/.]+$/, '')} |
| 103 | + title: ${yamlSrcFilename.replace(/\.[^/.]+$/, "").replaceAll('_', ' ')} |
| 104 | + --- |
| 105 | + {% include cli.md datafolder=page.datafolder datafile=page.datafile %}`; |
| 106 | + await core.group(`creating ${placeholderPath}`, async () => { |
| 107 | + core.info(placeholderContent); |
| 108 | + }); |
| 109 | + await fs.writeFileSync(placeholderPath, placeholderContent); |
| 110 | + } |
| 111 | + core.info(`${yamlSrcPath} => ${yamlDestPath}`); |
| 112 | + await fs.copyFileSync(yamlSrcPath, yamlDestPath); |
| 113 | + } |
77 | 114 | - |
78 | 115 | name: Set up Docker Buildx |
79 | 116 | uses: docker/setup-buildx-action@v2 |
|
0 commit comments