-
Notifications
You must be signed in to change notification settings - Fork 544
89 lines (71 loc) · 3.09 KB
/
build_and_release.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
name: CDK CI
on:
workflow_dispatch:
release:
types: [released, prereleased]
jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.22.2
- uses: actions/setup-node@v1
with:
node-version: 10.x
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
- name: Upload Release and Renew Changelog
env:
UPLOAD_URL: ${{ github.event.release.upload_url }}
API_HEADER: "Accept: application/vnd.github.v3+json"
AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
RELEASE_URL: ${{ github.event.release.url }}
run: |
set -euo pipefail
set -x
sudo apt-get update
sudo apt-get install -y upx file curl
export CGO_ENABLED=0
export GIT_COMMIT=$(git rev-list -1 HEAD)
export ldflags="-s -w -extldflags \"-static\" -X github.com/cdk-team/CDK/pkg/cli.GitCommit=$GIT_COMMIT"
mkdir -p bin
echo "Building standard versions..."
GOOS=darwin GOARCH=amd64 go build -ldflags="$ldflags" -o bin/cdk_darwin_amd64 ./cmd/cdk/ || echo "Darwin build failed"
GOOS=linux GOARCH=386 go build -ldflags="$ldflags" -o bin/cdk_linux_386 ./cmd/cdk/
GOOS=linux GOARCH=amd64 go build -ldflags="$ldflags" -o bin/cdk_linux_amd64 ./cmd/cdk/
GOOS=linux GOARCH=arm go build -ldflags="$ldflags" -o bin/cdk_linux_arm ./cmd/cdk/
GOOS=linux GOARCH=arm64 go build -ldflags="$ldflags" -o bin/cdk_linux_arm64 ./cmd/cdk/
echo "Building thin versions..."
GOOS=linux GOARCH=386 go build -ldflags="$ldflags" -tags="thin" -o bin/cdk_linux_386_thin ./cmd/cdk/
GOOS=linux GOARCH=amd64 go build -ldflags="$ldflags" -tags="thin" -o bin/cdk_linux_amd64_thin ./cmd/cdk/
GOOS=linux GOARCH=arm64 go build -ldflags="$ldflags" -tags="thin" -o bin/cdk_linux_arm64_thin ./cmd/cdk/
echo "Creating UPX compressed versions..."
for file in bin/cdk_linux_{386,amd64}{,_thin}; do
if [ -f "$file" ]; then
cp "$file" "${file}_upx"
upx "${file}_upx" || echo "UPX compression failed for ${file}"
fi
done
UPLOAD_URL=$(echo -n $UPLOAD_URL | sed s/\{.*//g)
echo "Uploading files..."
for FILE in bin/*; do
if [ -f "$FILE" ]; then
echo "Uploading ${FILE}"
MIME_TYPE=$(file -b --mime-type "${FILE}")
RESPONSE=$(curl -w "%{http_code}" \
-H "${API_HEADER}" \
-H "${AUTH_HEADER}" \
-H "Content-Type: ${MIME_TYPE}" \
--data-binary "@${FILE}" \
"${UPLOAD_URL}?name=$(basename ${FILE})" \
-o /dev/null)
if [ "$RESPONSE" -ne 201 ]; then
echo "Error uploading ${FILE}, status code: ${RESPONSE}"
fi
fi
done
bash ".github/workflows/changelog.sh"