ci: resolve the tag without GITHUB_REF_TYPE or git
The runner sets no GITHUB_REF_TYPE, and under set -u that one missing name killed the job before any build step ran. The tag now comes from GITHUB_REF, the dispatch input, or the API's tag list, every read defaulted; the git checkout is attempted only when there is a .git to check out from. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
a977b7e parent: 691dd59 modified
.rickub/workflows/release.yml +19 -5 | @@ -39,19 +39,33 @@ jobs: | ||
| 39 | 39 | INPUT_TAG: ${{ inputs.tag }} |
| 40 | 40 | run: | |
| 41 | 41 | set -euo pipefail |
| 42 | + # Every variable here is read with a default: this runner does not | |
| 43 | + # set GITHUB_REF_TYPE, and under `set -u` one missing name is a dead | |
| 44 | + # job three steps before anything interesting happens. | |
| 45 | + REF="${GITHUB_REF:-}" | |
| 42 | 46 | if [ -n "${INPUT_TAG:-}" ]; then |
| 43 | 47 | TAG="$INPUT_TAG" |
| 44 | - elif [ "$GITHUB_REF_TYPE" = tag ]; then | |
| 45 | - TAG="$GITHUB_REF_NAME" | |
| 46 | 48 | else |
| 47 | - TAG=$(git tag --list 'v*' --sort=-v:refname | head -1) | |
| 49 | + case "$REF" in | |
| 50 | + refs/tags/*) TAG="${REF#refs/tags/}" ;; | |
| 51 | + *) | |
| 52 | + # A dispatch: no tag in the ref, so ask the API for the newest. | |
| 53 | + TAG=$(curl -sSfL -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| 54 | + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/tags" \ | |
| 55 | + | python3 -c "import json,sys; ts=[t['name'] for t in json.load(sys.stdin) if t['name'].startswith('v')]; print(ts[0] if ts else '')") | |
| 56 | + ;; | |
| 57 | + esac | |
| 48 | 58 | fi |
| 49 | 59 | case "$TAG" in |
| 50 | 60 | v*) ;; |
| 51 | 61 | *) echo "refusing to release '$TAG': not a v* tag" >&2; exit 1 ;; |
| 52 | 62 | esac |
| 53 | - git checkout --detach "$TAG" | |
| 54 | - echo "releasing $TAG at $(git rev-parse --short HEAD)" | |
| 63 | + # The runner hands a tag build the right tree already; a dispatch | |
| 64 | + # gets whatever branch it ran on, so move only when we can. | |
| 65 | + if [ -d .git ]; then | |
| 66 | + git checkout --detach "$TAG" 2>/dev/null || echo "note: building the checked-out tree, not $TAG" | |
| 67 | + fi | |
| 68 | + echo "releasing $TAG" | |
| 55 | 69 | echo "TAG=$TAG" >> "$GITHUB_ENV" |
| 56 | 70 | |
| 57 | 71 | # Toolchains come straight from upstream tarballs rather than setup |
| @@ -39,19 +39,33 @@ jobs: | |||
| 39 | INPUT_TAG: ${{ inputs.tag }} | 39 | INPUT_TAG: ${{ inputs.tag }} |
| 40 | run: | | 40 | run: | |
| 41 | set -euo pipefail | 41 | set -euo pipefail |
| 42 | + # Every variable here is read with a default: this runner does not | ||
| 43 | + # set GITHUB_REF_TYPE, and under `set -u` one missing name is a dead | ||
| 44 | + # job three steps before anything interesting happens. | ||
| 45 | + REF="${GITHUB_REF:-}" | ||
| 42 | if [ -n "${INPUT_TAG:-}" ]; then | 46 | if [ -n "${INPUT_TAG:-}" ]; then |
| 43 | TAG="$INPUT_TAG" | 47 | TAG="$INPUT_TAG" |
| 44 | - elif [ "$GITHUB_REF_TYPE" = tag ]; then | ||
| 45 | - TAG="$GITHUB_REF_NAME" | ||
| 46 | else | 48 | else |
| 47 | - TAG=$(git tag --list 'v*' --sort=-v:refname | head -1) | 49 | + case "$REF" in |
| 50 | + refs/tags/*) TAG="${REF#refs/tags/}" ;; | ||
| 51 | + *) | ||
| 52 | + # A dispatch: no tag in the ref, so ask the API for the newest. | ||
| 53 | + TAG=$(curl -sSfL -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| 54 | + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/tags" \ | ||
| 55 | + | python3 -c "import json,sys; ts=[t['name'] for t in json.load(sys.stdin) if t['name'].startswith('v')]; print(ts[0] if ts else '')") | ||
| 56 | + ;; | ||
| 57 | + esac | ||
| 48 | fi | 58 | fi |
| 49 | case "$TAG" in | 59 | case "$TAG" in |
| 50 | v*) ;; | 60 | v*) ;; |
| 51 | *) echo "refusing to release '$TAG': not a v* tag" >&2; exit 1 ;; | 61 | *) echo "refusing to release '$TAG': not a v* tag" >&2; exit 1 ;; |
| 52 | esac | 62 | esac |
| 53 | - git checkout --detach "$TAG" | 63 | + # The runner hands a tag build the right tree already; a dispatch |
| 54 | - echo "releasing $TAG at $(git rev-parse --short HEAD)" | 64 | + # gets whatever branch it ran on, so move only when we can. |
| 65 | + if [ -d .git ]; then | ||
| 66 | + git checkout --detach "$TAG" 2>/dev/null || echo "note: building the checked-out tree, not $TAG" | ||
| 67 | + fi | ||
| 68 | + echo "releasing $TAG" | ||
| 55 | echo "TAG=$TAG" >> "$GITHUB_ENV" | 69 | echo "TAG=$TAG" >> "$GITHUB_ENV" |
| 56 | 70 | ||
| 57 | # Toolchains come straight from upstream tarballs rather than setup | 71 | # Toolchains come straight from upstream tarballs rather than setup |
modified
nimstatic.nimble +1 -1 | @@ -1,4 +1,4 @@ | ||
| 1 | -version = "0.1.3" | |
| 1 | +version = "0.1.4" | |
| 2 | 2 | author = "nandi" |
| 3 | 3 | description = "Fully static Nim binaries, dependencies and all — detects what you link and fetches musl archives from Alpine" |
| 4 | 4 | license = "MIT" |
| @@ -1,4 +1,4 @@ | |||
| 1 | -version = "0.1.3" | 1 | +version = "0.1.4" |
| 2 | author = "nandi" | 2 | author = "nandi" |
| 3 | description = "Fully static Nim binaries, dependencies and all — detects what you link and fetches musl archives from Alpine" | 3 | description = "Fully static Nim binaries, dependencies and all — detects what you link and fetches musl archives from Alpine" |
| 4 | license = "MIT" | 4 | license = "MIT" |