build-and-release.yml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. ---
  2. name: "Build & Release pipeline"
  3. on:
  4. pull_request:
  5. paths:
  6. - '.github/workflows/build-and-release.yml'
  7. - '.goreleaser.yml'
  8. - 'Dockerfile.multiarches'
  9. - 'Dockerfile.singlearch'
  10. - 'Makefile'
  11. - 'frontend/**'
  12. - 'integration-tests/**'
  13. - 'proto/**'
  14. - 'service/**'
  15. - 'var/windows/**'
  16. workflow_dispatch:
  17. push:
  18. tags:
  19. - '*'
  20. branches:
  21. - main
  22. - next
  23. - beta
  24. paths:
  25. - '.github/workflows/build-and-release.yml'
  26. - '.goreleaser.yml'
  27. - 'Dockerfile.multiarches'
  28. - 'Dockerfile.singlearch'
  29. - 'Makefile'
  30. - 'frontend/**'
  31. - 'integration-tests/**'
  32. - 'proto/**'
  33. - 'service/**'
  34. - 'var/windows/**'
  35. jobs:
  36. build:
  37. runs-on: ubuntu-latest
  38. outputs:
  39. new_release_published: ${{ steps.release.outputs.new_release_published }}
  40. new_release_git_tag: ${{ steps.release.outputs.new_release_git_tag }}
  41. windows_zip_artifact_id: ${{ steps.upload-windows-zip.outputs.artifact-id }}
  42. windows_msi_artifact_id: ${{ steps.upload-windows-msi.outputs.artifact-id }}
  43. steps:
  44. - name: Checkout
  45. uses: actions/checkout@v6
  46. with:
  47. fetch-depth: 0
  48. - name: Set up QEMU
  49. id: qemu
  50. uses: docker/setup-qemu-action@v4
  51. with:
  52. image: tonistiigi/binfmt:latest
  53. platforms: arm64,arm
  54. - name: Setup node (npm cache)
  55. if: github.event_name != 'pull_request'
  56. uses: actions/setup-node@v6.4.0
  57. with:
  58. node-version: '22'
  59. cache: 'npm'
  60. cache-dependency-path: frontend/package-lock.json
  61. - name: Setup node
  62. if: github.event_name == 'pull_request'
  63. uses: actions/setup-node@v6.4.0
  64. with:
  65. node-version: '22'
  66. - name: Setup Go
  67. uses: actions/setup-go@v6
  68. with:
  69. go-version-file: 'service/go.mod'
  70. cache: true
  71. cache-dependency-path: 'service/go.mod'
  72. - name: Print go version
  73. run: go version
  74. - name: Login to Docker Hub
  75. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  76. uses: docker/login-action@v4
  77. with:
  78. username: ${{ secrets.DOCKERHUB_USERNAME }}
  79. password: ${{ secrets.DOCKERHUB_KEY }}
  80. - name: Login to ghcr
  81. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  82. uses: docker/login-action@v4
  83. with:
  84. registry: ghcr.io
  85. username: ${{ github.actor }}
  86. password: ${{ secrets.CONTAINER_TOKEN }}
  87. - name: get date
  88. run: |
  89. echo "DATE=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"
  90. - name: make webui
  91. run: make -w webui-dist
  92. - name: unit tests
  93. run: make -w service-unittests
  94. - name: frontend unit tests
  95. run: make -w frontend-unittests
  96. - name: build service
  97. run: make -w service
  98. - name: integration tests
  99. run: cd integration-tests && make -w
  100. - name: Archive integration tests
  101. uses: actions/upload-artifact@v7
  102. if: always()
  103. with:
  104. name: "OliveTin-integration-tests-${{ env.DATE }}-${{ github.sha }}"
  105. path: |
  106. integration-tests
  107. !integration-tests/node_modules
  108. - name: Install wixl and msitools
  109. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  110. run: sudo apt-get update && sudo apt-get install -y wixl msitools
  111. - name: Install goreleaser
  112. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  113. uses: goreleaser/goreleaser-action@v7
  114. with:
  115. install-only: true
  116. - name: Set up Docker Buildx
  117. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  118. uses: docker/setup-buildx-action@v4
  119. - name: Verify macOS signing certificate chain
  120. if: github.ref_type != 'tag' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
  121. env:
  122. MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
  123. MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
  124. run: ./var/macos/verify-macos-sign-p12.sh
  125. - name: release
  126. id: release
  127. if: github.ref_type != 'tag' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
  128. uses: cycjimmy/semantic-release-action@v5
  129. with:
  130. extra_plugins: |
  131. @semantic-release/commit-analyzer
  132. @semantic-release/exec
  133. @semantic-release/git
  134. env:
  135. GITHUB_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  136. GH_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  137. MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
  138. MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
  139. MACOS_NOTARY_KEY: ${{ secrets.MACOS_NOTARY_KEY }}
  140. MACOS_NOTARY_KEY_ID: ${{ secrets.MACOS_NOTARY_KEY_ID }}
  141. MACOS_NOTARY_ISSUER_ID: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}
  142. - name: Upload unsigned Windows zip for SignPath
  143. id: upload-windows-zip
  144. if: steps.release.outputs.new_release_published == 'true'
  145. uses: actions/upload-artifact@v7
  146. with:
  147. # Upload as-is so SignPath receives OliveTin-windows-amd64.zip, not a wrapper zip.
  148. # With archive: false, the artifact name is the filename (`name` is ignored).
  149. path: dist/OliveTin-windows-amd64.zip
  150. archive: false
  151. if-no-files-found: error
  152. - name: Upload unsigned Windows MSI for SignPath
  153. id: upload-windows-msi
  154. if: steps.release.outputs.new_release_published == 'true'
  155. uses: actions/upload-artifact@v7
  156. with:
  157. path: dist/OliveTin-windows-amd64.msi
  158. archive: false
  159. if-no-files-found: error
  160. - name: Archive binaries
  161. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  162. uses: actions/upload-artifact@v7
  163. with:
  164. name: "OliveTin-snapshot-${{ env.DATE }}-${{ github.sha }}"
  165. path: dist/OliveTin*.*
  166. sign-windows:
  167. name: Sign Windows artifacts (SignPath)
  168. needs: build
  169. if: needs.build.outputs.new_release_published == 'true'
  170. runs-on: ubuntu-latest
  171. permissions:
  172. actions: read
  173. contents: write
  174. steps:
  175. - name: Checkout
  176. uses: actions/checkout@v6
  177. with:
  178. persist-credentials: false
  179. - name: Require SignPath configuration
  180. env:
  181. SIGNPATH_API_TOKEN: ${{ secrets.SIGNPATH_API_TOKEN }}
  182. SIGNPATH_ORGANIZATION_ID: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  183. SIGNPATH_PROJECT_SLUG: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  184. SIGNPATH_SIGNING_POLICY_SLUG: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  185. run: |
  186. missing=0
  187. for name in SIGNPATH_API_TOKEN SIGNPATH_ORGANIZATION_ID SIGNPATH_PROJECT_SLUG SIGNPATH_SIGNING_POLICY_SLUG; do
  188. if [[ -z "${!name}" ]]; then
  189. echo "Missing required SignPath setting: ${name}" >&2
  190. missing=1
  191. fi
  192. done
  193. if [[ "${missing}" -ne 0 ]]; then
  194. echo "SignPath secrets/vars are required to upload signed Windows assets. Configure them (see docs/modules/dev/pages/signing.adoc)." >&2
  195. exit 1
  196. fi
  197. - name: Sign Windows zip
  198. uses: signpath/github-action-submit-signing-request@v2
  199. with:
  200. api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
  201. organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  202. project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  203. signing-policy-slug: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  204. artifact-configuration-slug: windows-zip
  205. github-artifact-id: ${{ needs.build.outputs.windows_zip_artifact_id }}
  206. wait-for-completion: true
  207. # Preserve the signed .zip/.msi files; default decompress would unpack the zip.
  208. skip-decompress: true
  209. output-artifact-directory: signed-windows-zip
  210. - name: Sign Windows MSI
  211. uses: signpath/github-action-submit-signing-request@v2
  212. with:
  213. api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
  214. organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  215. project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  216. signing-policy-slug: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  217. artifact-configuration-slug: windows-msi
  218. github-artifact-id: ${{ needs.build.outputs.windows_msi_artifact_id }}
  219. wait-for-completion: true
  220. skip-decompress: true
  221. output-artifact-directory: signed-windows-msi
  222. - name: Upload signed Windows assets
  223. env:
  224. GH_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  225. GITHUB_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  226. run: |
  227. # SignPath may name the signed zip *.zip.zip (one compression level, bad Content-Disposition).
  228. if [[ -f signed-windows-zip/OliveTin-windows-amd64.zip.zip ]]; then
  229. mv signed-windows-zip/OliveTin-windows-amd64.zip.zip \
  230. signed-windows-zip/OliveTin-windows-amd64.zip
  231. fi
  232. zip_path="$(find signed-windows-zip -type f -name 'OliveTin-windows-amd64.zip' | head -n 1)"
  233. msi_path="$(find signed-windows-msi -type f -name 'OliveTin-windows-amd64.msi' | head -n 1)"
  234. if [[ -z "${zip_path}" || -z "${msi_path}" ]]; then
  235. echo "Signed Windows artifacts not found after SignPath:" >&2
  236. find signed-windows-zip signed-windows-msi -type f >&2 || true
  237. exit 1
  238. fi
  239. ./var/windows/signpath-publish-signed.sh \
  240. "${{ needs.build.outputs.new_release_git_tag }}" \
  241. "${zip_path}" \
  242. "${msi_path}"