release_esoctl.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1
  25. with:
  26. egress-policy: audit
  27. - name: Checkout
  28. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  29. with:
  30. fetch-depth: 0
  31. - name: Resolve and validate ref
  32. id: resolve_ref
  33. env:
  34. SOURCE_REF: ${{ github.event.inputs.source_ref }}
  35. run: |
  36. set -e
  37. # Try to fetch the ref from remote
  38. if git fetch origin "$SOURCE_REF"; then
  39. # Remote ref exists, use it
  40. RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
  41. elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
  42. # Local ref exists (e.g., a tag)
  43. RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
  44. else
  45. echo "Error: ref '$SOURCE_REF' not found"
  46. exit 1
  47. fi
  48. echo "Resolved to SHA: $RESOLVED_SHA"
  49. echo "sha=$RESOLVED_SHA" >> $GITHUB_OUTPUT
  50. - name: Checkout validated ref
  51. run: git checkout ${{ steps.resolve_ref.outputs.sha }}
  52. - name: Setup Go
  53. uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
  54. id: setup-go
  55. with:
  56. go-version-file: "go.mod"
  57. - name: Download Go modules
  58. run: go mod download
  59. - name: Install Syft
  60. uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
  61. - name: Import GPG key
  62. id: import_gpg
  63. uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd # v7.0.0
  64. with:
  65. gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
  66. passphrase: ${{ secrets.GPG_PASSPHRASE }}
  67. - name: Check if Tag Exists
  68. id: check_tag
  69. env:
  70. VERSION: ${{ github.event.inputs.version }}
  71. run: |
  72. if git rev-parse "$VERSION" >/dev/null 2>&1; then
  73. echo "Tag exists."
  74. exit 1
  75. fi
  76. - name: Create Tag if Not Exists
  77. if: success()
  78. env:
  79. TAG: ${{ github.event.inputs.version }}
  80. run: |
  81. git tag $TAG
  82. git push origin $TAG
  83. - name: Run GoReleaser
  84. uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
  85. with:
  86. version: '~> v2'
  87. args: release --clean
  88. workdir: cmd/esoctl
  89. env:
  90. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  91. GORELEASER_CURRENT_TAG: ${{ github.event.inputs.version }}
  92. GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}