chore: update data #155
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: S3 Preview Bucket - Deploy | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| BUCKET_NAME: ds-preview-contributor-network-${{ github.event.number }} | |
| AWS_ROLE_ARN: arn:aws:iam::552819999234:role/contributor-network-gh-actions | |
| AWS_REGION: us-west-2 | |
| DIST_DIRECTORY: dist | |
| permissions: | |
| id-token: write | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6 | |
| with: | |
| node-version-file: ".nvmrc" | |
| - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 | |
| - name: Install | |
| run: npm ci | |
| - name: Generate data | |
| run: uv run contributor-network build | |
| - name: Build frontend | |
| run: npm run build | |
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| path: ${{ env.DIST_DIRECTORY }} | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3 | |
| with: | |
| role-to-assume: ${{ env.AWS_ROLE_ARN }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| path: ${{ env.DIST_DIRECTORY }} | |
| - name: Check if bucket exists | |
| id: check_bucket | |
| run: | | |
| if aws s3 ls "s3://${{ env.BUCKET_NAME }}" 2>&1 | grep -q 'NoSuchBucket'; then | |
| echo "Bucket does not exist." | |
| echo "::set-output name=exists::false" | |
| else | |
| echo "Bucket exists." | |
| echo "::set-output name=exists::true" | |
| fi | |
| - name: Create S3 bucket | |
| if: steps.check_bucket.outputs.exists == 'false' | |
| run: | | |
| aws s3 mb s3://${{ env.BUCKET_NAME }} | |
| - name: Enable static website hosting | |
| if: steps.check_bucket.outputs.exists == 'false' | |
| run: | | |
| aws s3 website \ | |
| s3://${{ env.BUCKET_NAME }} \ | |
| --index-document index.html \ | |
| --error-document index.html | |
| - name: Sync files | |
| run: | | |
| aws s3 sync \ | |
| ./${{env.DIST_DIRECTORY}} s3://${{ env.BUCKET_NAME }} \ | |
| --delete \ | |
| --quiet | |
| - name: Make bucket public access | |
| if: steps.check_bucket.outputs.exists == 'false' | |
| run: | | |
| aws s3api delete-public-access-block --bucket ${{ env.BUCKET_NAME }} | |
| - name: Add bucket policy for public access | |
| if: steps.check_bucket.outputs.exists == 'false' | |
| run: | | |
| echo '{ | |
| "Version": "2012-10-17", | |
| "Statement": [{ | |
| "Sid": "PublicReadGetObject", | |
| "Effect": "Allow", | |
| "Principal": "*", | |
| "Action": "s3:GetObject", | |
| "Resource": "arn:aws:s3:::${{ env.BUCKET_NAME }}/*" | |
| }] | |
| }' > bucket-policy.json | |
| aws s3api put-bucket-policy --bucket ${{ env.BUCKET_NAME }} --policy file://bucket-policy.json | |
| - name: Check for existing preview comment | |
| id: check_comment | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| }); | |
| const existingComment = comments.data.find(comment => comment.body.includes('Preview deployed to S3!')); | |
| if (existingComment) { | |
| console.log('Deployment comment already exists:', existingComment.html_url); | |
| core.setOutput('should_post_comment', 'false'); | |
| return existingComment.html_url; | |
| } else { | |
| core.setOutput('should_post_comment', 'true'); | |
| return ''; | |
| } | |
| - name: Post comment with preview URL | |
| if: steps.check_comment.outputs.should_post_comment == 'true' | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| const websiteUrl = `http://${{ env.BUCKET_NAME }}.s3-website-${{ env.AWS_REGION }}.amazonaws.com/`; | |
| const pullRequestNumber = context.payload.pull_request.number; | |
| const message = `✨ Preview deployed to S3! Visit ${websiteUrl}`; | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pullRequestNumber, | |
| body: message | |
| }); |