name: Calypso Live on: pull_request: types: ['opened'] jobs: calypso-live: name: 'Links to a calypso.live instance for your branch' runs-on: ubuntu-latest # We only offer the Calypso.live link to PRs created from the Automattic organization. if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name timeout-minutes: 10 steps: - name: Check if comment exists id: has_comment uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} result-encoding: string script: | const comments = await github.rest.issues.listComments( { issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, } ); // For debugging, if needed! console.log( comments ); const existingComment = comments.data.find( comment => comment.body.includes( "calypso-live-watermark:apr@v1" ) ); const hasComment = existingComment ? "true" : "false"; console.log( `Has existing comment: ${ hasComment }` ); return hasComment; - name: Build calypso.live link. run: | echo "LINK=https://calypso.live?image=registry.a8c.com/calypso/app:commit-${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT echo "QR_CALYPSO=https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https%3A%2F%2Fcalypso.live%3Fimage%3Dregistry.a8c.com%2Fcalypso%2Fapp%3Acommit-${{ github.event.pull_request.head.sha }}%26flags%3Doauth&choe=UTF-8" >> $GITHUB_OUTPUT echo "QR_JETPACK=https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https%3A%2F%2Fcalypso.live%3Fimage%3Dregistry.a8c.com%2Fcalypso%2Fapp%3Acommit-${{ github.event.pull_request.head.sha }}%26env%3Djetpack%26flags%3Doauth&choe=UTF-}" >> $GITHUB_OUTPUT echo "QR_A4A=https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=https%3A%2F%2Fcalypso.live%3Fimage%3Dregistry.a8c.com%2Fcalypso%2Fapp%3Acommit-${{ github.event.pull_request.head.sha }}%26env%a8c-for-agencies%26flags%3Doauth&choe=UTF-}" >> $GITHUB_OUTPUT id: build_link - name: Post comment on PR uses: actions/github-script@v6 if: steps.has_comment.outputs.result == 'false' with: # Skip adding a comment if we already have one. github-token: ${{secrets.GITHUB_TOKEN}} script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: ' Calypso Live (direct link) ${{steps.build_link.outputs.LINK}} Jetpack Cloud live (direct link) ${{steps.build_link.outputs.LINK}}&env=jetpack Automattic for Agencies live (direct link) ${{steps.build_link.outputs.LINK}}&env=a8c-for-agencies ' })