[CONTENT] Add RA for BDC + AI Core #1317
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: PR Site Build | |
| on: | |
| pull_request_target: | |
| branches: | |
| - dev | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| - closed | |
| env: | |
| # https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request | |
| PR_FOLDER: preview/${{github.event.pull_request.user.login}}-${{github.event.pull_request.head.ref}} | |
| jobs: | |
| build: | |
| name: Build Site for PR | |
| runs-on: ubuntu-latest | |
| # Note: only run when trigger is 'pull_request' in case pull request is from the same repo (see https://github.com/orgs/community/discussions/26829#discussioncomment-3253575) | |
| if: (github.event_name == 'pull_request_target' || github.event.pull_request.base.repo.fork) && github.event.pull_request.merged != true && github.event.pull_request.state != 'closed' | |
| steps: | |
| - name: Checkout PR Code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{github.event.pull_request.head.sha}} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| cache: npm | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Get pages deployment URL | |
| run: | | |
| pages_url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url') | |
| url=$(echo $pages_url|cut -d'/' -f 1)//$(echo $pages_url|cut -d'/' -f 3) | |
| base_url=$(echo $pages_url|cut -d'/' -f 4) | |
| echo "url=$url" >> "$GITHUB_ENV" | |
| echo "base_url=$base_url" >> "$GITHUB_ENV" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Patch docusaurus.config.ts for PR builds | |
| run: | | |
| sed -E -i "s^url:(..*)^url: '${{ env.url }}',^g" docusaurus.config.ts | |
| sed -E -i "s^const baseUrl = '(.*)';^const baseUrl = '/@$PR_FOLDER/';^g" docusaurus.config.ts | |
| sed -E -i "s^title: 'Architecture Center'^title: 'Architecture Center (PR: #${PR_NUMBER})'^g" docusaurus.config.ts | |
| sed -E -i "s^logo: \{^logo: \{href: '${{ github.event.pull_request.html_url }}',^g" docusaurus.config.ts | |
| env: | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| - name: Verify Patch Application | |
| run: cat docusaurus.config.ts | |
| - name: Fetch contributors details from GitHub API | |
| env: | |
| GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
| run: node src/_scripts/_fetch-contributors-details.js | |
| - name: Export drawios to svgs | |
| run: DOCKER=1 node src/_scripts/_export-drawios.js | |
| - name: Build Website | |
| run: npm run build | |
| - name: Delete sitemap.xml | |
| run: | | |
| if [ -f build/sitemap.xml ]; then | |
| rm build/sitemap.xml | |
| echo "Deleted sitemap.xml from build output." | |
| else | |
| echo "No sitemap.xml found to delete." | |
| fi | |
| - name: Delete robots.txt | |
| run: | | |
| if [ -f build/robots.txt ]; then | |
| rm build/robots.txt | |
| echo "Deleted robots.txt from build output." | |
| else | |
| echo "No robots.txt found to delete." | |
| fi | |
| - name: Upload Build Artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: build | |
| deploy: | |
| name: Deploy Site for PR | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: success() && (github.event_name == 'pull_request_target' || github.event.pull_request.base.repo.fork) && github.event.pull_request.merged != true && github.event.pull_request.state != 'closed' | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{github.event.pull_request.head.sha}} | |
| token: ${{ secrets.PAASAPCOM_PAT }} | |
| - name: Download Build Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: build/ | |
| - name: Set up Git | |
| run: | | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "paasapcom" | |
| - name: Switch to Pages Branch | |
| run: | | |
| gh_pages_branch=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.source.branch') | |
| git fetch origin $gh_pages_branch | |
| git checkout $gh_pages_branch | |
| echo "gh_pages_branch=$gh_pages_branch" >> "$GITHUB_ENV" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Drop Previous Content | |
| run: | | |
| rm -rf @$PR_FOLDER | |
| mkdir -p @$PR_FOLDER | |
| - name: Extract Build Content | |
| run: | | |
| if [[ -d "build" && "$(ls -A build)" ]]; then | |
| mv build/* @$PR_FOLDER/ | |
| cd @$PR_FOLDER/ | |
| tar -xvf github-pages/artifact.tar | |
| rm github-pages/artifact.tar | |
| else | |
| echo "No build files found. Skipping move step." | |
| fi | |
| - name: Commit and Push Changes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAASAPCOM_PAT }} | |
| run: | | |
| git add -A | |
| if [[ "$(git status -s)" ]]; then | |
| git commit -m "pr build ➝ gh pages" | |
| git push -f origin ${{ env.gh_pages_branch }} | |
| fi | |
| pr_comment: | |
| name: Post Preview Link (PRs) | |
| needs: deploy | |
| runs-on: ubuntu-latest | |
| if: (github.event_name == 'pull_request_target' || github.event.pull_request.base.repo.fork) && github.event.pull_request.merged != true && github.event.pull_request.state != 'closed' | |
| permissions: | |
| pull-requests: write | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Wait for 120 seconds | |
| run: sleep 120s | |
| - name: Add PR Comment with Preview Link | |
| uses: thollander/actions-comment-pull-request@v2 | |
| with: | |
| message: 'Preview website is available <a href="https://architecture.learning.sap.com/@${{ env.PR_FOLDER }}" target="_blank" rel="noopener noreferrer">here</a>.' | |
| cleanup: | |
| name: Cleanup Merged PR | |
| runs-on: ubuntu-latest | |
| if: (github.event_name == 'pull_request_target' || github.event.pull_request.base.repo.fork) && (github.event.pull_request.merged == true || github.event.pull_request.state == 'closed') | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{github.event.pull_request.head.sha}} | |
| token: ${{ secrets.PAASAPCOM_PAT }} | |
| - name: Set up Git | |
| run: | | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "paasapcom" | |
| - name: Switch to GitHub Pages Branch | |
| run: | | |
| gh_pages_branch=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.source.branch') | |
| git fetch origin $gh_pages_branch | |
| git checkout $gh_pages_branch | |
| echo "gh_pages_branch=$gh_pages_branch" >> "$GITHUB_ENV" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Delete Folder of Merged PR | |
| run: | | |
| rm -rf @$PR_FOLDER | |
| - name: Commit and Push Changes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAASAPCOM_PAT }} | |
| run: | | |
| git add -A | |
| git commit -m "cleanup: removed folder @$PR_FOLDER after merge" || echo "No changes to commit" | |
| git push origin ${{ env.gh_pages_branch }} |