release_esoctl.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. persist-credentials: false
  32. - name: Resolve and validate ref
  33. id: resolve_ref
  34. env:
  35. SOURCE_REF: ${{ github.event.inputs.source_ref }}
  36. run: |
  37. set -e
  38. # Try to fetch the ref from remote
  39. if git fetch origin "$SOURCE_REF"; then
  40. # Remote ref exists, use it
  41. RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
  42. elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
  43. # Local ref exists (e.g., a tag)
  44. RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
  45. else
  46. echo "Error: ref '$SOURCE_REF' not found"
  47. exit 1
  48. fi
  49. echo "Resolved to SHA: $RESOLVED_SHA"
  50. echo "sha=$RESOLVED_SHA" >> $GITHUB_OUTPUT
  51. - name: Checkout validated ref
  52. env:
  53. RESOLVED_SHA: ${{ steps.resolve_ref.outputs.sha }}
  54. run: git checkout "$RESOLVED_SHA"
  55. - name: Setup Go
  56. uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
  57. id: setup-go
  58. with:
  59. go-version-file: "go.mod"
  60. cache: false
  61. - name: Download Go modules
  62. run: go mod download
  63. - name: Install Syft
  64. uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
  65. - name: Import GPG key
  66. id: import_gpg
  67. uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd # v7.0.0
  68. env:
  69. GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
  70. GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
  71. with:
  72. gpg_private_key: ${{ env.GPG_PRIVATE_KEY }}
  73. passphrase: ${{ env.GPG_PASSPHRASE }}
  74. - name: Check if Tag Exists
  75. id: check_tag
  76. env:
  77. VERSION: ${{ github.event.inputs.version }}
  78. run: |
  79. if git rev-parse "$VERSION" >/dev/null 2>&1; then
  80. echo "Tag exists."
  81. exit 1
  82. fi
  83. - name: Configure Git credentials
  84. env:
  85. TOKEN: ${{ secrets.GITHUB_TOKEN }}
  86. GH_REPO: ${{ github.repository }}
  87. run: |
  88. git config user.name "$GITHUB_ACTOR"
  89. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  90. git remote set-url origin "https://x-access-token:${TOKEN}@github.com/${GH_REPO}.git"
  91. - name: Create Tag if Not Exists
  92. if: success()
  93. env:
  94. TAG: ${{ github.event.inputs.version }}
  95. run: |
  96. git tag $TAG
  97. git push origin $TAG
  98. - name: Run GoReleaser
  99. uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
  100. with:
  101. version: '~> v2'
  102. args: release --clean
  103. workdir: cmd/esoctl
  104. env:
  105. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  106. GORELEASER_CURRENT_TAG: ${{ github.event.inputs.version }}
  107. GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}