From 67a58327d34a001ce2001c7e20690dac00ce7c87 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Fri, 15 Nov 2024 11:00:21 -0700 Subject: [PATCH] Add comment with links to deployed examples --- .github/workflows/deploy_examples.yml | 60 ++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_examples.yml b/.github/workflows/deploy_examples.yml index 7ced0b72ab..4314829edf 100644 --- a/.github/workflows/deploy_examples.yml +++ b/.github/workflows/deploy_examples.yml @@ -50,8 +50,64 @@ jobs: - name: Deploy Linearlite working-directory: examples/linearlite - run: pnpm sst deploy --stage ${{ env.DEPLOY_ENV }} + run: | + pnpm sst deploy --stage ${{ env.DEPLOY_ENV }} + if [ -f ".sst/outputs.json" ]; then + linearlite=$(jq -r '.website' .sst/outputs.json) + echo "linearlite=$linearlite" >> $GITHUB_ENV + else + echo "sst outputs file not found. Exiting." + exit 1 + fi + - name: Deploy NextJs example working-directory: examples/nextjs-example - run: pnpm sst deploy --stage ${{ env.DEPLOY_ENV }} + run: | + pnpm sst deploy --stage ${{ env.DEPLOY_ENV }} + if [ -f ".sst/outputs.json" ]; then + nextjs=$(jq -r '.website' .sst/outputs.json) + echo "nextjs=$nextjs" >> $GITHUB_ENV + else + echo "sst outputs file not found. Exiting." + exit 1 + fi + + - name: Add comment to PR + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const linearlite = process.env.linearlite; + const nextjs = process.env.nextjs; + const commentBody = `## Examples + - linearlite: ${linearlite} + - nextjs: ${nextjs} + `; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + + const existingComment = comments.find(comment => comment.user.login ==='github-actions[bot]' && comment.body.startsWith("## Examples")); + + if (existingComment) { + // Update the existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body: commentBody, + }); + } else { + // Create a new comment if none exists + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody, + }); + } +