build-and-release.yml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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: release
  118. id: release
  119. if: github.ref_type != 'tag' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
  120. uses: cycjimmy/semantic-release-action@v5
  121. with:
  122. extra_plugins: |
  123. @semantic-release/commit-analyzer
  124. @semantic-release/exec
  125. @semantic-release/git
  126. env:
  127. GITHUB_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  128. GH_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  129. MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
  130. MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
  131. MACOS_NOTARY_KEY: ${{ secrets.MACOS_NOTARY_KEY }}
  132. MACOS_NOTARY_KEY_ID: ${{ secrets.MACOS_NOTARY_KEY_ID }}
  133. MACOS_NOTARY_ISSUER_ID: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}
  134. - name: Upload unsigned Windows zip for SignPath
  135. id: upload-windows-zip
  136. if: steps.release.outputs.new_release_published == 'true'
  137. uses: actions/upload-artifact@v7
  138. with:
  139. # Upload as-is so SignPath receives OliveTin-windows-amd64.zip, not a wrapper zip.
  140. # With archive: false, the artifact name is the filename (`name` is ignored).
  141. path: dist/OliveTin-windows-amd64.zip
  142. archive: false
  143. if-no-files-found: error
  144. - name: Upload unsigned Windows MSI for SignPath
  145. id: upload-windows-msi
  146. if: steps.release.outputs.new_release_published == 'true'
  147. uses: actions/upload-artifact@v7
  148. with:
  149. path: dist/OliveTin-windows-amd64.msi
  150. archive: false
  151. if-no-files-found: error
  152. - name: Archive binaries
  153. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
  154. uses: actions/upload-artifact@v7
  155. with:
  156. name: "OliveTin-snapshot-${{ env.DATE }}-${{ github.sha }}"
  157. path: dist/OliveTin*.*
  158. sign-windows:
  159. name: Sign Windows artifacts (SignPath)
  160. needs: build
  161. if: needs.build.outputs.new_release_published == 'true'
  162. runs-on: ubuntu-latest
  163. permissions:
  164. actions: read
  165. contents: write
  166. steps:
  167. - name: Checkout
  168. uses: actions/checkout@v6
  169. with:
  170. persist-credentials: false
  171. - name: Require SignPath configuration
  172. env:
  173. SIGNPATH_API_TOKEN: ${{ secrets.SIGNPATH_API_TOKEN }}
  174. SIGNPATH_ORGANIZATION_ID: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  175. SIGNPATH_PROJECT_SLUG: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  176. SIGNPATH_SIGNING_POLICY_SLUG: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  177. run: |
  178. missing=0
  179. for name in SIGNPATH_API_TOKEN SIGNPATH_ORGANIZATION_ID SIGNPATH_PROJECT_SLUG SIGNPATH_SIGNING_POLICY_SLUG; do
  180. if [[ -z "${!name}" ]]; then
  181. echo "Missing required SignPath setting: ${name}" >&2
  182. missing=1
  183. fi
  184. done
  185. if [[ "${missing}" -ne 0 ]]; then
  186. echo "SignPath secrets/vars are required to upload signed Windows assets. Configure them (see docs/modules/dev/pages/signing.adoc)." >&2
  187. exit 1
  188. fi
  189. - name: Sign Windows zip
  190. uses: signpath/github-action-submit-signing-request@v2
  191. with:
  192. api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
  193. organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  194. project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  195. signing-policy-slug: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  196. artifact-configuration-slug: windows-zip
  197. github-artifact-id: ${{ needs.build.outputs.windows_zip_artifact_id }}
  198. wait-for-completion: true
  199. # Preserve the signed .zip/.msi files; default decompress would unpack the zip.
  200. skip-decompress: true
  201. output-artifact-directory: signed-windows-zip
  202. - name: Sign Windows MSI
  203. uses: signpath/github-action-submit-signing-request@v2
  204. with:
  205. api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
  206. organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
  207. project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
  208. signing-policy-slug: ${{ vars.SIGNPATH_SIGNING_POLICY_SLUG }}
  209. artifact-configuration-slug: windows-msi
  210. github-artifact-id: ${{ needs.build.outputs.windows_msi_artifact_id }}
  211. wait-for-completion: true
  212. skip-decompress: true
  213. output-artifact-directory: signed-windows-msi
  214. - name: Upload signed Windows assets
  215. env:
  216. GH_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  217. GITHUB_TOKEN: ${{ secrets.CONTAINER_TOKEN }}
  218. run: |
  219. zip_path="$(find signed-windows-zip -type f -name 'OliveTin-windows-amd64.zip' | head -n 1)"
  220. msi_path="$(find signed-windows-msi -type f -name 'OliveTin-windows-amd64.msi' | head -n 1)"
  221. if [[ -z "${zip_path}" || -z "${msi_path}" ]]; then
  222. echo "Signed Windows artifacts not found after SignPath:" >&2
  223. find signed-windows-zip signed-windows-msi -type f >&2 || true
  224. exit 1
  225. fi
  226. ./var/windows/signpath-publish-signed.sh \
  227. "${{ needs.build.outputs.new_release_git_tag }}" \
  228. "${zip_path}" \
  229. "${msi_path}"