@@ -12,8 +12,6 @@ export GO111MODULE=on
1212
1313# build 'cloudflared-darwin-amd64.tgz'
1414mkdir -p artifacts
15- FILENAME=" $( pwd) /artifacts/cloudflared-darwin-amd64.tgz"
16- PKGNAME=" $( pwd) /artifacts/cloudflared-amd64.pkg"
1715TARGET_DIRECTORY=" .build"
1816BINARY_NAME=" cloudflared"
1917VERSION=$( git describe --tags --always --dirty=" -dev" )
@@ -28,7 +26,6 @@ export PATH="$PATH:/usr/local/bin"
2826mkdir -p ../src/github.com/cloudflare/
2927cp -r . ../src/github.com/cloudflare/cloudflared
3028cd ../src/github.com/cloudflare/cloudflared
31- GOCACHE=" $PWD /../../../../" GOPATH=" $PWD /../../../../" CGO_ENABLED=1 make cloudflared
3229
3330# Add code signing private key to the key chain
3431if [[ ! -z " $CFD_CODE_SIGN_KEY " ]]; then
@@ -138,47 +135,59 @@ else
138135 fi
139136fi
140137
141- # sign the cloudflared binary
142- if [[ ! -z " $CODE_SIGN_NAME " ]]; then
143- codesign -s " ${CODE_SIGN_NAME} " -f -v --timestamp --options runtime ${BINARY_NAME}
138+ # cleanup the build directory because the previous execution might have failed without cleaning up.
139+ rm -rf " ${TARGET_DIRECTORY} "
140+ archs=(" amd64" " arm64" )
141+ export TARGET_OS=darwin
142+ for arch in ${archs[@]} ; do
144143
145- # notarize the binary
146- # TODO: TUN-5789
147- fi
144+ FILENAME=" $( pwd) /artifacts/cloudflared-darwin-$arch .tgz"
145+ PKGNAME=" $( pwd) /artifacts/cloudflared-$arch .pkg"
146+ TARGET_ARCH=$arch GOCACHE=" $PWD /../../../../" GOPATH=" $PWD /../../../../" CGO_ENABLED=1 make cloudflared
147+
148+ # sign the cloudflared binary
149+ if [[ ! -z " $CODE_SIGN_NAME " ]]; then
150+ codesign -s " ${CODE_SIGN_NAME} " -f -v --timestamp --options runtime ${BINARY_NAME}
151+
152+ # notarize the binary
153+ # TODO: TUN-5789
154+ fi
148155
149- # creating build directory
150- rm -rf $TARGET_DIRECTORY
151- mkdir " ${TARGET_DIRECTORY} "
152- mkdir " ${TARGET_DIRECTORY} /contents"
153- cp -r " .mac_resources/scripts" " ${TARGET_DIRECTORY} /scripts"
154-
155- # copy cloudflared into the build directory
156- cp ${BINARY_NAME} " ${TARGET_DIRECTORY} /contents/${PRODUCT} "
157-
158- # compress cloudflared into a tar and gzipped file
159- tar czf " $FILENAME " " ${BINARY_NAME} "
160-
161- # build the installer package
162- if [[ ! -z " $PKG_SIGN_NAME " ]]; then
163- pkgbuild --identifier com.cloudflare.${PRODUCT} \
164- --version ${VERSION} \
165- --scripts ${TARGET_DIRECTORY} /scripts \
166- --root ${TARGET_DIRECTORY} /contents \
167- --install-location /usr/local/bin \
168- --sign " ${PKG_SIGN_NAME} " \
169- ${PKGNAME}
170-
171- # notarize the package
172- # TODO: TUN-5789
173- else
174- pkgbuild --identifier com.cloudflare.${PRODUCT} \
175- --version ${VERSION} \
176- --scripts ${TARGET_DIRECTORY} /scripts \
177- --root ${TARGET_DIRECTORY} /contents \
178- --install-location /usr/local/bin \
179- ${PKGNAME}
180- fi
156+ ARCH_TARGET_DIRECTORY=" ${TARGET_DIRECTORY} /${arch} -build"
157+ # creating build directory
158+ rm -rf $ARCH_TARGET_DIRECTORY
159+ mkdir " ${ARCH_TARGET_DIRECTORY} "
160+ mkdir " ${ARCH_TARGET_DIRECTORY} /contents"
161+ cp -r " .mac_resources/scripts" " ${ARCH_TARGET_DIRECTORY} /scripts"
181162
163+ # copy cloudflared into the build directory
164+ cp ${BINARY_NAME} " ${ARCH_TARGET_DIRECTORY} /contents/${PRODUCT} "
165+
166+ # compress cloudflared into a tar and gzipped file
167+ tar czf " $FILENAME " " ${BINARY_NAME} "
168+
169+ # build the installer package
170+ if [[ ! -z " $PKG_SIGN_NAME " ]]; then
171+ pkgbuild --identifier com.cloudflare.${PRODUCT} \
172+ --version ${VERSION} \
173+ --scripts ${ARCH_TARGET_DIRECTORY} /scripts \
174+ --root ${ARCH_TARGET_DIRECTORY} /contents \
175+ --install-location /usr/local/bin \
176+ --sign " ${PKG_SIGN_NAME} " \
177+ ${PKGNAME}
178+
179+ # notarize the package
180+ # TODO: TUN-5789
181+ else
182+ pkgbuild --identifier com.cloudflare.${PRODUCT} \
183+ --version ${VERSION} \
184+ --scripts ${ARCH_TARGET_DIRECTORY} /scripts \
185+ --root ${ARCH_TARGET_DIRECTORY} /contents \
186+ --install-location /usr/local/bin \
187+ ${PKGNAME}
188+ fi
189+ done
182190
183- # cleaning up the build directory
184- rm -rf $TARGET_DIRECTORY
191+ # cleanup build the build directory because this script is not ran within containers,
192+ # which might lead to future issues in subsequent runs.
193+ rm -rf " ${TARGET_DIRECTORY} "
0 commit comments