diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3f03b2fd..c5af4938 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,7 +19,9 @@ jobs: name: Build and publish runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + fetch-tags: true - name: Echo Go Cache Paths id: go-cache-paths @@ -44,11 +46,18 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and Push + - name: Get version + id: get-version + env: + ENVBUILDER_RELEASE: "t" run: | - VERSION=$(./scripts/version.sh) - BASE=ghcr.io/coder/envbuilder + echo "ENVBUILDER_VERSION=$(./scripts.version.sh)" >> $GITHUB_OUTPUT + - name: Build and Push + env: + VERSION: "${{ steps.get-version.outputs.ENVBUILDER_VERSION }}" + BASE: "ghcr.io/coder/envbuilder" + run: | ./scripts/build.sh \ --arch=amd64 \ --arch=arm64 \ diff --git a/scripts/lib.sh b/scripts/lib.sh index 3fbcd979..b39c0b9d 100644 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -39,3 +39,9 @@ cdroot() { log() { echo "$*" 1>&2 } + +# error prints an error message and returns an error exit code. +error() { + log "ERROR: $*" + exit 1 +} diff --git a/scripts/version.sh b/scripts/version.sh index 17c8f727..75dafcc4 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -54,18 +54,11 @@ if [[ "${ENVBUILDER_RELEASE:-}" == *t* ]]; then # $last_tag will equal `git describe --always` if we currently have the tag # checked out. if [[ "${last_tag}" != "$(git describe --always)" ]]; then - # make won't exit on $(shell cmd) failures, so we have to kill it :( - if [[ "$(ps -o comm= "${PPID}" || true)" == *make* ]]; then - log "ERROR: version.sh: the current commit is not tagged with an annotated tag" - kill "${PPID}" || true - exit 1 - fi - error "version.sh: the current commit is not tagged with an annotated tag" fi else - rev=$(git rev-parse --short HEAD) - version="0.0.0+dev-${rev}" + rev=$(git log -1 --format='%h' HEAD) + version+="+dev-${rev}" # If the git repo has uncommitted changes, mark the version string as 'dirty'. dirty_files=$(git ls-files --other --modified --exclude-standard) if [[ -n "${dirty_files}" ]]; then @@ -73,6 +66,5 @@ else fi fi - # Remove the "v" prefix. echo "${version#v}"