Sync Remote Docs #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Remote Docs | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| target_tag: | |
| description: "Target Tag" | |
| required: true | |
| default: "0.11.26" | |
| enforce_version_continuity: | |
| description: "Fail if target tag is not the immediate next semver after current latest" | |
| required: false | |
| type: boolean | |
| default: true | |
| jobs: | |
| main: | |
| name: "Sync Remote Docs" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout TEN-framework/ten-framework with target tag | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Fetch full history including all tags | |
| repository: TEN-framework/ten-framework | |
| ref: ${{ github.event.inputs.target_tag }} | |
| path: ten_framework/${{ github.event.inputs.target_tag }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Checkout TEN-framework/portal | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Fetch full history including all tags | |
| repository: TEN-framework/portal | |
| path: portal | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get Previous Docs Version from portal | |
| id: previous_docs_version | |
| run: | | |
| cat portal/content/docs/ten_framework/_version.json | jq -r '.latest' | |
| latest=$(cat portal/content/docs/ten_framework/_version.json | jq -r '.latest') | |
| echo "latest=$latest" >> $GITHUB_OUTPUT | |
| cd ${{ github.workspace }} | |
| - name: Checkout TEN-framework/ten-framework with previous docs version | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Fetch full history including all tags | |
| repository: TEN-framework/ten-framework | |
| ref: ${{ steps.previous_docs_version.outputs.latest }} | |
| path: ten_framework/${{ steps.previous_docs_version.outputs.latest }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Diff remote docs between target tag and previous docs version | |
| # id: diff_remote_docs | |
| run: | | |
| cd ten_framework/${{ github.event.inputs.target_tag }} | |
| # list all ADDED files in target tag | |
| echo "-------------------------------- added_files --------------------------------" | |
| git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=A ./docs | |
| added_files=$(git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=A ./docs) | |
| # echo "added_files=$added_files" >> $GITHUB_OUTPUT | |
| echo $added_files | |
| echo "----------------------------------------------------------------" | |
| # list all DELETED files in previous docs version | |
| echo "-------------------------------- deleted_files --------------------------------" | |
| git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=D ./docs | |
| deleted_files=$(git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=D ./docs) | |
| # echo "deleted_files=$deleted_files" >> $GITHUB_OUTPUT | |
| echo $deleted_files | |
| echo "----------------------------------------------------------------" | |
| # list all MODIFIED files in target tag | |
| echo "-------------------------------- modified_files --------------------------------" | |
| git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=M ./docs | |
| modified_files=$(git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=M ./docs) | |
| # echo "modified_files=$modified_files" >> $GITHUB_OUTPUT | |
| echo $modified_files | |
| echo "----------------------------------------------------------------" | |
| # list all RENAMED files in target tag | |
| echo "-------------------------------- renamed_files --------------------------------" | |
| git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=R ./docs | |
| renamed_files=$(git diff ${{ steps.previous_docs_version.outputs.latest }}..${{ github.event.inputs.target_tag }} --name-only --diff-filter=R ./docs) | |
| # echo "renamed_files=$renamed_files" >> $GITHUB_OUTPUT | |
| echo $renamed_files | |
| echo "----------------------------------------------------------------" | |
| cd ${{ github.workspace }} | |
| cd portal | |
| # checkout to a new branch for sync | |
| git checkout -b sync/${{ github.event.inputs.target_tag }} | |
| # create new records in .tmp/diff.json | |
| mkdir -p .tmp | |
| touch .tmp/diff.json | |
| echo "{\"added_files\":[], \"deleted_files\":[], \"modified_files\":[], \"renamed_files\":[]}" > .tmp/diff.json | |
| # Save all files (added, deleted, modified, renamed) as string arrays by key in .tmp/diff.json | |
| jq -n \ | |
| --arg added "$added_files" \ | |
| --arg deleted "$deleted_files" \ | |
| --arg modified "$modified_files" \ | |
| --arg renamed "$renamed_files" \ | |
| '{ | |
| added_files: ($added | split("\n") | map(select(. != ""))), | |
| deleted_files: ($deleted | split("\n") | map(select(. != ""))), | |
| modified_files: ($modified | split("\n") | map(select(. != ""))), | |
| renamed_files: ($renamed | split("\n") | map(select(. != ""))) | |
| }' > .tmp/diff.json | |
| echo "-------------------------------- diff.json --------------------------------" | |
| cat .tmp/diff.json | |
| echo "----------------------------------------------------------------" | |
| cd ${{ github.workspace }} | |
| - name: Checkout TEN-framework/ten-framework with current tag | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Fetch full history including all tags | |
| repository: TEN-framework/ten-framework | |
| ref: ${{ steps.previous_docs_version.outputs.latest }} | |
| path: ten_framework/${{ steps.previous_docs_version.outputs.latest }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Run Scripts | |
| env: | |
| GH_TOKEN: ${{ secrets.TEN_FRAMEWORK_PORTAL_ACTION_PAT }} | |
| run: | | |
| cd portal | |
| # git status | |
| git status | |
| # git config | |
| git config user.name "GitHub Actions" | |
| git config user.email "github-actions@github.com" | |
| # install dependencies | |
| bun i | |
| # run scripts | |
| bun run scripts:sync-remote-docs --new-version ${{ github.event.inputs.target_tag }} --diff-json ${{ github.workspace }}/portal/.tmp/diff.json --prev-repo ${{ github.workspace }}/ten_framework/${{ steps.previous_docs_version.outputs.latest }} --latest-repo ${{ github.workspace }}/ten_framework/${{ github.event.inputs.target_tag }} --doc-config ${{ github.workspace }}/ten_framework/${{ github.event.inputs.target_tag }}/docs/_portal_config.json --enforce-version-continuity ${{ github.event.inputs.enforce_version_continuity }} | |
| # bun lint | |
| bun run lint | |
| # git status | |
| git status | |
| # git add all files under content/docs/ten_framework | |
| git add content/docs/ten_framework | |
| # git commit | |
| git commit -m "[sync-remote-docs] sync remote docs for ${{ github.event.inputs.target_tag }}" | |
| # git push | |
| git push origin sync/${{ github.event.inputs.target_tag }} | |
| # create a pull request | |
| gh pr create --base "${{ github.ref_name }}" --title "[sync-remote-docs] ${{ github.event.inputs.target_tag }}" --body "Sync remote docs for ${{ github.event.inputs.target_tag }}" | |
| # # upload diff.json to actions artifact | |
| # gh run upload ${{ github.run_id }} .tmp/diff.json |