release_esoctl.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. run: go mod download
  57. - name: Install Syft
  58. uses: anchore/sbom-action/download-syft@0b82b0b1a22399a1c542d4d656f70cd903571b5c # v0.21.1
  59. - name: Import GPG key
  60. id: import_gpg
  61. uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
  62. with:
  63. gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
  64. passphrase: ${{ secrets.GPG_PASSPHRASE }}
  65. - name: Check if Tag Exists
  66. id: check_tag
  67. env:
  68. VERSION: ${{ github.event.inputs.version }}
  69. run: |
  70. if git rev-parse "$VERSION" >/dev/null 2>&1; then
  71. echo "Tag exists."
  72. exit 1
  73. fi
  74. - name: Create Tag if Not Exists
  75. if: success()
  76. env:
  77. TAG: ${{ github.event.inputs.version }}
  78. run: |
  79. git tag $TAG
  80. git push origin $TAG
  81. - name: Run GoReleaser
  82. uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
  83. with:
  84. version: '~> v2'
  85. args: release --clean
  86. workdir: cmd/esoctl
  87. env:
  88. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  89. GORELEASER_CURRENT_TAG: ${{ github.event.inputs.version }}
  90. GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}