You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.3 KiB
94 lines
3.3 KiB
name: Review app pipeline |
|
|
|
on: |
|
issue_comment: |
|
types: [created] |
|
workflow_dispatch: |
|
inputs: |
|
pr_number: |
|
required: true |
|
type: string |
|
description: "The number of the PR for which to deploy a review app. Note: this is NOT the ticket number" |
|
|
|
permissions: {} |
|
|
|
jobs: |
|
get_pr_details: |
|
name: Get PR details |
|
if: github.event_name == 'workflow_dispatch' || (github.event.issue.pull_request && startsWith(github.event.comment.body, '/deploy-review')) |
|
runs-on: ubuntu-latest |
|
outputs: |
|
pr_number: ${{ steps.get_pr_details.outputs.pr_number }} |
|
pr_head_sha: ${{ steps.get_pr_details.outputs.pr_head_sha }} |
|
steps: |
|
- name: Get PR number and HEAD SHA |
|
id: get_pr_details |
|
uses: actions/github-script@v7 |
|
with: |
|
script: | |
|
let prNumber; |
|
if (context.eventName === 'workflow_dispatch') { |
|
prNumber = '${{ inputs.pr_number }}'; |
|
} else { |
|
prNumber = context.issue.number.toString(); |
|
} |
|
core.setOutput('pr_number', prNumber); |
|
const { data: pr } = await github.rest.pulls.get({ |
|
owner: context.repo.owner, |
|
repo: context.repo.repo, |
|
pull_number: parseInt(prNumber), |
|
}); |
|
core.setOutput('pr_head_sha', pr.head.sha); |
|
|
|
infra: |
|
name: Deploy review app infrastructure |
|
needs: [get_pr_details] |
|
uses: communitiesuk/submit-social-housing-lettings-and-sales-data-infrastructure/.github/workflows/create_review_app_infra.yml@main |
|
with: |
|
key: ${{ needs.get_pr_details.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: [get_pr_details, infra] |
|
uses: ./.github/workflows/aws_deploy.yml |
|
with: |
|
aws_account_id: 837698168072 |
|
aws_role_prefix: core-dev |
|
aws_task_prefix: core-review-${{ needs.get_pr_details.outputs.pr_number }} |
|
concurrency_tag: ${{ needs.get_pr_details.outputs.pr_number }} |
|
environment: review |
|
ref: ${{ needs.get_pr_details.outputs.pr_head_sha }} |
|
permissions: |
|
id-token: write |
|
|
|
comment: |
|
name: Add link to PR |
|
needs: [get_pr_details, code] |
|
runs-on: ubuntu-latest |
|
permissions: |
|
pull-requests: write |
|
|
|
steps: |
|
- name: Comment on PR with URL |
|
uses: actions/github-script@v7 |
|
with: |
|
script: | |
|
const prNumber = ${{ needs.get_pr_details.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: 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: prNumber, |
|
body: body, |
|
}); |
|
}
|
|
|