forked from nexodus-io/nexodus
-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (129 loc) · 4.6 KB
/
promote.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: promote
concurrency: prod-${{ github.ref_name }}
on:
workflow_call:
workflow_dispatch:
jobs:
run-qa-dev:
# Dispatch the qa-dev workflow to validate main prior to promotion
runs-on: ubuntu-latest
env:
WAIT_INTERVAL: "60"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Capture current timestamp
run: |
current_time=$(date --utc +%Y-%m-%dT%H:%M:%S+00:00)
echo "current_time=${current_time}" >> "$GITHUB_ENV"
- name: Dispatch the qa-dev workflow
run: |
curl -X POST \
-H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{github.repository}}/actions/workflows/qa-dev.yml/dispatches" \
-d '{"ref": "main", "inputs": {"deployment_size": "small", "pr_or_branch": "main"}}'
echo "Triggered qa-dev Workflow."
- name: Wait for qa-dev workflow to complete
timeout-minutes: 30
run: |
check_status() {
runs=$(curl -s -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{github.repository}}/actions/workflows/qa-dev.yml/runs?per_page=10")
latest_run=$(echo "$runs" | jq -r --arg timestamp "$current_time" \
'.workflow_runs[] | select(.created_at >= $timestamp) | .')
status=$(echo "$latest_run" | jq -r '.status')
conclusion=$(echo "$latest_run" | jq -r '.conclusion')
echo "Workflow status: $status, conclusion: $conclusion"
if [[ "$status" == "completed" && "$conclusion" == "success" ]]; then
return 0
elif [[ "$status" == "completed" && "$conclusion" != "success" ]]; then
echo "qa-dev workflow failed. For details, see https://github.com/nexodus-io/nexodus/actions/workflows/qa-dev.yml"
exit 1
else
return 1
fi
}
while ! check_status; do
echo "Waiting for qa-dev workflow to complete..."
sleep "$WAIT_INTERVAL"
done
update-prod:
# Sync prod with the QA ref
name: Update Production Deployment
runs-on: ubuntu-20.04
needs: ["run-qa-dev"]
steps:
- name: Checkout the qa Tag
uses: actions/checkout@v4
with:
ref: "qa"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Promote to the prod Tag
shell: bash
run: |
git fetch --tags
git tag prod-previous prod --force
git tag prod --force
git push origin prod prod-previous --force
build-packages:
# Sync the agent binary in s3 /download with the prod promotion in the update-prod job
runs-on: ubuntu-latest
needs: ["run-qa-dev"]
steps:
- name: Checkout the qa Tag
uses: actions/checkout@v4
with:
ref: "qa"
- name: Setup Go
uses: ./.github/actions/setup-go-env
- name: Build nexodus packages
id: build
shell: bash
run: |
NEXODUS_BUILD_PROFILE=prod make -j dist/packages
- name: Upload nexodus zip packages
uses: actions/upload-artifact@v4
with:
name: nexodus-zip-packages
if-no-files-found: error
path: |
dist/packages/*.zip
- name: Upload nexodus tar.gz packages
uses: actions/upload-artifact@v4
with:
name: nexodus-tar-packages
if-no-files-found: error
path: |
dist/packages/*.tar.gz
upload-s3-packages:
needs: ["build-packages"]
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
environment: image-repositories
steps:
- name: Download nexodus zip packages
uses: actions/download-artifact@v4
with:
name: nexodus-zip-packages
path: dist/packages
- name: Download nexodus tar.gz packages
uses: actions/download-artifact@v4
with:
name: nexodus-tar-packages
path: dist/packages
- name: Display structure of downloaded files
run: ls -lah -R
working-directory: dist/packages
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: nexodus-ci-deploy
aws-region: us-east-1
- name: Copy binaries to S3
run: |
aws s3 sync dist/packages s3://nexodus-io/download