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