|
| 1 | +name: Update latest Bindings documentation in the website |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - "**/*.md" |
| 9 | + - ".github/workflows/update-docs-in-website.yml" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + Make-PR: |
| 14 | + name: Make PR on website repository with updated latest Bindings documentation |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 18 | + steps: |
| 19 | + - name: Checkout Current repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + path: bindings |
| 23 | + - name: Checkout Another repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + repository: asyncapi/website |
| 27 | + path: website |
| 28 | + token: ${{ env.GITHUB_TOKEN }} |
| 29 | + - name: Config git |
| 30 | + run: | |
| 31 | + git config --global user.name asyncapi-bot |
| 32 | + git config --global user.email [email protected] |
| 33 | + - name: Create branch |
| 34 | + working-directory: ./website |
| 35 | + run: | |
| 36 | + git checkout -b update-bindings-docs-${{ github.sha }} |
| 37 | + - name: Update edit-page-config.json |
| 38 | + uses: actions/github-script@v4 |
| 39 | + with: |
| 40 | + script: | |
| 41 | + const { writeFile } = require('fs').promises; |
| 42 | + const configPath = './website/config/edit-page-config.json'; |
| 43 | + const checkSlug = 'reference/bindings/'; |
| 44 | + const slug = { |
| 45 | + "value": checkSlug, |
| 46 | + "href": "https://github.com/asyncapi/bindings/tree/master" |
| 47 | + }; |
| 48 | +
|
| 49 | + const configData = require(configPath); |
| 50 | + const entryExists = configData.some(entry => entry.value === checkSlug); |
| 51 | + if (!entryExists) { |
| 52 | + configData.unshift(slug); |
| 53 | + await writeFile(configPath, JSON.stringify(configData, null, 2)) |
| 54 | + } |
| 55 | +
|
| 56 | + - name: Update title and weight of the markdown files |
| 57 | + uses: actions/github-script@v4 |
| 58 | + with: |
| 59 | + script: | |
| 60 | + const fs = require('fs'); |
| 61 | + const path = require('path'); |
| 62 | + const rootPath = './bindings/'; |
| 63 | + let itemIndex = 10; |
| 64 | +
|
| 65 | + function processMarkdownFiles(folderPath, isRoot = true) { |
| 66 | + const items = fs.readdirSync(folderPath, { withFileTypes: true }); |
| 67 | + for (const item of items) { |
| 68 | + const fullPath = path.join(folderPath, item.name); |
| 69 | + if (item.isDirectory()) { |
| 70 | + // Always process subdirectories, mark isRoot as false for recursive calls |
| 71 | + processMarkdownFiles(fullPath, false); |
| 72 | + } else if (item.name.endsWith('.md') && !isRoot) { // Skip root level .md files |
| 73 | + const baseName = path.basename(fullPath, '.md'); |
| 74 | + const parentDirName = path.basename(folderPath); |
| 75 | + const newFileName = `${parentDirName}.md`; |
| 76 | + const newFullPath = path.join(folderPath, newFileName); |
| 77 | + fs.renameSync(fullPath, newFullPath); |
| 78 | + |
| 79 | + const newData = `---\ntitle: '${parentDirName}'\nweight: ${itemIndex}\n---\n\n`; |
| 80 | + let existingFileData = fs.readFileSync(newFullPath, 'utf8'); |
| 81 | + |
| 82 | + existingFileData = existingFileData.replace(/<img\s+src="(?!http)(.*?)"/g, (match, src) => { |
| 83 | + // Remove './' prefix from src path and prepend '/img/docs/' |
| 84 | + const updatedSrc = src.replace(/^\.\//, ''); |
| 85 | + return `<img src="/img/docs/${updatedSrc}"`; |
| 86 | + }); |
| 87 | + |
| 88 | + const updatedContent = newData + existingFileData; |
| 89 | + fs.writeFileSync(newFullPath, updatedContent); |
| 90 | + itemIndex++; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +
|
| 95 | + await processMarkdownFiles(rootPath); |
| 96 | +
|
| 97 | + - name: Copy bindings folder from Current Repo to Another |
| 98 | + working-directory: ./website |
| 99 | + run: | |
| 100 | + mkdir -p ./markdown/docs/reference/bindings |
| 101 | + printf "%s\ntitle: Bindings\nweight: 11\n%s" "---" "---"> ../bindings/_section.md |
| 102 | + find ../bindings -type f -name '*.md' ! -name 'CONTRIBUTING.md' ! -name 'README.md' ! -name 'CODE_OF_CONDUCT.md' -exec mv {} ./markdown/docs/reference/bindings/ \; |
| 103 | +
|
| 104 | + - name: Copy images to website |
| 105 | + run: | |
| 106 | + # Assuming the workflow runs on Linux/macOS |
| 107 | + # Create the target directory if it doesn't exist |
| 108 | + mkdir -p ./website/public/img/docs/ |
| 109 | + # Find and copy all image files from the source directory to the target directory |
| 110 | + find ./bindings/ -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" -iname "*.webp" \) -exec cp {} ./website/public/img/docs/ \; |
| 111 | +
|
| 112 | + - name: Commit and push |
| 113 | + working-directory: ./website |
| 114 | + run: | |
| 115 | + git add . |
| 116 | + git commit -m "docs(extension): update latest bindings docs" |
| 117 | + git push https://${{ env.GITHUB_TOKEN }}@github.com/asyncapi/website |
| 118 | +
|
| 119 | + - name: Create PR |
| 120 | + working-directory: ./website |
| 121 | + run: | |
| 122 | + gh pr create --title "docs(bindings): update latest bindings documentation" --body "Updated bindings documentation is available and this PR introduces update to bindings folder on the website" --head "update-bindings-docs-${{ github.sha }}" |
0 commit comments