-
Notifications
You must be signed in to change notification settings - Fork 11
63 lines (57 loc) · 2.57 KB
/
deploy-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Uses label to decide which environment to deploy to.
# e.g. "dev-blue" or "dev-green"
name: "Deploy: PR"
on:
pull_request:
types:
- synchronize
- labeled
env:
# deploy only if any PR label is "dev-green" or "dev-blue"
DO_DEPLOY: ${{ contains(github.event.pull_request.labels.*.name, 'dev-green') || contains(github.event.pull_request.labels.*.name, 'dev-blue') }}
# really hacky expression because Github Actions
# lacks real conditional statements
DEPLOY_ENV: ${{ contains(github.event.pull_request.labels.*.name, 'dev-green') && 'dev-green' || 'dev-blue' }}
concurrency:
group: ${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
pr:
# env not available for job if
if: ${{ contains(github.event.pull_request.labels.*.name, 'dev-green') || contains(github.event.pull_request.labels.*.name, 'dev-blue') }}
uses: ./.github/workflows/use-deploy-ecs.yml
with:
deployment-env: ${{ contains(github.event.pull_request.labels.*.name, 'dev-green') && 'dev-green' || 'dev-blue' }} # env not valid here either
secrets:
aws-account-id: ${{ secrets.TID_AWS_ACCOUNT_ID }}
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
docker-repo: ${{ secrets.DOCKER_REPO }}
notify:
needs: [pr]
uses: ./.github/workflows/use-notify-slack.yml
if: ${{ success() || failure() }}
secrets:
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
with:
job-status: ${{ needs.pr.result }}
success-message: |
PR#${{ github.event.pull_request.number }} (`${{ github.ref_name }}` branch) deployed to ${{ contains(github.event.pull_request.labels.*.name, 'dev-green') && 'dev-green' || 'dev-blue' }}
failure-message: |
PR#${{ github.event.pull_request.number }} failed to deploy to ${{ contains(github.event.pull_request.labels.*.name, 'dev-green') && 'dev-green' || 'dev-blue' }}
cleanup:
runs-on: ubuntu-latest
needs: [pr]
permissions:
pull-requests: write
steps:
- name: Unlabel other PRs (if needed)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ env.DO_DEPLOY }}
run: |
gh pr list --repo ${{ github.repository }} --state all --label "${{ env.DEPLOY_ENV }}" --json number --jq ".[].number"| while read -r pr_number ; do
if [[ "${pr_number}" != "${{ github.event.pull_request.number }}" ]]; then
echo "=== PR ${pr_number} : remove ${{ env.DEPLOY_ENV }} label ==="
gh pr edit "${pr_number}" --repo ${{ github.repository }} --remove-label "${{ env.DEPLOY_ENV }}"
fi
done