From a51563b996da452bd2b1ee0181a651b172974aa8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 16 May 2024 18:09:46 -0400 Subject: [PATCH] refactor: remove shell entrypoint --- Dockerfile | 3 +-- README.md | 3 --- action.yml | 9 +++++---- entrypoint | 26 -------------------------- main.go | 21 ++++++++++++++++++--- 5 files changed, 24 insertions(+), 38 deletions(-) delete mode 100755 entrypoint diff --git a/Dockerfile b/Dockerfile index 5f675d1..a682175 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,5 @@ FROM alpine:3.19.1 # hadolint ignore=DL3018 RUN apk add --no-cache bash COPY --from=builder /go/src/github.com/dokku/semver/semver /usr/local/bin/semver -COPY entrypoint /usr/local/bin/entrypoint -ENTRYPOINT ["/usr/local/bin/entrypoint"] +ENTRYPOINT ["/usr/local/bin/semver"] LABEL org.opencontainers.image.description "A tool for generating a semver version from an existing version and a desired bump level" \ No newline at end of file diff --git a/README.md b/README.md index 342d71a..2cafb01 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,6 @@ docker build --progress plain -t semver . # run it with arguments docker run --rm semver --input 0.1.2 --bump patch - -# run it with environment variables -docker run --rm -e SEMVER_GENERATOR_INPUT=0.1.2 -e SEMVER_GENERATOR_BUMP=patch semver ``` ## Releasing diff --git a/action.yml b/action.yml index 5ad3c89..38b875a 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,8 @@ inputs: runs: using: "docker" image: "Dockerfile" - entrypoint: "/usr/local/bin/entrypoint" - env: - SEMVER_GENERATOR_BUMP: ${{ inputs.bump }} - SEMVER_GENERATOR_INPUT: ${{ inputs.input }} + args: + - "--bump" + - ${{ inputs.bump }} + - "--input" + - ${{ inputs.input }} diff --git a/entrypoint b/entrypoint deleted file mode 100755 index 757a02f..0000000 --- a/entrypoint +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -e - -main() { - declare ARGS=("$@") - if [[ -n "$SEMVER_GENERATOR_INPUT" ]] && [[ -n "$SEMVER_GENERATOR_BUMP" ]]; then - ARGS=("--input" "$SEMVER_GENERATOR_INPUT" "--bump" "$SEMVER_GENERATOR_BUMP") - fi - - if [ ${#ARGS[@]} -eq 0 ]; then - echo "No arguments provided for bumping version" >&2 - exit 1 - fi - - if ! /usr/local/bin/semver "${ARGS[@]}" >/dev/null; then - exit 1 - fi - - BUMPED_VERSION="$(/usr/local/bin/semver "${ARGS[@]}")" - echo "$BUMPED_VERSION" - if [ -n "$GITHUB_OUTPUT" ]; then - echo "BUMPED_VERSION=$BUMPED_VERSION" >>"$GITHUB_OUTPUT" - fi -} - -main "$@" diff --git a/main.go b/main.go index 9e6caa5..b3249a2 100644 --- a/main.go +++ b/main.go @@ -58,9 +58,24 @@ func main() { parsed.Patch += 1 } + updatedVersion := parsed.String() if addPrefix { - fmt.Printf("v" + parsed.String() + "\n") - } else { - fmt.Printf(parsed.String() + "\n") + updatedVersion = "v" + parsed.String() + } + + fmt.Printf(updatedVersion + "\n") + githubOutput := os.Getenv("GITHUB_OUTPUT") + if githubOutput != "" { + f, err := os.OpenFile(githubOutput, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + slog.Error("Failed to open file", "file", githubOutput, "error", err.Error()) + os.Exit(1) + } + defer f.Close() + + if _, err = f.WriteString(fmt.Sprintf("VERSION=%s", updatedVersion)); err != nil { + slog.Error("Failed to write to file", "file", githubOutput, "error", err.Error()) + os.Exit(1) + } } }