5050 if : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
5151 run : yarn build:storybook
5252
53+ - name : Build Docs
54+ # Don't run Storybook build on PRs from forks
55+ if : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
56+ run : |
57+ echo "Current content of docusaurus.config.ts:"
58+ cat packages/docs/docusaurus.config.ts
59+ # modify the docusaurus.config.ts, changing the baseUrl to /react-spectrum-charts/PR-${{ github.event.number }}-docs/
60+ sed -i 's|baseUrl: '"'"'/react-spectrum-charts/docs/'"'"'|baseUrl: '"'"'/react-spectrum-charts/PR-${{ github.event.number }}-docs/'"'"'|g' packages/docs/docusaurus.config.ts
61+ echo "Content after sed command:"
62+ cat packages/docs/docusaurus.config.ts
63+ # build the docs
64+ yarn build:docs
65+ # revert the docusaurus.config.ts
66+ git checkout packages/docs/docusaurus.config.ts
67+
5368 - name : Create and Upload Storybook to PR directory
5469 # Don't run Storybook upload on PRs from forks
5570 if : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
@@ -67,29 +82,60 @@ jobs:
6782
6883 # Remove the PR directory if it exists
6984 rm -rf "${PR_NUMBER}"
85+ rm -rf "${PR_NUMBER}-docs"
7086
7187 # Create the PR directory
7288 mkdir "${PR_NUMBER}"
89+ mkdir "${PR_NUMBER}-docs"
7390
7491 # Copy the contents of dist-storybook to the directory
7592 cp -r dist-storybook/* "${PR_NUMBER}/"
93+ cp -r packages/docs/dist/* "${PR_NUMBER}-docs/"
7694
7795 rm -rf node_modules # Explicitly remove the node_modules directory
7896 rm -rf dist-storybook # Explicitly remove the dist-storybook directory
7997
8098 # Add, commit, and push changes
8199 git add "${PR_NUMBER}/."
82- git commit -m "Update Storybook for ${PR_NUMBER}"
100+ git add "${PR_NUMBER}-docs/."
101+ git commit -m "Update Storybook and Docs for ${PR_NUMBER}"
83102 git push -f origin gh-pages
84103 env :
85104 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
86105
87- - name : Add comment to the PR with Storybook URL
106+ - name : Delete Storybook URL and Docs URL comment if it exists
107+ # Don't delete comment on PRs from forks
108+ if : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
109+ run : |
110+ PR_NUMBER="${{ github.event.number }}"
111+
112+ # Find comments with the Storybook URL and Docs URL
113+ COMMENT_IDS=$(curl -sSL \
114+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
115+ "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" | \
116+ jq -r '.[] | select(.body | contains("🎨 Storybook ->") or contains("📚 Docs ->")) | .id')
117+
118+ # Check if we found any comments
119+ if [ ! -z "$COMMENT_IDS" ]; then
120+ echo "Found matching comments to delete"
121+ # Loop through each comment ID
122+ echo "$COMMENT_IDS" | while read -r COMMENT_ID; do
123+ echo "Deleting comment with ID: $COMMENT_ID"
124+ curl -sSL \
125+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
126+ -X DELETE \
127+ "https://api.github.com/repos/${{ github.repository }}/issues/comments/${COMMENT_ID}"
128+ done
129+ else
130+ echo "No matching comments found to delete"
131+ fi
132+
133+ - name : Add comment to the PR with Storybook URL and Docs URL
88134 # Don't add comment on PRs from forks
89135 if : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
90136 run : |
91137 PR_NUMBER="${{ github.event.number }}"
92- COMMENT_BODY="🎨 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-${PR_NUMBER}"
138+ COMMENT_BODY="🎨 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-${PR_NUMBER}\n\n📚 Docs -> https://opensource.adobe.com/react-spectrum-charts/PR-${PR_NUMBER}-docs/ "
93139
94140 curl -sSL \
95141 -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
0 commit comments