-
Notifications
You must be signed in to change notification settings - Fork 25
69 lines (65 loc) · 2.26 KB
/
deploy.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
64
65
66
67
68
69
name: Deploy
on:
workflow_call:
inputs:
imageTag:
description: 'An image tag to deploy'
required: false
default: ${{ github.sha }}
type: string
appName:
description: 'Name of the app being deployed'
required: false
default: ${{ github.event.repository.name }}
type: string
environment:
description: 'Environment to deploy to'
required: false
default: integration
type: string
secrets:
WEBHOOK_TOKEN:
required: true
WEBHOOK_URL:
required: true
GH_TOKEN:
required: true
jobs:
update-image-tag:
name: Update image tag
runs-on: ubuntu-latest
env:
ENVIRONMENT: ${{ inputs.environment || 'integration' }}
steps:
- name: Check deploy permissions
id: deploy-permissions
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TEAM: gov-uk-production-deploy
GITHUB_USER: ${{ github.triggering_actor }}
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
run: |
TEAM_MEMBERSHIP=$(gh api "orgs/alphagov/teams/$GITHUB_TEAM/memberships/$GITHUB_USER" -q .state || echo false)
if ! [[ "$TEAM_MEMBERSHIP" = active || "$ENVIRONMENT" = integration ]]; then
echo "::error title=Insufficient permissions to deploy::User $TRIGGERING_ACTOR needs to be a member of the GOV.UK Production Deploy team"
exit 1
fi
- name: Trigger Argo Workflows
if: steps.deploy-permissions.outcome == 'success'
env:
IMAGE_TAG: ${{ inputs.imageTag }}
REPO_NAME: ${{ inputs.appName }}
PROMOTE_DEPLOYMENT: ${{ github.event_name == 'release' }}
WEBHOOK_TOKEN: ${{ secrets.WEBHOOK_TOKEN }}
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
run: |
curl --fail-with-body --silent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${WEBHOOK_TOKEN}" \
-d "{
\"environment\": \"${ENVIRONMENT}\",
\"repoName\": \"${REPO_NAME}\",
\"imageTag\": \"${IMAGE_TAG}\",
\"promoteDeployment\": \"${PROMOTE_DEPLOYMENT}\"
}" \
"${WEBHOOK_URL}/update-image-tag"