|
| 1 | +name: Update latest Community documentation in the website |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - 'master' |
| 8 | + paths: |
| 9 | + - 'docs/**/*.md' |
| 10 | + |
| 11 | +jobs: |
| 12 | + Make-PR: |
| 13 | + name: Make PR on website repository with updated latest Community documentation |
| 14 | + runs-on: ubuntu-latest |
| 15 | + env: |
| 16 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 17 | + steps: |
| 18 | + - name: Checkout Current repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + path: community |
| 22 | + - name: Checkout Another repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + repository: asyncapi/website |
| 26 | + path: website |
| 27 | + token: ${{ env.GITHUB_TOKEN }} |
| 28 | + - name: Config git |
| 29 | + run: | |
| 30 | + git config --global user.name asyncapi-bot |
| 31 | + git config --global user.email [email protected] |
| 32 | + - name: Create branch |
| 33 | + working-directory: ./website |
| 34 | + run: | |
| 35 | + git checkout -b update-community-docs-${{ github.sha }} |
| 36 | + - name: Update edit-page-config.json |
| 37 | + uses: actions/github-script@v4 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const fs = require('fs').promises; |
| 41 | + const configPath = './website/config/edit-page-config.json'; |
| 42 | + const configData = require(configPath); |
| 43 | + const docsDir = 'community/docs'; |
| 44 | + |
| 45 | + async function readDirectories(dirPath) { |
| 46 | + const entries = await fs.readdir(dirPath, { withFileTypes: true }); |
| 47 | + const subdirectories = entries.filter(entry => entry.isDirectory()).map(entry => entry.name); |
| 48 | + return subdirectories; |
| 49 | + } |
| 50 | + |
| 51 | + async function updateConfigData() { |
| 52 | + const subfolders = await readDirectories(docsDir); |
| 53 | + |
| 54 | + for (const subfolder of subfolders) { |
| 55 | + const checkSlug = `community/${subfolder}`; |
| 56 | + const slug = { |
| 57 | + "value": checkSlug, |
| 58 | + "href": `https://github.com/asyncapi/community/tree/master/docs/${subfolder}` |
| 59 | + }; |
| 60 | + |
| 61 | + const entryExists = configData.some(entry => entry.value === checkSlug); |
| 62 | + if (!entryExists) { |
| 63 | + configData.push(slug); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + await fs.writeFile(configPath, JSON.stringify(configData, null, 2)); |
| 68 | + } |
| 69 | + updateConfigData(); |
| 70 | +
|
| 71 | + - name: Copy community folder from Current Repo to Another |
| 72 | + working-directory: ./website |
| 73 | + run: | |
| 74 | + find "./markdown/docs/community" -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} + |
| 75 | + rm ../community/docs/README.md |
| 76 | + mv ../community/docs/* ./markdown/docs/community/ |
| 77 | + - name: Commit and push |
| 78 | + working-directory: ./website |
| 79 | + run: | |
| 80 | + git add . |
| 81 | + git commit -m "docs(community): update latest community docs" |
| 82 | + git push https://${{ env.GITHUB_TOKEN }}@github.com/asyncapi/website |
| 83 | + - name: Create PR |
| 84 | + working-directory: ./website |
| 85 | + run: | |
| 86 | + gh pr create --title "docs(community): update latest community documentation" --body "Updated community documentation is available and this PR introduces update to community folder on the website" --head "update-community-docs-${{ github.sha }}" |
0 commit comments