ongdisheng commented on issue #703:
URL: https://github.com/apache/fesod/issues/703#issuecomment-3585394555

   Hi @Delei, Thank you for the suggestion! Just to clarify and make sure if I 
understand correctly: are you suggesting we combine `deploy-docs.yml` and the 
PR preview workflows into fewer files since they share similar build steps? I'm 
thinking of creating two consolidated workflows: 
   1. `ci-docs.yml`: Combined build and production deployment
   
   <details>
     <summary>Click to expand</summary>
   
   ```yaml
   name: Documentation CI
   
   on:
     push:
       branches: [main]
       paths: ['website/**']
     pull_request:
       paths: ['website/**']
   
   jobs:
     build:
       runs-on: ubuntu-latest
       steps:
         - uses: actions/checkout@v4
         - uses: pnpm/action-setup@v4
           with:
             version: 8
             run_install: false
         - uses: actions/setup-node@v4
           with:
             node-version: "20"
         - name: Corepack
           working-directory: website
           run: npm i -g --force corepack && corepack enable
         - name: Install Dependencies
           working-directory: website
           run: pnpm install
         - name: Build
           working-directory: website
           run: pnpm build
         
         # For PRs: upload artifact
         - name: Upload artifact
           if: github.event_name == 'pull_request'
           uses: actions/upload-artifact@v4
           with:
             name: website
             path: website/build
             retention-days: 7
         
         # For main branch: deploy to GitHub Pages
         - name: Copy asf file
           if: github.event_name == 'push' && github.repository == 
'apache/fesod'
           run: cp .asf.yaml ./website/build/.asf.yaml
         
         - name: Deploy to GitHub Pages
           if: github.event_name == 'push' && github.repository == 
'apache/fesod'
           uses: peaceiris/actions-gh-pages@v4
           with:
             github_token: ${{ secrets.GITHUB_TOKEN }}
             publish_dir: website/build
             publish_branch: gh-pages
             force_orphan: true
   ```
   </details>
   
   2. `ci-docs-netlify.yml`: Secure Netlify preview deployment
   
   <details>
     <summary>Click to expand</summary>
   
   ```yml
   name: Deploy Netlify Preview
   
   on:
     workflow_run:
       workflows: ["Documentation CI"]
       types: [completed]
   
   jobs:
     preview:
       runs-on: ubuntu-latest
       permissions:
         pull-requests: write
       if: github.event.workflow_run.event == 'pull_request' && 
github.event.workflow_run.conclusion == 'success'
       steps:
         - name: Checkout
           uses: actions/checkout@v4
   
         - name: Download artifact
           uses: actions/github-script@v7
           with:
             script: |
               const artifacts = await 
github.rest.actions.listWorkflowRunArtifacts({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  run_id: ${{ github.event.workflow_run.id }},
               });
               const websiteArtifact = 
artifacts.data.artifacts.filter((artifact) => {
                 return artifact.name == 'website'
               })[0];
               var download = await github.rest.actions.downloadArtifact({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  artifact_id: websiteArtifact.id,
                  archive_format: 'zip',
               });
               const fs = require('fs');
               fs.writeFileSync('${{github.workspace}}/website.zip', 
Buffer.from(download.data));
   
         - name: Unzip artifact
           run: unzip -q website.zip -d website/build
   
         - name: Deploy preview to Netlify
           id: netlify
           uses: nwtgck/actions-netlify@4cbaf4c08f1a7bfa537d6113472ef4424e4eb654
           with:
             publish-dir: './website/build'
             production-deploy: false
             github-token: ${{ secrets.GITHUB_TOKEN }}
             deploy-message: "Deploy preview for PR #${{ 
github.event.workflow_run.pull_requests[0].number }}"
             enable-pull-request-comment: false
             enable-commit-comment: false
             enable-commit-status: false
             enable-github-deployment: false
             alias: deploy-preview-${{ 
github.event.workflow_run.pull_requests[0].number }}
           env:
             NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
             NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
           timeout-minutes: 10
   
         - name: Comment on PR
           uses: 
actions-cool/maintain-one-comment@4b2dbf086015f892dcb5e8c1106f5fccd6c1476b
           with:
             token: ${{ secrets.GITHUB_TOKEN }}
             number: ${{ github.event.workflow_run.pull_requests[0].number }}
             body: |
               🚀 Preview is ready at: ${{ steps.netlify.outputs.deploy-url }}
               <!-- Netlify Preview Comment -->
             body-include: '<!-- Netlify Preview Comment -->'
   ```
   </details>
   
   ## Logic flow:
   
   - For PRs: `ci-docs.yml` builds and uploads artifact -> 
`ci-docs-netlify.yml` downloads and deploys to Netlify for secure fork PRs
   - For main branch push: `ci-docs.yml` builds and deploys directly to GitHub 
Pages
   
   Just wondering if is this what you had in mind? 😊


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to