release.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. name: release-binaries
  2. on:
  3. push:
  4. tags:
  5. - "v*"
  6. workflow_dispatch:
  7. permissions:
  8. contents: write
  9. jobs:
  10. web:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout
  14. uses: actions/checkout@v4
  15. - name: Set up Node.js
  16. uses: actions/setup-node@v4
  17. with:
  18. node-version: "20"
  19. cache: npm
  20. cache-dependency-path: web/package-lock.json
  21. - name: Build embedded web UI
  22. working-directory: web
  23. run: |
  24. npm ci --no-audit --no-fund
  25. npm run build
  26. - name: Upload embedded web UI
  27. uses: actions/upload-artifact@v4
  28. with:
  29. name: web-dist
  30. path: web/dist
  31. if-no-files-found: error
  32. retention-days: 1
  33. test:
  34. runs-on: ubuntu-latest
  35. steps:
  36. - name: Checkout
  37. uses: actions/checkout@v4
  38. - name: Set up Go
  39. uses: actions/setup-go@v5
  40. with:
  41. go-version-file: go.mod
  42. cache: true
  43. - name: Test
  44. run: go test ./...
  45. binaries:
  46. needs: [web, test]
  47. runs-on: ubuntu-latest
  48. strategy:
  49. fail-fast: false
  50. matrix:
  51. include:
  52. - target: linux-amd64
  53. goarch: amd64
  54. goarm: ""
  55. filename: vocat-linux-amd64
  56. - target: linux-386
  57. goarch: "386"
  58. goarm: ""
  59. filename: vocat-linux-386
  60. - target: linux-arm64
  61. goarch: arm64
  62. goarm: ""
  63. filename: vocat-linux-arm64
  64. - target: linux-armv7
  65. goarch: arm
  66. goarm: "7"
  67. filename: vocat-linux-armv7
  68. steps:
  69. - name: Checkout
  70. uses: actions/checkout@v4
  71. - name: Set up Go
  72. uses: actions/setup-go@v5
  73. with:
  74. go-version-file: go.mod
  75. cache: true
  76. - name: Download embedded web UI
  77. uses: actions/download-artifact@v4
  78. with:
  79. name: web-dist
  80. path: web/dist
  81. - name: Build ${{ matrix.target }}
  82. env:
  83. GOOS: linux
  84. GOARCH: ${{ matrix.goarch }}
  85. GOARM: ${{ matrix.goarm }}
  86. CGO_ENABLED: "0"
  87. OUTPUT: dist/${{ matrix.filename }}
  88. VERSION: ${{ github.ref_name }}
  89. run: |
  90. mkdir -p dist
  91. VERSION="${VERSION#v}"
  92. BUILD_TIME="$(git show -s --format=%cI HEAD)"
  93. go build -trimpath \
  94. -ldflags "-s -w -X vocat/internal/buildinfo.Version=${VERSION} -X vocat/internal/buildinfo.BuildTime=${BUILD_TIME}" \
  95. -o "$OUTPUT" \
  96. ./cmd/vocat
  97. chmod 0755 "$OUTPUT"
  98. - name: Upload ${{ matrix.target }}
  99. uses: actions/upload-artifact@v4
  100. with:
  101. name: binary-${{ matrix.target }}
  102. path: dist/${{ matrix.filename }}
  103. if-no-files-found: error
  104. retention-days: 1
  105. github-release:
  106. if: github.ref_type == 'tag'
  107. needs: binaries
  108. runs-on: ubuntu-latest
  109. env:
  110. GH_TOKEN: ${{ github.token }}
  111. steps:
  112. - name: Download binaries
  113. uses: actions/download-artifact@v4
  114. with:
  115. pattern: binary-*
  116. path: dist
  117. merge-multiple: true
  118. - name: Generate checksums
  119. working-directory: dist
  120. run: sha256sum vocat-linux-* | sort > SHA256SUMS
  121. - name: Create or update GitHub Release
  122. run: |
  123. if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
  124. gh release upload "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --clobber
  125. else
  126. gh release create "$GITHUB_REF_NAME" dist/* \
  127. --repo "$GITHUB_REPOSITORY" \
  128. --title "$GITHUB_REF_NAME" \
  129. --generate-notes \
  130. --verify-tag
  131. fi