|
| 1 | +name: Deploy Test (PR Preview) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + types: [opened, synchronize, reopened] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +env: |
| 13 | + TF_VAR_env: test |
| 14 | + TF_VAR_env_vars: ${{ secrets.LIVE_ENV_VARS }} |
| 15 | + TF_VAR_zone_id: ${{ secrets.LIVE_ZONE_ID }} |
| 16 | + TF_VAR_root_domain: lhowsam.com |
| 17 | + TF_VAR_sub_domain: nowplaying.lhowsam.com |
| 18 | + TF_VAR_private_key: ${{ secrets.STAGING_PRIVATE_KEY }} |
| 19 | + TF_VAR_certificate_body: ${{ secrets.STAGING_CERTIFICATE_BODY }} |
| 20 | + TF_VAR_certificate_chain: ${{ secrets.STAGING_CERTIFICATE_CHAIN }} |
| 21 | + TF_VAR_deployed_by: ${{ github.actor }} |
| 22 | + TF_VAR_git_sha: ${{ github.sha }} |
| 23 | + TF_VAR_api_key: ${{ secrets.STAGING_API_KEY }} |
| 24 | + TF_VAR_discord_webhook_url: ${{ secrets.DISCORD_ALERTS_WEBHOOK_URL }} |
| 25 | + |
| 26 | +permissions: write-all |
| 27 | + |
| 28 | +jobs: |
| 29 | + deploy: |
| 30 | + name: Deploy to Test |
| 31 | + runs-on: ubuntu-latest |
| 32 | + timeout-minutes: 15 |
| 33 | + steps: |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + ref: ${{ github.head_ref }} |
| 39 | + |
| 40 | + - name: Ensure rebased with main |
| 41 | + run: ./scripts/ensure-rebased.sh |
| 42 | + |
| 43 | + - name: Setup Bun |
| 44 | + uses: oven-sh/setup-bun@v2 |
| 45 | + with: |
| 46 | + bun-version-file: ".bun-version" |
| 47 | + |
| 48 | + - name: Install dependencies |
| 49 | + run: bun install --frozen-lockfile |
| 50 | + |
| 51 | + - name: Get pre-release version |
| 52 | + id: version |
| 53 | + run: | |
| 54 | + BASE_VERSION=$(jq -r .version package.json) |
| 55 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 56 | + SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7) |
| 57 | + PRERELEASE_VERSION="${BASE_VERSION}-pr.${PR_NUMBER}.${SHORT_SHA}" |
| 58 | + echo "version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT |
| 59 | + echo "Pre-release version: ${PRERELEASE_VERSION}" |
| 60 | +
|
| 61 | + - name: Deploy |
| 62 | + uses: ./.github/actions/deploy |
| 63 | + with: |
| 64 | + environment: ${{ env.TF_VAR_env }} |
| 65 | + aws-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 66 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 67 | + env: |
| 68 | + VERSION: ${{ steps.version.outputs.version }} |
| 69 | + |
| 70 | + - name: Comment on PR |
| 71 | + uses: actions/github-script@v7 |
| 72 | + with: |
| 73 | + script: | |
| 74 | + const version = '${{ steps.version.outputs.version }}'; |
| 75 | + const marker = '<!-- test-deployment-comment -->'; |
| 76 | + const body = `${marker}\n## 🚀 Test Deployment\n\n- **Version**: \`${version}\`\n- **URL**: https://nowplaying-test.lhowsam.com\n- **Health**: https://nowplaying-test.lhowsam.com/api/health\n- **Version API**: https://nowplaying-test.lhowsam.com/api/version`; |
| 77 | + |
| 78 | + // Find existing comment |
| 79 | + const { data: comments } = await github.rest.issues.listComments({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + issue_number: context.issue.number, |
| 83 | + }); |
| 84 | + |
| 85 | + const existingComment = comments.find(comment => comment.body.includes(marker)); |
| 86 | + |
| 87 | + if (existingComment) { |
| 88 | + // Update existing comment |
| 89 | + await github.rest.issues.updateComment({ |
| 90 | + owner: context.repo.owner, |
| 91 | + repo: context.repo.repo, |
| 92 | + comment_id: existingComment.id, |
| 93 | + body: body |
| 94 | + }); |
| 95 | + } else { |
| 96 | + // Create new comment |
| 97 | + await github.rest.issues.createComment({ |
| 98 | + owner: context.repo.owner, |
| 99 | + repo: context.repo.repo, |
| 100 | + issue_number: context.issue.number, |
| 101 | + body: body |
| 102 | + }); |
| 103 | + } |
0 commit comments