-
Notifications
You must be signed in to change notification settings - Fork 55
188 lines (158 loc) · 7.85 KB
/
Copy pathvcf.yml
File metadata and controls
188 lines (158 loc) · 7.85 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: tdnf VCF workflow
on: [push, workflow_dispatch]
jobs:
build:
runs-on:
- self-hosted
- docker:rootless
steps:
- name: checkout code
uses: actions/checkout@v3
- name: create tarball
working-directory: ${{ github.workspace }}
run: |
VERSION=$(cat VERSION)
FULL_NAME=tdnf-${VERSION}
tar zcf ${FULL_NAME}.tar.gz --transform "s,^,${FULL_NAME}/," $(git ls-files)
cat tdnf.spec.in | sed s/@PROJECT_VERSION@/${VERSION}/g > tdnf.spec
- name: build RPMs
working-directory: ${{ github.workspace }}
run: |
PWD=$(pwd)
mkdir -p photon
docker run --privileged --rm \
-v${PWD}/photon:/usr/src/photon \
-v${PWD}:/usr/src/photon/SOURCES \
photon/installer \
create-pkg \
-v 5.0 tdnf --skip-checksum -o
- name: copy artifacts and create repo
run: |
rm -rf photon/RPMS/repodata
mkdir -p ${HOME}/artifacts/tdnf/${GITHUB_SHA::7}
cp -r photon/RPMS/ ${HOME}/artifacts/tdnf/${GITHUB_SHA::7}/
cp -r photon/SRPMS/ ${HOME}/artifacts/tdnf/${GITHUB_SHA::7}/
cd ${HOME}/artifacts/tdnf/${GITHUB_SHA::7} && createrepo .
- name: set symlink for dev
run: |
if [[ "${{ github.ref_name }}" == "dev" ]] ; then
cd ${HOME}/artifacts/tdnf/ && rm -f dev && ln -fs ${GITHUB_SHA::7} ./dev
fi
cayman_poi:
runs-on: self-hosted
steps:
- name: Checkout Cayman POI
uses: actions/checkout@master
with:
repository: vcf/cayman-poi
ref: vmware-master
path: ./cayman-poi
submodules: "true"
fetch-depth: 0
ssh-key: ${{ secrets.POI_CICD_SSH_KEY }}
ssh-strict: "false"
- name: create branch and push
run: |
cd ./cayman-poi
BRANCH_NAME="test/tdnf-submodule/${GITHUB_SHA::7}"
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME already exists locally, switching to it"
git checkout "$BRANCH_NAME"
elif git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME exists remotely, checking it out"
git checkout -b "$BRANCH_NAME" "origin/$BRANCH_NAME"
else
echo "Branch $BRANCH_NAME does not exist, creating it"
git checkout -b "$BRANCH_NAME"
fi
pushd poi/tdnf
# sometimes the sha is not available yet
git fetch
git checkout ${GITHUB_SHA::7}
popd
# Enable tdnf submodule
sed -i 's/USE_TDNF_SUBMODULE = False/USE_TDNF_SUBMODULE = True/' poi/poi_defs.py
git add poi/tdnf poi/poi_defs.py
git config --global user.email "poi-cicd@broadcom.com"
git config --global user.name "POI CI/CD"
# Only commit if there are changes
if git diff --cached --quiet; then
echo "No changes to commit, skipping commit step"
else
git commit -m "update poi/tdnf to ${GITHUB_SHA::7} for testing branch ${{ github.ref_name }}"
fi
git push origin "$BRANCH_NAME"
- name: Wait for and monitor cayman-poi workflow
env:
GITHUB_TOKEN: ${{ secrets.PAT_POI_CICD_RO }}
run: |
BRANCH_NAME="test/tdnf-submodule/${GITHUB_SHA::7}"
echo "Monitoring branch: $BRANCH_NAME"
# Function to get workflow runs for the branch
get_workflow_runs() {
curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs?branch=$BRANCH_NAME" \
| jq -r '.workflow_runs[] | select(.head_branch == "'$BRANCH_NAME'") | "\(.id) \(.status) \(.conclusion // "null") \(.created_at)"'
}
# Wait for workflow to start (up to 5 minutes)
echo "Waiting for workflow to start on branch $BRANCH_NAME..."
timeout=300
interval=30
elapsed=0
while [ $elapsed -lt $timeout ]; do
runs=$(get_workflow_runs)
if [ -n "$runs" ]; then
echo "Workflow detected:"
echo "$runs"
break
fi
echo "No workflow found yet, waiting ${interval}s..."
sleep $interval
elapsed=$((elapsed + interval))
done
if [ $elapsed -ge $timeout ]; then
echo "ERROR: No workflow was triggered within $timeout seconds"
exit 1
fi
# Get the workflow run ID (first field from the output)
run_id=$(echo "$runs" | head -1 | cut -d' ' -f1)
echo "Monitoring workflow run ID: $run_id"
# Monitor workflow status (up to 1 hour)
timeout=3600
interval=60
elapsed=0
while [ $elapsed -lt $timeout ]; do
run_info=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs/$run_id")
status=$(echo "$run_info" | jq -r '.status')
conclusion=$(echo "$run_info" | jq -r '.conclusion // "null"')
url=$(echo "$run_info" | jq -r '.html_url')
echo "Workflow status: $status, conclusion: $conclusion"
if [ "$status" = "completed" ]; then
echo "Workflow completed with conclusion: $conclusion"
echo "Workflow URL: $url"
if [ "$conclusion" = "success" ]; then
echo "✅ Cayman POI workflow succeeded!"
exit 0
elif [ "$conclusion" = "null" ]; then
echo "❌ Cayman POI workflow completed but conclusion is null"
echo "Check the workflow at: $url"
exit 1
else
echo "❌ Cayman POI workflow failed with conclusion: $conclusion"
echo "Check the workflow at: $url"
exit 1
fi
fi
sleep $interval
elapsed=$((elapsed + interval))
done
echo "ERROR: Workflow did not complete within $timeout seconds"
echo "Workflow URL: $url"
exit 1