From 38bee98982471791133abaaa89dbffe225adeb3a Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Mon, 11 Sep 2023 19:11:25 +0200 Subject: [PATCH] chore: rekres to support gh actions Rekres to support GitHub action workflows. Signed-off-by: Noel Georgi --- .codecov.yml | 4 +- .drone.yml | 345 ------------------------------------ .github/workflows/ci.yaml | 80 ++++++++- .golangci.yml | 4 +- .kres.yaml | 20 ++- Dockerfile | 129 ++++++++------ Makefile | 12 +- internal/version/data/sha | 1 + internal/version/data/tag | 1 + internal/version/version.go | 36 +++- 10 files changed, 216 insertions(+), 416 deletions(-) delete mode 100644 .drone.yml create mode 100644 internal/version/data/sha create mode 100644 internal/version/data/tag diff --git a/.codecov.yml b/.codecov.yml index ff3eceb..c519970 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-08-29T16:54:01Z by kres bb965bb. +# Generated on 2023-09-11T18:54:59Z by kres latest. codecov: require_ci_to_pass: false @@ -9,7 +9,7 @@ coverage: status: project: default: - target: 50% + target: 7% threshold: 0.5% base: auto if_ci_failed: success diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index f2d01ef..0000000 --- a/.drone.yml +++ /dev/null @@ -1,345 +0,0 @@ ---- -# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. -# -# Generated on 2023-08-10T14:47:54Z by kres latest. - -kind: pipeline -type: kubernetes -name: default - -platform: - os: linux - arch: amd64 - -steps: -- name: setup-ci - pull: always - image: autonomy/build-container:latest - commands: - - sleep 5 - - git fetch --tags - - install-ci-key - - docker buildx create --driver docker-container --platform linux/amd64 --name local --use unix:///var/outer-run/docker.sock - - docker buildx inspect --bootstrap - environment: - SSH_KEY: - from_secret: ssh_key - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - -- name: base - pull: always - image: autonomy/build-container:latest - commands: - - make base - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - setup-ci - -- name: unit-tests - pull: always - image: autonomy/build-container:latest - commands: - - make unit-tests - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - base - -- name: unit-tests-race - pull: always - image: autonomy/build-container:latest - commands: - - make unit-tests-race - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - base - -- name: coverage - pull: always - image: autonomy/build-container:latest - commands: - - make coverage - environment: - CODECOV_TOKEN: - from_secret: CODECOV_TOKEN - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - unit-tests - -- name: bldr - pull: always - image: autonomy/build-container:latest - commands: - - make bldr - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - base - -- name: lint - pull: always - image: autonomy/build-container:latest - commands: - - make lint - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - base - -- name: image-bldr - pull: always - image: autonomy/build-container:latest - commands: - - make image-bldr - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - bldr - - lint - - unit-tests - -- name: push-bldr - pull: always - image: autonomy/build-container:latest - commands: - - docker login ghcr.io --username "$${GHCR_USERNAME}" --password "$${GHCR_PASSWORD}" - - make image-bldr - environment: - GHCR_PASSWORD: - from_secret: ghcr_token - GHCR_USERNAME: - from_secret: ghcr_username - PLATFORM: linux/amd64,linux/arm64 - PUSH: true - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - when: - event: - exclude: - - pull_request - depends_on: - - image-bldr - -- name: integration - pull: always - image: autonomy/build-container:latest - commands: - - make integration - environment: - REGISTRY: registry.dev.talos-systems.io - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - depends_on: - - base - -- name: release-notes - pull: always - image: autonomy/build-container:latest - commands: - - make release-notes - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - when: - event: - - tag - depends_on: - - unit-tests - - coverage - - bldr - - image-bldr - - integration - - lint - -- name: release - pull: always - image: plugins/github-release - settings: - api_key: - from_secret: github_token - checksum: - - sha256 - - sha512 - draft: true - files: - - _out/* - note: _out/RELEASE_NOTES.md - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - when: - event: - - tag - depends_on: - - release-notes - -services: -- name: docker - image: docker:24.0-dind - entrypoint: - - dockerd - commands: - - --dns=8.8.8.8 - - --dns=8.8.4.4 - - --mtu=1500 - - --log-level=error - privileged: true - volumes: - - name: outer-docker-socket - path: /var/outer-run - - name: docker-socket - path: /var/run - - name: buildx - path: /root/.docker/buildx - - name: ssh - path: /root/.ssh - -volumes: -- name: outer-docker-socket - host: - path: /var/ci-docker -- name: docker-socket - temp: - medium: memory -- name: buildx - temp: - medium: memory -- name: ssh - temp: - medium: memory - -trigger: - branch: - exclude: - - renovate/* - - dependabot/* - event: - exclude: - - promote - - cron - ---- -kind: pipeline -type: kubernetes -name: notify - -platform: - os: linux - arch: amd64 - -clone: - disable: true - -steps: -- name: slack - image: plugins/slack - settings: - channel: proj-talos-maintainers - link_names: true - template: "{{#if build.pull }}\n*{{#success build.status}}✓ Success{{else}}✕ Fail{{/success}}*: {{ repo.owner }}/{{ repo.name }} - \n{{else}}\n*{{#success build.status}}✓ Success{{else}}✕ Fail{{/success}}: {{ repo.owner }}/{{ repo.name }} - Build #{{ build.number }}* (type: `{{ build.event }}`)\n{{/if}}\nCommit: \nBranch: \nAuthor: {{ build.author }}\n<{{ build.link }}|Visit build page>" - webhook: - from_secret: slack_webhook - when: - status: - - success - - failure - -trigger: - branch: - exclude: - - renovate/* - - dependabot/* - status: - - success - - failure - -depends_on: -- default - -... diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 05dd981..8fb791b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,7 +13,85 @@ jobs: permissions: contents: write packages: write - runs-on: self-hosted + runs-on: + - self-hosted + - X64 steps: - name: checkout uses: actions/checkout@v3 + - name: Unshallow + run: | + git fetch --prune --unshallow + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + config-inline: | + [worker.oci] + gc = true + gckeepstorage = 100000 # 100 GiB + + [[worker.oci.gcpolicy]] + keepBytes = 32212254720 # 30 GiB + keepDuration = 604800 + filters = [ "type==source.local", "type==exec.cachemount", "type==source.git.checkout"] + [[worker.oci.gcpolicy]] + all = true + keepBytes = 107374182400 # 100 GiB + - name: base + run: | + make base + - name: unit-tests + run: | + make unit-tests + - name: unit-tests-race + run: | + make unit-tests-race + - name: coverage + run: | + make coverage + - name: bldr + run: | + make bldr + - name: lint + run: | + make lint + - name: Login to registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.repository_owner }} + - name: image-bldr + run: | + make image-bldr + - name: push-bldr + if: github.event_name != 'pull_request' + env: + PLATFORM: linux/amd64,linux/arm64 + PUSH: "true" + run: | + make image-bldr + - name: integration + env: + REGISTRY: registry.dev.siderolabs.io + run: | + make integration + - name: Generate Checksums + if: startsWith(github.ref, 'refs/tags/') + run: | + sha256sum _out/bldr-* > _out/sha256sum.txt + sha512sum _out/bldr-* > _out/sha512sum.txt + - name: release-notes + if: startsWith(github.ref, 'refs/tags/') + run: | + make release-notes + - name: Release + if: startsWith(github.ref, 'refs/tags/') + uses: crazy-max/ghaction-github-release@v1 + with: + body_path: _out/RELEASE_NOTES.md + draft: "true" + files: |- + _out/bldr-* + _out/sha*.txt diff --git a/.golangci.yml b/.golangci.yml index c302996..835046f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-08-10T14:47:54Z by kres latest. +# Generated on 2023-09-11T14:30:57Z by kres 8540947-dirty. # options for analysis running run: @@ -74,6 +74,8 @@ linters-settings: govet: check-shadowing: true enable-all: true + disable: + - loopclosure lll: line-length: 200 tab-width: 4 diff --git a/.kres.yaml b/.kres.yaml index 908cae3..778be0f 100644 --- a/.kres.yaml +++ b/.kres.yaml @@ -3,7 +3,7 @@ kind: common.Image name: image-bldr spec: pushLatest: false - droneExtraEnvironment: + extraEnvironment: PLATFORM: linux/amd64,linux/arm64 entrypointArgs: - frontend @@ -24,6 +24,20 @@ spec: GOOS: darwin GOARCH: arm64 --- +kind: service.CodeCov +spec: + targetThreshold: 7 +--- +kind: golang.Generate +spec: + versionPackagePath: internal/version +--- +kind: common.Release +name: release +spec: + artifacts: + - bldr-* +--- kind: auto.CustomSteps spec: steps: @@ -82,7 +96,7 @@ spec: - "@$(MAKE) image-bldr PUSH=true" - cp $(ARTIFACTS)/bldr-$(subst /,-,$(PLATFORM)) $(ARTIFACTS)/bldr - cd internal/pkg/integration && PATH="$$PWD/../../../$(ARTIFACTS):$$PATH" integration.test -test.v -test.run $(RUN_TESTS) - drone: + ghaction: enabled: true environment: - REGISTRY: registry.dev.talos-systems.io + REGISTRY: registry.dev.siderolabs.io diff --git a/Dockerfile b/Dockerfile index b7fe8e9..1f9d1d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,19 +2,16 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-08-10T14:47:54Z by kres latest. +# Generated on 2023-09-11T14:47:35Z by kres 8540947-dirty. ARG TOOLCHAIN -# cleaned up specs and compiled versions -FROM scratch AS generate +FROM ghcr.io/siderolabs/ca-certificates:v1.6.0-alpha.0-10-gd3d7d29 AS image-ca-certificates -FROM ghcr.io/siderolabs/ca-certificates:v1.5.0 AS image-ca-certificates - -FROM ghcr.io/siderolabs/fhs:v1.5.0 AS image-fhs +FROM ghcr.io/siderolabs/fhs:v1.6.0-alpha.0-10-gd3d7d29 AS image-fhs # runs markdownlint -FROM docker.io/node:20.5.0-alpine3.18 AS lint-markdown +FROM docker.io/node:20.5.1-alpine3.18 AS lint-markdown WORKDIR /src RUN npm i -g markdownlint-cli@0.35.0 RUN npm i sentences-per-line@0.2.1 @@ -64,49 +61,13 @@ COPY ./cmd ./cmd COPY ./internal ./internal RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null -# builds bldr-darwin-amd64 -FROM base AS bldr-darwin-amd64-build -COPY --from=generate / / -WORKDIR /src/cmd/bldr -ARG GO_BUILDFLAGS -ARG GO_LDFLAGS -ARG VERSION_PKG="github.com/siderolabs/bldr/internal/version" -ARG SHA -ARG TAG -RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=darwin go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-darwin-amd64 - -# builds bldr-darwin-arm64 -FROM base AS bldr-darwin-arm64-build -COPY --from=generate / / -WORKDIR /src/cmd/bldr -ARG GO_BUILDFLAGS -ARG GO_LDFLAGS -ARG VERSION_PKG="github.com/siderolabs/bldr/internal/version" -ARG SHA -ARG TAG -RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=darwin go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-darwin-arm64 - -# builds bldr-linux-amd64 -FROM base AS bldr-linux-amd64-build -COPY --from=generate / / -WORKDIR /src/cmd/bldr -ARG GO_BUILDFLAGS -ARG GO_LDFLAGS -ARG VERSION_PKG="github.com/siderolabs/bldr/internal/version" -ARG SHA -ARG TAG -RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-linux-amd64 - -# builds bldr-linux-arm64 -FROM base AS bldr-linux-arm64-build -COPY --from=generate / / -WORKDIR /src/cmd/bldr -ARG GO_BUILDFLAGS -ARG GO_LDFLAGS -ARG VERSION_PKG="github.com/siderolabs/bldr/internal/version" +FROM tools AS embed-generate ARG SHA ARG TAG -RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-linux-arm64 +WORKDIR /src +RUN mkdir -p internal/version/data && \ + echo -n ${SHA} > internal/version/data/sha && \ + echo -n ${TAG} > internal/version/data/tag # builds the integration test binary FROM base AS integration-build @@ -148,6 +109,71 @@ WORKDIR /src ARG TESTPKGS RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS} +FROM embed-generate AS embed-abbrev-generate +WORKDIR /src +ARG ABBREV_TAG +RUN echo -n 'undefined' > internal/version/data/sha && \ + echo -n ${ABBREV_TAG} > internal/version/data/tag + +# copies out the integration test binary +FROM scratch AS integration.test +COPY --from=integration-build /src/integration.test /integration.test + +FROM scratch AS unit-tests +COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.txt + +# cleaned up specs and compiled versions +FROM scratch AS generate +COPY --from=embed-abbrev-generate /src/internal/version internal/version + +# builds bldr-darwin-amd64 +FROM base AS bldr-darwin-amd64-build +COPY --from=generate / / +COPY --from=embed-generate / / +WORKDIR /src/cmd/bldr +ARG GO_BUILDFLAGS +ARG GO_LDFLAGS +ARG VERSION_PKG="internal/version" +ARG SHA +ARG TAG +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=darwin go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-darwin-amd64 + +# builds bldr-darwin-arm64 +FROM base AS bldr-darwin-arm64-build +COPY --from=generate / / +COPY --from=embed-generate / / +WORKDIR /src/cmd/bldr +ARG GO_BUILDFLAGS +ARG GO_LDFLAGS +ARG VERSION_PKG="internal/version" +ARG SHA +ARG TAG +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=darwin go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-darwin-arm64 + +# builds bldr-linux-amd64 +FROM base AS bldr-linux-amd64-build +COPY --from=generate / / +COPY --from=embed-generate / / +WORKDIR /src/cmd/bldr +ARG GO_BUILDFLAGS +ARG GO_LDFLAGS +ARG VERSION_PKG="internal/version" +ARG SHA +ARG TAG +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-linux-amd64 + +# builds bldr-linux-arm64 +FROM base AS bldr-linux-arm64-build +COPY --from=generate / / +COPY --from=embed-generate / / +WORKDIR /src/cmd/bldr +ARG GO_BUILDFLAGS +ARG GO_LDFLAGS +ARG VERSION_PKG="internal/version" +ARG SHA +ARG TAG +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-linux-arm64 + FROM scratch AS bldr-darwin-amd64 COPY --from=bldr-darwin-amd64-build /bldr-darwin-amd64 /bldr-darwin-amd64 @@ -160,13 +186,6 @@ COPY --from=bldr-linux-amd64-build /bldr-linux-amd64 /bldr-linux-amd64 FROM scratch AS bldr-linux-arm64 COPY --from=bldr-linux-arm64-build /bldr-linux-arm64 /bldr-linux-arm64 -# copies out the integration test binary -FROM scratch AS integration.test -COPY --from=integration-build /src/integration.test /integration.test - -FROM scratch AS unit-tests -COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.txt - FROM bldr-linux-${TARGETARCH} AS bldr FROM scratch AS bldr-all diff --git a/Makefile b/Makefile index e1b76f4..80ed0d6 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-08-10T15:46:20Z by kres latest. +# Generated on 2023-09-11T14:47:35Z by kres 8540947-dirty. # common variables @@ -14,12 +14,12 @@ WITH_RACE ?= false REGISTRY ?= ghcr.io USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) -PROTOBUF_GO_VERSION ?= 1.28.1 +PROTOBUF_GO_VERSION ?= 1.31.0 GRPC_GO_VERSION ?= 1.3.0 -GRPC_GATEWAY_VERSION ?= 2.16.2 +GRPC_GATEWAY_VERSION ?= 2.17.1 VTPROTOBUF_VERSION ?= 0.4.0 DEEPCOPY_VERSION ?= v0.5.5 -GOLANGCILINT_VERSION ?= v1.54.0 +GOLANGCILINT_VERSION ?= v1.54.2 GOFUMPT_VERSION ?= v0.5.0 GO_VERSION ?= 1.21 GOIMPORTS_VERSION ?= v0.12.0 @@ -40,6 +40,7 @@ PROGRESS ?= auto PUSH ?= false CI_ARGS ?= COMMON_ARGS = --file=Dockerfile +COMMON_ARGS += --provenance=false COMMON_ARGS += --progress=$(PROGRESS) COMMON_ARGS += --platform=$(PLATFORM) COMMON_ARGS += --push=$(PUSH) @@ -127,6 +128,9 @@ target-%: ## Builds the specified target defined in the Dockerfile. The build r local-%: ## Builds the specified target defined in the Dockerfile using the local output type. The build result will be output to the specified local destination. @$(MAKE) target-$* TARGET_ARGS="--output=type=local,dest=$(DEST) $(TARGET_ARGS)" +generate: ## Generate .proto definitions. + @$(MAKE) local-$@ DEST=./ + lint-golangci-lint: ## Runs golangci-lint linter. @$(MAKE) target-$@ diff --git a/internal/version/data/sha b/internal/version/data/sha new file mode 100644 index 0000000..66dc905 --- /dev/null +++ b/internal/version/data/sha @@ -0,0 +1 @@ +undefined \ No newline at end of file diff --git a/internal/version/data/tag b/internal/version/data/tag new file mode 100644 index 0000000..eac0a14 --- /dev/null +++ b/internal/version/data/tag @@ -0,0 +1 @@ +v0.2.1 \ No newline at end of file diff --git a/internal/version/version.go b/internal/version/version.go index 3f1426c..3fa1ad2 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -2,14 +2,40 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -// Package version provides version information. +// THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. +// +// Generated on 2023-06-27T03:07:43Z by kres b93f606. + +// Package version contains variables such as project name, tag and sha. It's a proper alternative to using +// -ldflags '-X ...'. package version +import ( + _ "embed" + "runtime/debug" + "strings" +) + var ( - // Name is set at build time. - Name string - // Tag is set at build time. + // Tag declares project git tag. + //go:embed data/tag Tag string - // SHA is set at build time. + // SHA declares project git SHA. + //go:embed data/sha SHA string + // Name declares project name. + Name = func() string { + info, ok := debug.ReadBuildInfo() + if !ok { + panic("cannot read build info, something is very wrong") + } + + // Check if siderolabs project + if strings.HasPrefix(info.Path, "github.com/siderolabs/") { + return info.Path[strings.LastIndex(info.Path, "/")+1:] + } + + // We could return a proper full path here, but it could be seen as a privacy violation. + return "community-project" + }() )