diff --git a/.github/workflows/build-and-preview-site.yml b/.github/workflows/build-and-preview-site.yml index 7cf0708..b45d43b 100644 --- a/.github/workflows/build-and-preview-site.yml +++ b/.github/workflows/build-and-preview-site.yml @@ -1,32 +1,78 @@ name: Build and Preview Site + on: - pull_request: + pull_request_target: branches: [master] - types: [opened, synchronize, reopened] + types: [opened, synchronize, reopened, closed] + +permissions: + contents: write + pull-requests: write + +concurrency: + group: "preview-${{ github.event.pull_request.number || github.run_id }}" + cancel-in-progress: true jobs: - site-preview: - runs-on: ubuntu-latest + build-and-deploy-preview: + runs-on: ubuntu-24.04 steps: - - name: Checkout 🛎️ - uses: actions/checkout@master + - name: Checkout PR + if: github.event.action != 'closed' + uses: actions/checkout@v6 with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false - fetch-depth: 1 + fetch-depth: 0 - - name: Install and Build 🔧 + - name: Checkout for cleanup + if: github.event.action == 'closed' + uses: actions/checkout@v6 + with: + ref: gh-pages + fetch-depth: 0 + + - name: Install and Build + if: github.event.action != 'closed' run: | make setup make build - - name: Zip Site - run: bash ./script.sh + - name: Add robots.txt for previews + if: github.event.action != 'closed' + run: | + cat > site/public/robots.txt <<'EOF' + User-agent: * + Disallow: / + EOF + + - name: Deploy PR preview + if: github.event.action != 'closed' + uses: rossjrw/pr-preview-action@v1.6.3 + with: + source-dir: ./site/public + preview-branch: gh-pages + umbrella-dir: pr-preview + action: auto + comment: false + + - name: Comment PR with Preview URL + if: github.event.action != 'closed' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: pr-preview + message: | + 🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}** + + 🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/ + + _This preview is updated automatically when commits are pushed to this PR._ - - name: Upload files - uses: actions/upload-artifact@v4 + - name: Cleanup PR preview on close + if: github.event.action == 'closed' + uses: rossjrw/pr-preview-action@v1.6.3 with: - name: public-dir - path: public-dir.zip - retention-days: 1 - - name: Trigger Inner workflow - run: echo "triggering inner workflow" \ No newline at end of file + preview-branch: gh-pages + umbrella-dir: pr-preview + action: remove diff --git a/.github/workflows/preview-site.yml b/.github/workflows/preview-site.yml deleted file mode 100644 index 269826c..0000000 --- a/.github/workflows/preview-site.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Deploy Preview -on: - workflow_run: - workflows: - - Build and Preview Site - types: - - completed - -jobs: - deploy-preview: - if: > - github.repository == 'meshery-extensions/shape-builder' && - github.event.workflow_run.conclusion == 'success' - runs-on: ubuntu-24.04 - steps: - - name: Checkout code - uses: actions/checkout@master - - - name: Download Site dir - uses: actions/download-artifact@v6 - with: - name: public-dir - github-token: ${{ secrets.RELEASE_NOTES_PATN }} - repository: ${{ github.event.workflow_run.repository.full_name }} - run-id: ${{ github.event.workflow_run.id }} - - - name: Unzip Site - run: | - rm -rf docs/_site - mkdir -p docs/_site - unzip public-dir.zip -d docs/_site - rm -f public-dir.zip - - - name: Deploy to Netlify - id: netlify - uses: nwtgck/actions-netlify@v3 - with: - publish-dir: 'docs/_site' - production-deploy: false - github-token: ${{ secrets.RELEASE_NOTES_PATN }} - enable-commit-comment: false - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - - - name: Comment Deploy URL - uses: ./.github/actions/comment-preview-on-pr - with: - token: ${{ secrets.RELEASE_NOTES_PATN }} - deploy_url: "${{ steps.netlify.outputs.deploy-url }}" - -