build-and-release.yml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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: build service
  95. run: make -w service
  96. - name: integration tests
  97. run: cd integration-tests && make -w
  98. - name: Archive integration tests
  99. uses: actions/upload-artifact@v7
  100. if: always()
  101. with:
  102. name: "OliveTin-integration-tests-${{ env.DATE }}-${{ github.sha }}"
  103. path: |
  104. integration-tests
  105. !integration-tests/node_modules
  106. - name: Install wixl and msitools
  107. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  108. run: sudo apt-get update && sudo apt-get install -y wixl msitools
  109. - name: Install goreleaser
  110. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  111. uses: goreleaser/goreleaser-action@v7
  112. with:
  113. install-only: true
  114. - name: Set up Docker Buildx
  115. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  116. uses: docker/setup-buildx-action@v4
  117. - name: Verify macOS signing certificate chain
  118. if: github.ref_type != 'tag' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
  119. env:
  120. MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
  121. MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
  122. run: ./var/macos/verify-macos-sign-p12.sh
  123. - name: release
  124. id: release
  125. if: github.ref_type != 'tag' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
  126. uses: cycjimmy/semantic-release-action@v5
  127. with:
  128. extra_plugins: |
  129. @semantic-release/commit-analyzer
  130. @semantic-release/exec
  131. @semantic-release/git
  132. env:
  133. GITHUB_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  134. GH_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  135. MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
  136. MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
  137. MACOS_NOTARY_KEY: ${{ secrets.MACOS_NOTARY_KEY }}
  138. MACOS_NOTARY_KEY_ID: ${{ secrets.MACOS_NOTARY_KEY_ID }}
  139. MACOS_NOTARY_ISSUER_ID: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}
  140. - name: Upload unsigned Windows zip for SignPath
  141. id: upload-windows-zip
  142. if: steps.release.outputs.new_release_published == 'true'
  143. uses: actions/upload-artifact@v7
  144. with:
  145. # Upload as-is so SignPath receives OliveTin-windows-amd64.zip, not a wrapper zip.
  146. # With archive: false, the artifact name is the filename (`name` is ignored).
  147. path: dist/OliveTin-windows-amd64.zip
  148. archive: false
  149. if-no-files-found: error
  150. - name: Upload unsigned Windows MSI for SignPath
  151. id: upload-windows-msi
  152. if: steps.release.outputs.new_release_published == 'true'
  153. uses: actions/upload-artifact@v7
  154. with:
  155. path: dist/OliveTin-windows-amd64.msi
  156. archive: false
  157. if-no-files-found: error
  158. - name: Archive binaries
  159. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  160. uses: actions/upload-artifact@v7
  161. with:
  162. name: "OliveTin-snapshot-${{ env.DATE }}-${{ github.sha }}"
  163. path: dist/OliveTin*.*
  164. sign-windows:
  165. name: Sign Windows artifacts (SignPath)
  166. needs: build
  167. if: needs.build.outputs.new_release_published == 'true'
  168. runs-on: ubuntu-latest
  169. permissions:
  170. actions: read
  171. contents: write
  172. steps:
  173. - name: Checkout
  174. uses: actions/checkout@v6
  175. with:
  176. persist-credentials: false
  177. - name: Require SignPath configuration
  178. env:
  179. SIGNPATH_API_TOKEN: ${{ secrets.SIGNPATH_API_TOKEN }}
  180. SIGNPATH_ORGANIZATION_ID: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  181. SIGNPATH_PROJECT_SLUG: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  182. SIGNPATH_SIGNING_POLICY_SLUG: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  183. run: |
  184. missing=0
  185. for name in SIGNPATH_API_TOKEN SIGNPATH_ORGANIZATION_ID SIGNPATH_PROJECT_SLUG SIGNPATH_SIGNING_POLICY_SLUG; do
  186. if [[ -z "${!name}" ]]; then
  187. echo "Missing required SignPath setting: ${name}" >&2
  188. missing=1
  189. fi
  190. done
  191. if [[ "${missing}" -ne 0 ]]; then
  192. echo "SignPath secrets/vars are required to upload signed Windows assets. Configure them (see docs/modules/dev/pages/signing.adoc)." >&2
  193. exit 1
  194. fi
  195. - name: Sign Windows zip
  196. uses: signpath/github-action-submit-signing-request@v2
  197. with:
  198. api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
  199. organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  200. project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  201. signing-policy-slug: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  202. artifact-configuration-slug: windows-zip
  203. github-artifact-id: ${{ needs.build.outputs.windows_zip_artifact_id }}
  204. wait-for-completion: true
  205. # Preserve the signed .zip/.msi files; default decompress would unpack the zip.
  206. skip-decompress: true
  207. output-artifact-directory: signed-windows-zip
  208. - name: Sign Windows MSI
  209. uses: signpath/github-action-submit-signing-request@v2
  210. with:
  211. api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
  212. organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  213. project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  214. signing-policy-slug: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  215. artifact-configuration-slug: windows-msi
  216. github-artifact-id: ${{ needs.build.outputs.windows_msi_artifact_id }}
  217. wait-for-completion: true
  218. skip-decompress: true
  219. output-artifact-directory: signed-windows-msi
  220. - name: Upload signed Windows assets
  221. env:
  222. GH_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  223. GITHUB_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  224. run: |
  225. # SignPath may name the signed zip *.zip.zip (one compression level, bad Content-Disposition).
  226. if [[ -f signed-windows-zip/OliveTin-windows-amd64.zip.zip ]]; then
  227. mv signed-windows-zip/OliveTin-windows-amd64.zip.zip \
  228. signed-windows-zip/OliveTin-windows-amd64.zip
  229. fi
  230. zip_path="$(find signed-windows-zip -type f -name 'OliveTin-windows-amd64.zip' | head -n 1)"
  231. msi_path="$(find signed-windows-msi -type f -name 'OliveTin-windows-amd64.msi' | head -n 1)"
  232. if [[ -z "${zip_path}" || -z "${msi_path}" ]]; then
  233. echo "Signed Windows artifacts not found after SignPath:" >&2
  234. find signed-windows-zip signed-windows-msi -type f >&2 || true
  235. exit 1
  236. fi
  237. ./var/windows/signpath-publish-signed.sh \
  238. "${{ needs.build.outputs.new_release_git_tag }}" \
  239. "${zip_path}" \
  240. "${msi_path}"