release_esoctl.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. name: Create Release for esoctl
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. version:
  6. description: 'version to release, e.g. v0.1.0-esoctl'
  7. required: true
  8. default: 'v0.1.0-esoctl'
  9. source_ref:
  10. description: 'source ref to publish from. E.g.: main'
  11. required: true
  12. default: 'main'
  13. # this is required for security check even though we immediately set it to
  14. # write in the release job.
  15. permissions:
  16. contents: read
  17. jobs:
  18. release:
  19. name: Create Release for esoctl
  20. runs-on: ubuntu-latest
  21. permissions:
  22. contents: write # for publishing the release
  23. steps:
  24. - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
  25. with:
  26. egress-policy: audit
  27. - name: Checkout
  28. uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
  29. with:
  30. fetch-depth: 0
  31. - name: Resolve and validate ref
  32. id: resolve_ref
  33. run: |
  34. set -e
  35. # Try to fetch the ref from remote
  36. if git fetch origin "${{ github.event.inputs.source_ref }}"; then
  37. # Remote ref exists, use it
  38. RESOLVED_SHA=$(git rev-parse "origin/${{ github.event.inputs.source_ref }}")
  39. elif git rev-parse --verify "${{ github.event.inputs.source_ref }}" >/dev/null 2>&1; then
  40. # Local ref exists (e.g., a tag)
  41. RESOLVED_SHA=$(git rev-parse "${{ github.event.inputs.source_ref }}")
  42. else
  43. echo "Error: ref '${{ github.event.inputs.source_ref }}' not found"
  44. exit 1
  45. fi
  46. echo "Resolved to SHA: $RESOLVED_SHA"
  47. echo "sha=$RESOLVED_SHA" >> $GITHUB_OUTPUT
  48. - name: Checkout validated ref
  49. run: git checkout ${{ steps.resolve_ref.outputs.sha }}
  50. - name: Setup Go
  51. uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
  52. id: setup-go
  53. with:
  54. go-version-file: "go.mod"
  55. - name: Download Go modules
  56. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  57. run: go mod download
  58. - name: Install Syft
  59. uses: anchore/sbom-action/download-syft@a930d0ac434e3182448fe678398ba5713717112a # v0.21.0
  60. - name: Import GPG key
  61. id: import_gpg
  62. uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
  63. with:
  64. gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
  65. passphrase: ${{ secrets.GPG_PASSPHRASE }}
  66. - name: Check if Tag Exists
  67. id: check_tag
  68. env:
  69. VERSION: ${{ github.event.inputs.version }}
  70. run: |
  71. if git rev-parse "$VERSION" >/dev/null 2>&1; then
  72. echo "Tag exists."
  73. exit 1
  74. fi
  75. - name: Create Tag if Not Exists
  76. if: success()
  77. env:
  78. TAG: ${{ github.event.inputs.version }}
  79. run: |
  80. git tag $TAG
  81. git push origin $TAG
  82. - name: Run GoReleaser
  83. uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
  84. with:
  85. version: '~> v2'
  86. args: release --clean
  87. workdir: cmd/esoctl
  88. env:
  89. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  90. GORELEASER_CURRENT_TAG: ${{ github.event.inputs.version }}
  91. GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}