chore(config): add codemie-cli config and fix hook working directory #652
Workflow file for this run
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 Preview on AWS S3 | |
| on: | |
| workflow_run: | |
| workflows: ['Documentation Pipeline'] | |
| types: [completed] | |
| branches: | |
| - '**' | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR number to deploy (e.g., 81)' | |
| required: true | |
| type: number | |
| run_id: | |
| description: 'Workflow run ID with the build artifact (e.g., 21067393377 - find in PR Checks tab → Documentation Pipeline → URL)' | |
| required: true | |
| type: number | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| id-token: write | |
| actions: read | |
| jobs: | |
| deploy-preview: | |
| name: Deploy PR Preview | |
| runs-on: ubuntu-latest | |
| if: | | |
| (github.event_name == 'workflow_run' && | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request') || | |
| github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Get PR number and run ID | |
| id: pr | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | |
| with: | |
| script: | | |
| let prNumber, runId; | |
| if (context.eventName === 'workflow_dispatch') { | |
| prNumber = context.payload.inputs.pr_number; | |
| runId = context.payload.inputs.run_id; | |
| } else { | |
| prNumber = context.payload.workflow_run.pull_requests[0].number; | |
| runId = context.payload.workflow_run.id; | |
| } | |
| core.setOutput('number', prNumber); | |
| core.setOutput('run_id', runId); | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: docs-build-pr-${{ steps.pr.outputs.number }} | |
| path: build/ | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ steps.pr.outputs.run_id }} | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7 # v6.0.0 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Deploy to S3 | |
| run: | | |
| aws s3 sync ./build s3://${{ secrets.AWS_S3_BUCKET_NAME }}/pr-${{ steps.pr.outputs.number }}/ \ | |
| --delete \ | |
| --cache-control "public, max-age=3600" \ | |
| --content-type "text/html; charset=utf-8" \ | |
| --exclude "*" \ | |
| --include "*.html" | |
| aws s3 sync ./build s3://${{ secrets.AWS_S3_BUCKET_NAME }}/pr-${{ steps.pr.outputs.number }}/ \ | |
| --delete \ | |
| --cache-control "public, max-age=86400" \ | |
| --exclude "*.html" | |
| - name: Comment PR with preview URL | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const prNumber = ${{ steps.pr.outputs.number }}; | |
| const previewUrl = `http://${{ secrets.AWS_S3_BUCKET_NAME }}.s3-website.${{ secrets.AWS_REGION }}.amazonaws.com/pr-${prNumber}/`; | |
| // Check if comment already exists | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('PR Preview') | |
| ); | |
| const commentBody = `## PR Preview Ready! | |
| Your preview documentation is ready! Visit it here: | |
| **Preview URL:** ${previewUrl} | |
| --- | |
| *This preview will be automatically updated when you push new commits to this PR.* | |
| *Preview files will be deleted when the PR is closed or merged.*`; | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: commentBody | |
| }); | |
| } | |
| cleanup-preview: | |
| name: Cleanup PR Preview | |
| runs-on: ubuntu-latest | |
| if: github.event.action == 'closed' | |
| steps: | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7 # v6.0.0 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Delete preview from S3 | |
| run: | | |
| aws s3 rm s3://${{ secrets.AWS_S3_BUCKET_NAME }}/pr-${{ github.event.pull_request.number }}/ --recursive | |
| - name: Comment PR about cleanup | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const prNumber = context.payload.pull_request.number; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: '## Preview Cleaned Up\n\nThe PR preview has been removed from S3.' | |
| }); |