release.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. on:
  2. push:
  3. tags:
  4. - 'v[0-9]+.[0-9]+.[0-9]*'
  5. name: Create release and upload binaries
  6. jobs:
  7. build-linux:
  8. name: Build Linux/BSD All
  9. runs-on: ubuntu-latest
  10. steps:
  11. - uses: actions/checkout@v7
  12. - uses: actions/setup-go@v7
  13. with:
  14. go-version: '1.26'
  15. check-latest: true
  16. - name: Build
  17. run: |
  18. make BUILD_NUMBER="${GITHUB_REF#refs/tags/v}" release-linux release-freebsd release-openbsd release-netbsd
  19. mkdir release
  20. mv build/*.tar.gz release
  21. - name: Upload artifacts
  22. uses: actions/upload-artifact@v7
  23. with:
  24. name: linux-latest
  25. path: release
  26. build-windows:
  27. name: Build Windows
  28. runs-on: windows-latest
  29. permissions:
  30. id-token: write
  31. contents: read
  32. steps:
  33. - uses: actions/checkout@v7
  34. - uses: actions/setup-go@v7
  35. with:
  36. go-version: '1.26'
  37. check-latest: true
  38. - name: Build
  39. run: |
  40. echo $Env:GITHUB_REF.Substring(11)
  41. mkdir build\windows-amd64
  42. $Env:GOARCH = "amd64"
  43. go build -trimpath -ldflags "-X main.Build=$($Env:GITHUB_REF.Substring(11))" -o build\windows-amd64\nebula.exe ./cmd/nebula-service
  44. go build -trimpath -ldflags "-X main.Build=$($Env:GITHUB_REF.Substring(11))" -o build\windows-amd64\nebula-cert.exe ./cmd/nebula-cert
  45. mkdir build\windows-arm64
  46. $Env:GOARCH = "arm64"
  47. go build -trimpath -ldflags "-X main.Build=$($Env:GITHUB_REF.Substring(11))" -o build\windows-arm64\nebula.exe ./cmd/nebula-service
  48. go build -trimpath -ldflags "-X main.Build=$($Env:GITHUB_REF.Substring(11))" -o build\windows-arm64\nebula-cert.exe ./cmd/nebula-cert
  49. mkdir build\dist\windows
  50. mv dist\windows\wintun build\dist\windows\
  51. - name: Code-sign
  52. uses: ./.github/actions/code-sign
  53. with:
  54. path: build
  55. role: ${{ secrets.DEFINED_CODE_SIGNER_ROLE }}
  56. bucket: ${{ secrets.DEFINED_CODE_SIGNER_BUCKET }}
  57. - name: Upload artifacts
  58. uses: actions/upload-artifact@v7
  59. with:
  60. name: windows-latest
  61. path: build
  62. build-darwin:
  63. name: Build Universal Darwin
  64. env:
  65. HAS_SIGNING_CREDS: ${{ secrets.APPLE_SIGNING_ROLE_ARN != '' }}
  66. runs-on: macos-latest
  67. permissions:
  68. id-token: write
  69. contents: read
  70. steps:
  71. - uses: actions/checkout@v7
  72. - uses: actions/setup-go@v7
  73. with:
  74. go-version: '1.26'
  75. check-latest: true
  76. # GitHub holds ARNs, not credentials, and ARNs outlive a rotation
  77. - name: Configure AWS credentials
  78. if: env.HAS_SIGNING_CREDS == 'true'
  79. uses: aws-actions/configure-aws-credentials@v6
  80. with:
  81. role-to-assume: ${{ secrets.APPLE_SIGNING_ROLE_ARN }}
  82. aws-region: us-east-2
  83. # parse-json-secrets unpacks into SIGNING_* and ASC_*, masked on the way in
  84. - name: Fetch signing credentials
  85. if: env.HAS_SIGNING_CREDS == 'true'
  86. uses: aws-actions/aws-secretsmanager-get-secrets@v3
  87. with:
  88. parse-json-secrets: true
  89. secret-ids: |
  90. SIGNING,${{ secrets.APPLE_SIGNING_DEVELOPER_ID_ARN }}
  91. ASC,${{ secrets.APPLE_NOTARY_KEY_ARN }}
  92. - name: Import certificates
  93. if: env.HAS_SIGNING_CREDS == 'true'
  94. uses: Apple-Actions/import-codesign-certs@v7
  95. with:
  96. p12-file-base64: ${{ env.SIGNING_P12_BASE64 }}
  97. p12-password: ${{ env.SIGNING_PASSWORD }}
  98. # The action imports but does not check the chain validates, which is how a p12
  99. # missing its intermediate reaches a failing codesign
  100. - name: Check the identity is usable
  101. if: env.HAS_SIGNING_CREDS == 'true'
  102. run: |
  103. : "${SIGNING_IDENTITY_SHA1:?empty, so the secret has no identity_sha1}"
  104. identities=$(security find-identity -v -p codesigning signing_temp.keychain)
  105. case "$identities" in
  106. *"$SIGNING_IDENTITY_SHA1"*) ;;
  107. *) printf '%s\n' "$identities" >&2; exit 1 ;;
  108. esac
  109. # notarytool wants the key as a file
  110. - name: Write the App Store Connect key
  111. if: env.HAS_SIGNING_CREDS == 'true'
  112. run: |
  113. mkdir -p ~/private_keys
  114. chmod 700 ~/private_keys
  115. key_path="$HOME/private_keys/AuthKey_${ASC_KEY_ID}.p8"
  116. (umask 077; printf '%s\n' "$ASC_PRIVATE_KEY" > "$key_path")
  117. echo "ASC_P8=$key_path" >> "$GITHUB_ENV"
  118. - name: Drop the credentials from the environment
  119. if: env.HAS_SIGNING_CREDS == 'true'
  120. run: |
  121. # The action's own inventory, so a new field in a secret is covered
  122. python3 -c '
  123. import json, os
  124. raw = os.environ.get("SECRETS_LIST_CLEAN_UP")
  125. if raw is None and os.environ.get("SIGNING_P12_BASE64"):
  126. raise SystemExit("SECRETS_LIST_CLEAN_UP is gone, fetched secrets are not being scrubbed")
  127. keep = {"SIGNING_IDENTITY_SHA1", "ASC_KEY_ID", "ASC_ISSUER_ID"}
  128. names = [n for n in json.loads(raw or "[]") if n not in keep]
  129. print("\n".join(f"{n}=" for n in dict.fromkeys(names)))
  130. ' >> "$GITHUB_ENV"
  131. - name: Build, sign, and notarize
  132. run: |
  133. rm -rf release
  134. mkdir release
  135. make BUILD_NUMBER="${GITHUB_REF#refs/tags/v}" service build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  136. make BUILD_NUMBER="${GITHUB_REF#refs/tags/v}" service build/darwin-arm64/nebula build/darwin-arm64/nebula-cert
  137. lipo -create -output ./release/nebula ./build/darwin-amd64/nebula ./build/darwin-arm64/nebula
  138. lipo -create -output ./release/nebula-cert ./build/darwin-amd64/nebula-cert ./build/darwin-arm64/nebula-cert
  139. # Unset in a fork, which has no credentials to sign with
  140. if [ -n "$SIGNING_IDENTITY_SHA1" ]; then
  141. codesign -s "$SIGNING_IDENTITY_SHA1" -f -v --timestamp --options=runtime -i "net.defined.nebula" ./release/nebula
  142. codesign -s "$SIGNING_IDENTITY_SHA1" -f -v --timestamp --options=runtime -i "net.defined.nebula-cert" ./release/nebula-cert
  143. fi
  144. zip -j release/nebula-darwin.zip release/nebula-cert release/nebula
  145. if [ -n "$ASC_P8" ]; then
  146. xcrun notarytool submit ./release/nebula-darwin.zip --key "$ASC_P8" --key-id "$ASC_KEY_ID" --issuer "$ASC_ISSUER_ID" --wait
  147. fi
  148. - name: Drop the signing key
  149. if: always() && env.HAS_SIGNING_CREDS == 'true'
  150. run: |
  151. # Locked, not deleted: import-codesign-certs deletes it in its own post
  152. # step and fails the job if it is already gone. Locked is unusable.
  153. security lock-keychain signing_temp.keychain || true
  154. rm -f "$ASC_P8"
  155. # Nothing later in this job needs AWS
  156. python3 -c '
  157. import json, os
  158. names = json.loads(os.environ.get("SECRETS_LIST_CLEAN_UP") or "[]")
  159. names += ["ASC_P8", "SIGNING_IDENTITY_SHA1", "ASC_KEY_ID", "ASC_ISSUER_ID",
  160. "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
  161. print("\n".join(f"{n}=" for n in dict.fromkeys(names)))
  162. ' >> "$GITHUB_ENV"
  163. - name: Upload artifacts
  164. uses: actions/upload-artifact@v7
  165. with:
  166. name: darwin-latest
  167. path: ./release/*
  168. build-docker:
  169. name: Create and Upload Docker Images
  170. # Technically we only need build-linux to succeed, but if any platforms fail we'll
  171. # want to investigate and restart the build
  172. needs: [build-linux, build-darwin, build-windows]
  173. runs-on: ubuntu-latest
  174. env:
  175. HAS_DOCKER_CREDS: ${{ vars.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
  176. # XXX It's not possible to write a conditional here, so instead we do it on every step
  177. #if: ${{ env.HAS_DOCKER_CREDS == 'true' }}
  178. steps:
  179. # Be sure to checkout the code before downloading artifacts, or they will
  180. # be overwritten
  181. - name: Checkout code
  182. if: ${{ env.HAS_DOCKER_CREDS == 'true' }}
  183. uses: actions/checkout@v7
  184. - name: Download artifacts
  185. if: ${{ env.HAS_DOCKER_CREDS == 'true' }}
  186. uses: actions/download-artifact@v8
  187. with:
  188. name: linux-latest
  189. path: artifacts
  190. - name: Login to Docker Hub
  191. if: ${{ env.HAS_DOCKER_CREDS == 'true' }}
  192. uses: docker/login-action@v4
  193. with:
  194. username: ${{ vars.DOCKERHUB_USERNAME }}
  195. password: ${{ secrets.DOCKERHUB_TOKEN }}
  196. - name: Set up Docker Buildx
  197. if: ${{ env.HAS_DOCKER_CREDS == 'true' }}
  198. uses: docker/setup-buildx-action@v4
  199. - name: Build and push images
  200. if: ${{ env.HAS_DOCKER_CREDS == 'true' }}
  201. env:
  202. DOCKER_IMAGE_REPO: ${{ vars.DOCKER_IMAGE_REPO || 'nebulaoss/nebula' }}
  203. DOCKER_IMAGE_TAG: ${{ vars.DOCKER_IMAGE_TAG || 'latest' }}
  204. run: |
  205. mkdir -p build/linux-{amd64,arm64}
  206. tar -zxvf artifacts/nebula-linux-amd64.tar.gz -C build/linux-amd64/
  207. tar -zxvf artifacts/nebula-linux-arm64.tar.gz -C build/linux-arm64/
  208. docker buildx build . --push -f docker/Dockerfile --platform linux/amd64,linux/arm64 \
  209. --build-arg VERSION="${GITHUB_REF#refs/tags/v}" \
  210. --build-arg REVISION="${GITHUB_SHA}" \
  211. --tag "${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG}" --tag "${DOCKER_IMAGE_REPO}:${GITHUB_REF#refs/tags/v}"
  212. release:
  213. name: Create and Upload Release
  214. needs: [build-linux, build-darwin, build-windows]
  215. runs-on: ubuntu-latest
  216. steps:
  217. - uses: actions/checkout@v7
  218. - name: Download artifacts
  219. uses: actions/download-artifact@v8
  220. with:
  221. path: artifacts
  222. - name: Zip Windows
  223. run: |
  224. cd artifacts/windows-latest
  225. cp windows-amd64/* .
  226. zip -r nebula-windows-amd64.zip nebula.exe nebula-cert.exe dist
  227. cp windows-arm64/* .
  228. zip -r nebula-windows-arm64.zip nebula.exe nebula-cert.exe dist
  229. - name: Create sha256sum
  230. run: |
  231. cd artifacts
  232. for dir in linux-latest darwin-latest windows-latest
  233. do
  234. (
  235. cd $dir
  236. if [ "$dir" = windows-latest ]
  237. then
  238. sha256sum <windows-amd64/nebula.exe | sed 's=-$=nebula-windows-amd64.zip/nebula.exe='
  239. sha256sum <windows-amd64/nebula-cert.exe | sed 's=-$=nebula-windows-amd64.zip/nebula-cert.exe='
  240. sha256sum <windows-arm64/nebula.exe | sed 's=-$=nebula-windows-arm64.zip/nebula.exe='
  241. sha256sum <windows-arm64/nebula-cert.exe | sed 's=-$=nebula-windows-arm64.zip/nebula-cert.exe='
  242. sha256sum nebula-windows-amd64.zip
  243. sha256sum nebula-windows-arm64.zip
  244. elif [ "$dir" = darwin-latest ]
  245. then
  246. sha256sum <nebula-darwin.zip | sed 's=-$=nebula-darwin.zip='
  247. sha256sum <nebula | sed 's=-$=nebula-darwin.zip/nebula='
  248. sha256sum <nebula-cert | sed 's=-$=nebula-darwin.zip/nebula-cert='
  249. else
  250. for v in *.tar.gz
  251. do
  252. sha256sum $v
  253. tar zxf $v --to-command='sh -c "sha256sum | sed s=-$='$v'/$TAR_FILENAME="'
  254. done
  255. fi
  256. )
  257. done | sort -k 2 >SHASUM256.txt
  258. - name: Create Release
  259. id: create_release
  260. env:
  261. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  262. GITHUB_REF_NAME: ${{ github.ref_name }}
  263. run: |
  264. cd artifacts
  265. gh release create \
  266. --verify-tag \
  267. --title "Release ${GITHUB_REF_NAME}" \
  268. "${GITHUB_REF_NAME}" \
  269. SHASUM256.txt *-latest/*.zip *-latest/*.tar.gz