release.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. name: Create Release & Upload Assets
  2. on:
  3. push:
  4. # Sequence of patterns matched against refs/tags
  5. tags:
  6. - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
  7. jobs:
  8. test:
  9. name: Lint, Test, Build
  10. runs-on: ubuntu-20.04
  11. strategy:
  12. matrix:
  13. go: [ '1.15', '1.16', '1.17' ]
  14. outputs:
  15. is_prerelease: ${{ steps.is_prerelease.outputs.IS_PRERELEASE }}
  16. steps:
  17. -
  18. name: Checkout
  19. uses: actions/checkout@v2
  20. -
  21. name: Setup Go
  22. uses: actions/setup-go@v2
  23. with:
  24. go-version: ${{ matrix.go }}
  25. -
  26. name: Install Deps
  27. id: install-deps
  28. run: sudo apt-get -y install libpcsclite-dev
  29. -
  30. name: golangci-lint
  31. uses: golangci/golangci-lint-action@v2
  32. with:
  33. # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
  34. version: 'latest'
  35. # Optional: working directory, useful for monorepos
  36. # working-directory: somedir
  37. # Optional: golangci-lint command line arguments.
  38. args: --timeout=30m
  39. # Optional: show only new issues if it's a pull request. The default value is `false`.
  40. # only-new-issues: true
  41. # Optional: if set to true then the action will use pre-installed Go.
  42. # skip-go-installation: true
  43. # Optional: if set to true then the action don't cache or restore ~/go/pkg.
  44. # skip-pkg-cache: true
  45. # Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
  46. # skip-build-cache: true
  47. -
  48. name: Test, Build
  49. id: lint_test_build
  50. run: V=1 make ci
  51. create_release:
  52. name: Create Release
  53. needs: test
  54. runs-on: ubuntu-20.04
  55. outputs:
  56. debversion: ${{ steps.extract-tag.outputs.DEB_VERSION }}
  57. is_prerelease: ${{ steps.is_prerelease.outputs.IS_PRERELEASE }}
  58. steps:
  59. -
  60. name: Extract Tag Names
  61. id: extract-tag
  62. run: |
  63. DEB_VERSION=$(echo ${GITHUB_REF#refs/tags/v} | sed 's/-/./')
  64. echo "::set-output name=DEB_VERSION::${DEB_VERSION}"
  65. -
  66. name: Is Pre-release
  67. id: is_prerelease
  68. run: |
  69. set +e
  70. echo ${{ github.ref }} | grep "\-rc.*"
  71. OUT=$?
  72. if [ $OUT -eq 0 ]; then IS_PRERELEASE=true; else IS_PRERELEASE=false; fi
  73. echo "::set-output name=IS_PRERELEASE::${IS_PRERELEASE}"
  74. -
  75. name: Create Release
  76. id: create_release
  77. uses: actions/create-release@v1
  78. env:
  79. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  80. with:
  81. tag_name: ${{ github.ref }}
  82. release_name: Release ${{ github.ref }}
  83. draft: false
  84. prerelease: ${{ steps.is_prerelease.outputs.IS_PRERELEASE }}
  85. goreleaser:
  86. name: Upload Assets To Github w/ goreleaser
  87. runs-on: ubuntu-20.04
  88. needs: create_release
  89. steps:
  90. -
  91. name: Checkout
  92. uses: actions/checkout@v2
  93. with:
  94. fetch-depth: 0
  95. -
  96. name: Set up Go
  97. uses: actions/setup-go@v2
  98. with:
  99. go-version: 1.17
  100. -
  101. name: APT Install
  102. id: aptInstall
  103. run: sudo apt-get -y install build-essential debhelper fakeroot
  104. -
  105. name: Build Debian package
  106. id: make_debian
  107. run: |
  108. PATH=$PATH:/usr/local/go/bin:/home/admin/go/bin
  109. make debian
  110. # need to restore the git state otherwise goreleaser fails due to dirty state
  111. git restore debian/changelog
  112. git clean -fd
  113. -
  114. name: Install cosign
  115. uses: sigstore/cosign-installer@v1.1.0
  116. with:
  117. cosign-release: 'v1.1.0'
  118. -
  119. name: Write cosign key to disk
  120. id: write_key
  121. run: echo "${{ secrets.COSIGN_KEY }}" > "/tmp/cosign.key"
  122. -
  123. name: Get Release Date
  124. id: release_date
  125. run: |
  126. RELEASE_DATE=$(date +"%y-%m-%d")
  127. echo "::set-output name=RELEASE_DATE::${RELEASE_DATE}"
  128. -
  129. name: Run GoReleaser
  130. uses: goreleaser/goreleaser-action@5a54d7e660bda43b405e8463261b3d25631ffe86 # v2.7.0
  131. with:
  132. version: latest
  133. args: release --rm-dist
  134. env:
  135. GITHUB_TOKEN: ${{ secrets.PAT }}
  136. COSIGN_PWD: ${{ secrets.COSIGN_PWD }}
  137. DEB_VERSION: ${{ needs.create_release.outputs.debversion }}
  138. RELEASE_DATE: ${{ steps.release_date.outputs.RELEASE_DATE }}
  139. build_upload_docker:
  140. name: Build & Upload Docker Images
  141. runs-on: ubuntu-20.04
  142. needs: test
  143. steps:
  144. -
  145. name: Checkout
  146. uses: actions/checkout@v2
  147. -
  148. name: Setup Go
  149. uses: actions/setup-go@v2
  150. with:
  151. go-version: '1.17'
  152. -
  153. name: Install cosign
  154. uses: sigstore/cosign-installer@v1.1.0
  155. with:
  156. cosign-release: 'v1.1.0'
  157. -
  158. name: Write cosign key to disk
  159. id: write_key
  160. run: echo "${{ secrets.COSIGN_KEY }}" > "/tmp/cosign.key"
  161. -
  162. name: Build
  163. id: build
  164. run: |
  165. PATH=$PATH:/usr/local/go/bin:/home/admin/go/bin
  166. make docker-artifacts
  167. env:
  168. DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
  169. DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
  170. COSIGN_PWD: ${{ secrets.COSIGN_PWD }}