-
Notifications
You must be signed in to change notification settings - Fork 4
54 lines (51 loc) · 2.07 KB
/
web-pr.yml
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
name: Web App - PR Preview
on:
pull_request:
branches:
- main
paths:
- "web-app/**"
- "functions/**"
- ".github/workflows/web-*.yml"
jobs:
deploy-web-app:
name: Deploy Web App
uses: ./.github/workflows/web-app-deployer.yml
with:
FIREBASE_PROJECT: dev
PREVIEW_DEPLOYMENT: true
PREVIEW_HOST_NAME: "pr-${{ github.event.number }}"
secrets: inherit
update-pr-comment:
name: Update PR comments
runs-on: ubuntu-latest
needs: [ deploy-web-app ]
env:
PR_ID: ${{ github.event.number }}
steps:
- name: Check for Existing Comment
id: check-comment
run: |
HOSTING_URL=$(echo "$HOSTING_URL_64" | base64 -d)
COMMENT="Preview Firebase Hosting URL: $HOSTING_URL"
echo "PR comment: $COMMENT"
COMMENTS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/issues/${{ env.PR_ID }}/comments")
JQ_CHECK=`echo "$COMMENTS" | jq -r ".[] | select(.body == \"$COMMENT\")"`
if [ -z "$JQ_CHECK" ]; then
echo "Comment does not exist."
echo "comment_exists=false" >> $GITHUB_OUTPUT
else
echo "Comment already exists."
echo "comment_exists=true" >> $GITHUB_OUTPUT
fi
env:
HOSTING_URL_64: ${{ needs.deploy-web-app.outputs.hosting_url }}
- name: Comment on PR with Hosting URL (PR Preview)
if: steps.check-comment.outputs.comment_exists == 'false'
run: |
HOSTING_URL=$(echo "$HOSTING_URL_64" | base64 -d)
COMMENT="Preview Firebase Hosting URL: $HOSTING_URL"
echo "$COMMENT" > comment.txt
curl -d "{\"body\":\"$(cat comment.txt)\"}" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/json" -X POST "https://api.github.com/repos/${{ github.repository }}/issues/${{ env.PR_ID }}/comments"
env:
HOSTING_URL_64: ${{ needs.deploy-web-app.outputs.hosting_url }}