diff --git a/.github/workflows/review_app_prompt.yml b/.github/workflows/review_app_prompt.yml new file mode 100644 index 000000000..9c795cfa9 --- /dev/null +++ b/.github/workflows/review_app_prompt.yml @@ -0,0 +1,24 @@ +name: Review app deploy prompt + +on: + pull_request: + types: [opened] + +jobs: + prompt: + name: Add review app deploy instructions + runs-on: ubuntu-latest + permissions: + pull-requests: write + + steps: + - name: Comment with deploy instructions + uses: actions/github-script@v7 + with: + script: | + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: 'To deploy a review app for this PR, comment `/deploy-review`.', + }); diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml index 8bb553c37..801e4f9f5 100644 --- a/.github/workflows/review_pipeline.yml +++ b/.github/workflows/review_pipeline.yml @@ -1,46 +1,64 @@ name: Review app pipeline -concurrency: - group: review-${{ inputs.pull_request_id }} - on: - workflow_dispatch: - inputs: - pull_request_id: - required: true - type: string - description: "The pull request ID to deploy a review app for." + issue_comment: + types: [created] defaults: run: shell: bash jobs: + setup: + name: Resolve PR details + if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/deploy-review') + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + pr_number: ${{ steps.resolve.outputs.pr_number }} + ref: ${{ steps.resolve.outputs.ref }} + steps: + - name: Resolve PR number and ref + id: resolve + uses: actions/github-script@v7 + with: + script: | + const prNumber = context.issue.number; + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + }); + core.setOutput('pr_number', prNumber.toString()); + core.setOutput('ref', pr.head.ref); + infra: name: Deploy review app infrastructure + needs: [setup] uses: communitiesuk/submit-social-housing-lettings-and-sales-data-infrastructure/.github/workflows/create_review_app_infra.yml@main with: - key: ${{ inputs.pull_request_id }} + key: ${{ needs.setup.outputs.pr_number }} app_repo_role: arn:aws:iam::815624722760:role/core-application-repo permissions: id-token: write code: name: Deploy review app code - needs: [infra] + needs: [setup, infra] uses: ./.github/workflows/aws_deploy.yml with: aws_account_id: 837698168072 aws_role_prefix: core-dev - aws_task_prefix: core-review-${{ inputs.pull_request_id }} - concurrency_tag: ${{ inputs.pull_request_id }} + aws_task_prefix: core-review-${{ needs.setup.outputs.pr_number }} + concurrency_tag: ${{ needs.setup.outputs.pr_number }} environment: review permissions: id-token: write comment: name: Add link to PR - needs: [code] + needs: [setup, code] runs-on: ubuntu-latest permissions: pull-requests: write @@ -50,19 +68,19 @@ jobs: uses: actions/github-script@v7 with: script: | - const pullRequestId = ${{ inputs.pull_request_id }}; - const body = `Created review app at https://review.submit-social-housing-data.communities.gov.uk/${pullRequestId}. Note that the review app will be automatically deprovisioned after 30 days and will need the review app pipeline running again.`; + const prNumber = ${{ needs.setup.outputs.pr_number }}; + const body = `Created review app at https://review.submit-social-housing-data.communities.gov.uk/${prNumber}. Note that the review app will be automatically deprovisioned after 30 days and will need the review app pipeline running again.`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: pullRequestId, + issue_number: prNumber, }); const duplicate = comments.find(c => c.body.startsWith('Created review app at')); if (!duplicate) { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: pullRequestId, + issue_number: prNumber, body: body, }); }