| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- name: Create Release for esoctl
- on:
- workflow_dispatch:
- inputs:
- version:
- description: 'version to release, e.g. v0.1.0-esoctl'
- required: true
- default: 'v0.1.0-esoctl'
- source_ref:
- description: 'source ref to publish from. E.g.: main'
- required: true
- default: 'main'
- # this is required for security check even though we immediately set it to
- # write in the release job.
- permissions:
- contents: read
- jobs:
- release:
- name: Create Release for esoctl
- runs-on: ubuntu-latest
- permissions:
- contents: write # for publishing the release
- steps:
- - uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
- with:
- egress-policy: audit
- - name: Checkout
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- with:
- fetch-depth: 0
- - name: Resolve and validate ref
- id: resolve_ref
- env:
- SOURCE_REF: ${{ github.event.inputs.source_ref }}
- run: |
- set -e
- # Try to fetch the ref from remote
- if git fetch origin "$SOURCE_REF"; then
- # Remote ref exists, use it
- RESOLVED_SHA=$(git rev-parse "origin/$SOURCE_REF")
- elif git rev-parse --verify "$SOURCE_REF" >/dev/null 2>&1; then
- # Local ref exists (e.g., a tag)
- RESOLVED_SHA=$(git rev-parse "$SOURCE_REF")
- else
- echo "Error: ref '$SOURCE_REF' not found"
- exit 1
- fi
- echo "Resolved to SHA: $RESOLVED_SHA"
- echo "sha=$RESOLVED_SHA" >> $GITHUB_OUTPUT
- - name: Checkout validated ref
- run: git checkout ${{ steps.resolve_ref.outputs.sha }}
- - name: Setup Go
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
- id: setup-go
- with:
- go-version-file: "go.mod"
- - name: Download Go modules
- run: go mod download
- - name: Install Syft
- uses: anchore/sbom-action/download-syft@28d71544de8eaf1b958d335707167c5f783590ad # v0.22.2
- - name: Import GPG key
- id: import_gpg
- uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
- with:
- gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
- passphrase: ${{ secrets.GPG_PASSPHRASE }}
- - name: Check if Tag Exists
- id: check_tag
- env:
- VERSION: ${{ github.event.inputs.version }}
- run: |
- if git rev-parse "$VERSION" >/dev/null 2>&1; then
- echo "Tag exists."
- exit 1
- fi
- - name: Create Tag if Not Exists
- if: success()
- env:
- TAG: ${{ github.event.inputs.version }}
- run: |
- git tag $TAG
- git push origin $TAG
- - name: Run GoReleaser
- uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
- with:
- version: '~> v2'
- args: release --clean
- workdir: cmd/esoctl
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- GORELEASER_CURRENT_TAG: ${{ github.event.inputs.version }}
- GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|