feat: slack notification on add feed form #352
Workflow file for this run
This file contains 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: Web App - PR Preview | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "web-app/**" | |
- "functions/**" | |
- ".github/workflows/web-*.yml" | |
jobs: | |
load-secrets: | |
name: Load Secrets and Deploy Web App | |
runs-on: ubuntu-latest | |
steps: | |
- name: 1Password - Load Secrets | |
id: op-load-secret | |
uses: 1Password/[email protected] | |
with: | |
export-env: false | |
env: | |
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | |
SLACK_WEBHOOK_URL: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/wm52iemzzm2cwfaoakwaufthuq/password" | |
outputs: # Pass the secret loaded from this job as an output | |
SLACK_WEBHOOK_URL: ${{ steps.op-load-secret.outputs.SLACK_WEBHOOK_URL }} | |
deploy-web-app: | |
name: Deploy Web App | |
needs: load-secrets | |
uses: ./.github/workflows/web-app-deployer.yml | |
with: | |
FIREBASE_PROJECT: dev | |
PREVIEW_DEPLOYMENT: true | |
FEED_SUBMIT_GOOGLE_SHEET_ID: "1iXwux9hM4p5Li1EGgwx-8hU3sMDnF15yTflqmGjiZqE" | |
SLACK_WEBHOOK_URL: ${{ needs.load-secrets.outputs.SLACK_WEBHOOK_URL }} | |
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 }} | |