-
Notifications
You must be signed in to change notification settings - Fork 12
126 lines (119 loc) · 4.07 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
name: deploy
on: # yamllint disable-line rule:truthy
push:
branches: ["main"]
pull_request:
branches: ["main"]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
environment: ["staging", "firefoxci"]
env:
TASKCLUSTER_ROOT_URL: ${{vars.TASKCLUSTER_ROOT_URL}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: pip
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Set root url
run: |
if [ "${{ matrix.environment }}" == "staging" ]; then
echo "TASKCLUSTER_ROOT_URL=https://stage.taskcluster.nonprod.cloudops.mozgcp.net" >> $GITHUB_ENV;
elif [ "${{ matrix.environment }}" == "firefoxci" ]; then
echo "TASKCLUSTER_ROOT_URL=https://firefox-ci-tc.services.mozilla.com" >> $GITHUB_ENV;
fi
- name: Run checks
run: tc-admin check --environment ${{matrix.environment}}
apply:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: check
environment: apply-${{matrix.environment}}
continue-on-error: true
strategy:
matrix:
environment: ["staging", "firefoxci"]
env:
TASKCLUSTER_ROOT_URL: ${{vars.TASKCLUSTER_ROOT_URL}}
TASKCLUSTER_CLIENT_ID: ${{vars.TASKCLUSTER_CLIENT_ID}}
TASKCLUSTER_ACCESS_TOKEN: ${{secrets.TASKCLUSTER_ACCESS_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: pip
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: Deploy environment
id: apply_config
run: tc-admin apply --environment ${{matrix.environment}}
notify:
if: github.event_name == 'push' && always()
runs-on: ubuntu-latest
needs: [check, apply]
steps:
- name: Notify Slack
if: always()
run: |
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
SLACK_MESSAGE="*Deploy ${{ github.repository }}* (<${WORKFLOW_URL}|view workflow>)"
if [ "${{ needs.check.result }}" == "success" ]; then
CHECK_EMOJI=":white_check_mark:"
CHECK_VERB="succeeded"
else
CHECK_EMOJI=":x:"
CHECK_VERB="failed"
fi
if [ "${{ needs.apply.result }}" == "success" ]; then
APPLY_EMOJI=":white_check_mark:"
APPLY_VERB="succeeded"
else
APPLY_EMOJI=":x:"
APPLY_VERB="failed"
fi
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
SLACK_MESSAGE=$(cat <<-EOF
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Deploy of <https://github.com/${{ github.repository }}|${{ github.repository }}> from <https://github.com/${{ github.repository }}/commit/${{ github.sha }}|${SHORT_SHA}> is resolved"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${CHECK_EMOJI} check ${CHECK_VERB}\n${APPLY_EMOJI} apply ${APPLY_VERB}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Workflow>"
}
}
]
}
EOF
)
curl -X POST -H 'Content-type: application/json' --data "${SLACK_MESSAGE}" ${{ secrets.SLACK_WEBHOOK_URL }}