|
67 | 67 | id: semver |
68 | 68 | env: |
69 | 69 | REF_NAME: ${{ github.ref_name }} |
| 70 | + REF_TYPE: ${{ github.ref_type }} |
70 | 71 | run: | |
71 | | - semver="${REF_NAME#collector-}" |
| 72 | + if [ "$REF_TYPE" = "tag" ]; then |
| 73 | + tag="$REF_NAME" |
| 74 | + else |
| 75 | + # workflow_dispatch / branch run: fall back to the latest collector-v* tag |
| 76 | + tag="$(git describe --tags --abbrev=0 --match 'collector-v*')" |
| 77 | + fi |
| 78 | + if [ -z "$tag" ]; then |
| 79 | + echo "::error::no collector-v* tag found to release from" >&2 |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + # goreleaser (OSS) parses .Version from GORELEASER_CURRENT_TAG, so it |
| 83 | + # must be a bare semver (v0.2.0) with the "collector-" prefix stripped. |
| 84 | + # The GitHub release is published separately at the full tag below. |
| 85 | + semver="${tag#collector-}" |
| 86 | + echo "Releasing ${semver} (from ${tag})" |
72 | 87 | echo "tag=${semver}" >> "$GITHUB_OUTPUT" |
| 88 | + echo "full_tag=${tag}" >> "$GITHUB_OUTPUT" |
73 | 89 |
|
74 | 90 | - name: Run goreleaser |
75 | 91 | uses: goreleaser/goreleaser-action@v6 |
|
80 | 96 | env: |
81 | 97 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
82 | 98 | GORELEASER_CURRENT_TAG: ${{ steps.semver.outputs.tag }} |
| 99 | + |
| 100 | + - name: Publish GitHub release |
| 101 | + env: |
| 102 | + GH_TOKEN: ${{ github.token }} |
| 103 | + FULL_TAG: ${{ steps.semver.outputs.full_tag }} |
| 104 | + SEMVER: ${{ steps.semver.outputs.tag }} |
| 105 | + run: | |
| 106 | + # goreleaser left the archives + checksums in dist/ (release.disable). |
| 107 | + # Publish them at the namespaced collector-vX.Y.Z tag, idempotently so |
| 108 | + # re-runs of the same tag re-upload instead of failing. |
| 109 | + prerelease_flag="" |
| 110 | + case "$SEMVER" in *-*) prerelease_flag="--prerelease" ;; esac |
| 111 | + if gh release view "$FULL_TAG" >/dev/null 2>&1; then |
| 112 | + gh release upload "$FULL_TAG" dist/*.tar.gz dist/checksums.txt --clobber |
| 113 | + else |
| 114 | + gh release create "$FULL_TAG" \ |
| 115 | + --title "l9gpu-collector ${SEMVER#v}" \ |
| 116 | + --generate-notes \ |
| 117 | + $prerelease_flag \ |
| 118 | + dist/*.tar.gz dist/checksums.txt |
| 119 | + fi |
0 commit comments