Skip to content

Commit f94eaf2

Browse files
author
Cameron Meissner
committed
chore: tweaks
1 parent 417f8b8 commit f94eaf2

File tree

3 files changed

+163
-24
lines changed

3 files changed

+163
-24
lines changed

.pipelines/client/publish.yaml

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,40 @@ stages:
8080
- publish: $(Build.ArtifactStagingDirectory)/aks-secure-tls-bootstrap-client.exe
8181
artifact: windows-amd64
8282

83-
# - stage: publish
84-
# jobs:
85-
# - job: publish
86-
# displayName: Publish
87-
# steps:
88-
# - checkout: self
89-
# path: s
90-
# fetchTags: false
91-
# fetchDepth: 1
92-
93-
# - bash: |
94-
# set -euxo pipefail
95-
96-
# az login --identity --resource-id $AGENT_IDENTITY_RESOURCE_ID
97-
# az account set --subscription $STORAGE_ACCOUNT_SUBSCRIPTION
98-
99-
# pushd client/
100-
# ./hack/upload.sh
101-
# popd
102-
# env:
103-
# OS: all # build linux + windows binaries
104-
# VERSION: $(CLIENT_VERSION_STRING)
105-
# displayName: Build and Upload x86_64 Linux and Windows Binaries
83+
- stage: publish
84+
dependsOn:
85+
- build_linux_amd64
86+
- build_linux_arm64
87+
- build_windows_amd64
88+
jobs:
89+
- job: publish
90+
displayName: Publish
91+
steps:
92+
- checkout: self
93+
94+
- task: DownloadPipelineArtifact@2
95+
displayName: Download linux-amd64
96+
inputs:
97+
buildType: current
98+
artifactName: linux-amd64
99+
path: $(Build.ArtifactStagingDirectory)
100+
101+
- task: DownloadPipelineArtifact@2
102+
displayName: Download linux-arm64
103+
inputs:
104+
buildType: current
105+
artifactName: linux-arm64
106+
path: $(Build.ArtifactStagingDirectory)
107+
108+
- task: DownloadPipelineArtifact@2
109+
displayName: Download windows-amd64
110+
inputs:
111+
buildType: current
112+
artifactName: windows-amd64
113+
path: $(Build.ArtifactStagingDirectory)
114+
115+
- bash: /bin/bash .pipelines/client/scripts/github-publish.sh
116+
env:
117+
ARTIFACT_DIRECTORY: "$(Build.ArtifactStagingDirectory)"
118+
VERSION: "v${{ parameters.Version }}"
119+
displayName: Publish new GitHub release

.pipelines/client/scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ if [ ! -f "${BIN_PATH}" ]; then
2424
fi
2525

2626
# move the newly-built binary to the staging directory
27-
mv "${BIN_PATH}" "${STAGING_DIRECTORY}/aks-secure-tls-bootstrap-client${EXTENSION}"
27+
mv "${BIN_PATH}" "${STAGING_DIRECTORY}/aks-secure-tls-bootstrap-client-${ARCH}${EXTENSION}"
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
[ -z "${VERSION:-}" ] && echo "VERSION must be specified" && exit 1
5+
[ -z "${ARTIFACT_DIRECTORY:-}" ] && echo "ARTIFACT_DIRECTORY must be specified" && exit 1
6+
7+
LINUX_AMD64_PATH="${ARTIFACT_DIRECTORY}/aks-secure-tls-bootstrap-client-amd64"
8+
LINUX_ARM64_PATH="${ARTIFACT_DIRECTORY}/aks-secure-tls-bootstrap-client-arm64"
9+
WINDOWS_AMD64_PATH="${ARTIFACT_DIRECTORY}/aks-secure-tls-bootstrap-client-amd64.exe"
10+
11+
verify_artifacts() {
12+
if [ ! -f "${LINUX_AMD64_PATH}" ]; then
13+
echo "could not find linux-amd64 client binary artifact at: ${LINUX_AMD64_PATH}"
14+
exit 1
15+
fi
16+
if [ ! -f "${LINUX_ARM64_PATH}" ]; then
17+
echo "could not find linux-arm64 client binary artifact at: ${LINUX_ARM64_PATH}"
18+
exit 1
19+
fi
20+
if [ ! -f "${WINDOWS_AMD64_PATH}" ]; then
21+
echo "could not find windows-amd64 client binary artifact at: ${WINDOWS_AMD64_PATH}"
22+
exit 1
23+
fi
24+
}
25+
26+
create_linux_tarballs() {
27+
CLIENT_PATH="aks-secure-tls-bootstrap-client"
28+
29+
# create linux-amd64 tarball
30+
mv "${LINUX_AMD64_PATH}" "${CLIENT_PATH}"
31+
LINUX_AMD64_TAR="linux-amd64.tar.gz"
32+
tar -czvf "${LINUX_AMD64_TAR}" "${CLIENT_PATH}"
33+
34+
# cleanup
35+
rm -f "${CLIENT_PATH}"
36+
37+
# create linux-arm64 tarball
38+
mv "${LINUX_ARM64_PATH}" "${CLIENT_PATH}"
39+
LINUX_ARM64_TAR="linux-arm64.tar.gz"
40+
tar -czvf "${LINUX_ARM64_TAR}" "${CLIENT_PATH}"
41+
42+
# cleanup
43+
rm -f "${CLIENT_PATH}"
44+
}
45+
46+
create_windows_zip_archive() {
47+
CLIENT_PATH="aks-secure-tls-bootstrap-client.exe"
48+
49+
#create windows-amd64 zip archive
50+
mv "${WINDOWS_AMD64_PATH}" "${CLIENT_PATH}"
51+
WINDOWS_AMD64_ZIP="windows-amd64.zip"
52+
zip -r "${WINDOWS_AMD64_ZIP}" "${CLIENT_PATH}"
53+
54+
# cleanup
55+
rm -f "${CLIENT_PATH}"
56+
}
57+
58+
create_github_release() {
59+
TAG_NAME="client/v${VERSION}"
60+
echo "Creating GitHub release for tag: ${TAG_NAME}"
61+
62+
RELEASE_RESPONSE=$(curl -s -X POST \
63+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
64+
-H "Accept: application/vnd.github.v3+json" \
65+
-H "Content-Type: application/json" \
66+
"https://api.github.com/repos/Azure/aks-secure-tls-bootstrap/releases" \
67+
-d "{
68+
\"tag_name\": \"${TAG_NAME}\",
69+
\"name\": \"${TAG_NAME}\",
70+
\"body\": \"official client release - v${VERSION}\",
71+
\"draft\": false,
72+
\"prerelease\": false
73+
}")
74+
75+
# Extract release ID and upload URL
76+
RELEASE_ID=$(echo "${RELEASE_RESPONSE}" | grep -o '"id":[[:space:]]*[0-9]\+' | head -1 | grep -o '[0-9]\+')
77+
UPLOAD_URL=$(echo "${RELEASE_RESPONSE}" | grep -o '"upload_url":[[:space:]]*"[^"]\+"' | grep -o 'https://[^"]\+')
78+
UPLOAD_URL="${UPLOAD_URL%\{*}" # Remove the {?name,label} template part
79+
80+
if [ -z "${RELEASE_ID}" ] || [ -z "${UPLOAD_URL}" ]; then
81+
echo "Failed to create GitHub release. Response:"
82+
echo "${RELEASE_RESPONSE}"
83+
exit 1
84+
fi
85+
86+
echo "Created GitHub release with ID: ${RELEASE_ID}"
87+
88+
# Upload artifacts
89+
upload_asset "${UPLOAD_URL}" "${LINUX_AMD64_TAR}" "application/gzip"
90+
upload_asset "${UPLOAD_URL}" "${LINUX_ARM64_TAR}" "application/gzip"
91+
upload_asset "${UPLOAD_URL}" "${WINDOWS_AMD64_ZIP}" "application/zip"
92+
93+
echo "Successfully created GitHub release: ${RELEASE_TAG}"
94+
echo "Release URL: https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/releases/tag/${RELEASE_TAG}"
95+
}
96+
97+
upload_asset() {
98+
local upload_url="$1"
99+
local file_path="$2"
100+
local content_type="$3"
101+
local file_name=$(basename "${file_path}")
102+
103+
echo "Uploading asset: ${file_name}"
104+
105+
UPLOAD_RESPONSE=$(curl -s -X POST \
106+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
107+
-H "Accept: application/vnd.github.v3+json" \
108+
-H "Content-Type: ${content_type}" \
109+
"${upload_url}?name=${file_name}" \
110+
--data-binary "@${file_path}")
111+
112+
# Check if upload was successful
113+
if echo "${UPLOAD_RESPONSE}" | grep -q '"state":[[:space:]]*"uploaded"'; then
114+
echo "Successfully uploaded: ${file_name}"
115+
else
116+
echo "Failed to upload asset: ${file_name}. Response:"
117+
echo "${UPLOAD_RESPONSE}"
118+
exit 1
119+
fi
120+
}
121+
122+
verify_artifacts
123+
create_linux_tarballs
124+
create_windows_zip_archive
125+
# create_github_release

0 commit comments

Comments
 (0)