diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 531a834c..aefa4062 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,6 +2,11 @@ name: Docker image builds on: workflow_dispatch: + inputs: + version: + description: "Image version/tag to publish, for example v1.0.0-beta" + required: false + type: string push: tags: ["v*"] @@ -35,9 +40,25 @@ jobs: - name: Set image metadata shell: bash + env: + INPUT_VERSION: ${{ github.event.inputs.version }} run: | + POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)" + INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}" + echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" - echo "VERSION=$(git describe --tags)" >> "$GITHUB_ENV" + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VERSION="${GITHUB_REF_NAME}" + elif [[ -n "$INPUT_VERSION" ]]; then + VERSION="$INPUT_VERSION" + elif [[ -n "$POINTED_TAG" ]]; then + VERSION="$POINTED_TAG" + else + echo "workflow_dispatch requires an explicit version input when HEAD is not tagged" >&2 + exit 1 + fi + + echo "VERSION=$VERSION" >> "$GITHUB_ENV" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -99,9 +120,25 @@ jobs: - name: Set image metadata shell: bash + env: + INPUT_VERSION: ${{ github.event.inputs.version }} run: | + POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)" + INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}" + echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" - echo "VERSION=$(git describe --tags)" >> "$GITHUB_ENV" + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VERSION="${GITHUB_REF_NAME}" + elif [[ -n "$INPUT_VERSION" ]]; then + VERSION="$INPUT_VERSION" + elif [[ -n "$POINTED_TAG" ]]; then + VERSION="$POINTED_TAG" + else + echo "workflow_dispatch requires an explicit version input when HEAD is not tagged" >&2 + exit 1 + fi + + echo "VERSION=$VERSION" >> "$GITHUB_ENV" - name: Download digests uses: actions/download-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 983c17a7..01ebd838 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,10 +2,15 @@ name: Release permissions: contents: write -on: - workflow_dispatch: - push: - tags: ["v*"] +on: + workflow_dispatch: + inputs: + version: + description: "Release version/tag to publish, for example v1.0.0-beta" + required: false + type: string + push: + tags: ["v*"] jobs: prepare: @@ -20,22 +25,33 @@ jobs: with: fetch-depth: 0 - - name: Resolve version metadata - id: version - run: | - SHOULD_RUN=true - POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)" - - if [[ "${GITHUB_REF}" == refs/heads/main ]] && [[ -n "$POINTED_TAG" ]]; then - SHOULD_RUN=true - VERSION="$POINTED_TAG" - elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then - VERSION="${GITHUB_REF_NAME}" - else - VERSION="$(git describe --tags)" - fi - - echo "should_run=$SHOULD_RUN" >> "$GITHUB_OUTPUT" + - name: Resolve version metadata + id: version + env: + INPUT_VERSION: ${{ github.event.inputs.version }} + run: | + SHOULD_RUN=true + POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)" + INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}" + + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VERSION="${GITHUB_REF_NAME}" + elif [[ -n "$INPUT_VERSION" ]]; then + VERSION="$INPUT_VERSION" + elif [[ -n "$POINTED_TAG" ]]; then + VERSION="$POINTED_TAG" + elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then + echo "workflow_dispatch requires an explicit version input when HEAD is not tagged" >&2 + exit 1 + elif [[ "${GITHUB_REF}" == refs/heads/main ]]; then + echo "main branch release requires the current commit to be tagged" >&2 + exit 1 + else + echo "unable to resolve release version from the current ref" >&2 + exit 1 + fi + + echo "should_run=$SHOULD_RUN" >> "$GITHUB_OUTPUT" echo "version=$VERSION" >> "$GITHUB_OUTPUT" if [[ "$VERSION" =~ ^v[0-9]+(\.[0-9]+)*$ ]]; then echo "is_prerelease=false" >> "$GITHUB_OUTPUT"