|
| 1 | +name: Deploy Preview Environment |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: ['examples/homepage/**', 'packages/vechain-kit/**', 'yarn.lock'] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + id-token: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + deploy: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + BASE_PATH: '/${{ github.event.pull_request.head.ref }}' |
| 19 | + NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID }} |
| 20 | + NEXT_PUBLIC_PRIVY_APP_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_APP_ID }} |
| 21 | + NEXT_PUBLIC_PRIVY_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_CLIENT_ID }} |
| 22 | + NEXT_PUBLIC_DELEGATOR_URL: ${{ secrets.NEXT_PUBLIC_DELEGATOR_URL }} |
| 23 | + NEXT_PUBLIC_NETWORK_TYPE: 'main' |
| 24 | + AWS_REGION: eu-west-1 |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Build App |
| 30 | + env: |
| 31 | + NODE_OPTIONS: '--max-old-space-size=8192' |
| 32 | + run: | |
| 33 | + yarn install:all |
| 34 | + yarn build |
| 35 | +
|
| 36 | + - name: Fix permissions |
| 37 | + run: | |
| 38 | + chmod -c -R +rX "./examples/homepage/dist" | while read line; do |
| 39 | + echo "::warning title=Invalid file permissions automatically fixed::$line" |
| 40 | + done |
| 41 | +
|
| 42 | + - name: Configure AWS credentials |
| 43 | + uses: aws-actions/configure-aws-credentials@v4 |
| 44 | + with: |
| 45 | + role-to-assume: ${{ secrets.AWS_ACC_ROLE }} |
| 46 | + aws-region: ${{ env.AWS_REGION }} |
| 47 | + |
| 48 | + - name: Process Branch Name |
| 49 | + id: process-branch-name |
| 50 | + run: | |
| 51 | + # Convert to lowercase, remove special characters, and truncate to 20 characters |
| 52 | + sanitized_branch_name=$(echo "${{ github.event.pull_request.head.ref }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g' | cut -c1-20) |
| 53 | + echo "processedBranchName=$sanitized_branch_name" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Deploy to S3 |
| 56 | + run: | |
| 57 | + aws s3 sync ./examples/homepage/dist s3://${{ secrets.AWS_PREVIEW_BUCKET_NAME }}/${{ steps.process-branch-name.outputs.processedBranchName }} --delete |
| 58 | +
|
| 59 | + - name: Cloudfront Invalidation |
| 60 | + run: | |
| 61 | + AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PREVIEW_CLOUDFRONT_DISTRIBUTION_ID }} --paths '/' '/*' |
| 62 | +
|
| 63 | + |
| 64 | + - name: Create Deployment Comment |
| 65 | + if: github.event.action == 'opened' |
| 66 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 67 | + with: |
| 68 | + issue-number: ${{ github.event.pull_request.number }} |
| 69 | + body: | |
| 70 | + # 🚀 Preview environment deployed! |
| 71 | + Preview URL: https://preview.vechainkit.vechain.org/${{ steps.process-branch-name.outputs.processedBranchName }} |
| 72 | + edit-mode: replace |
0 commit comments