Skip to content

CICD: GoReleaser version - part 1#2737

Merged
tlimoncelli merged 9 commits intoStackExchange:masterfrom
cafferata:cicd/goreleaser-version
Jan 2, 2024
Merged

CICD: GoReleaser version - part 1#2737
tlimoncelli merged 9 commits intoStackExchange:masterfrom
cafferata:cicd/goreleaser-version

Conversation

@cafferata
Copy link
Copy Markdown
Collaborator

What is the reason for this pull request?

I saw the comment below listed in the various YAML files within .github/workflows. So I thought I'd see how far I could get! 🤓

  1. .github/workflows/pr_test.yml#L41-L44
  2. .github/workflows/release_draft.yml#L52-L55
# For some reason goreleaser isn't correctly setting the version
# string used by "dnscontrol version".  Therefore, we're forcing the
# string using the GORELEASER_CURRENT_TAG feature.
# TODO(tlim): Use the native gorelease version mechanism.

GoReleaser documentation

By default, GoReleaser will set the following 3 ldflags:

  1. main.version: Current Git tag (the v prefix is stripped) or the name of the snapshot, if you're using the --snapshot flag
  2. main.commit: Current git commit SHA
  3. main.date: Date in the RFC3339 format

https://goreleaser.com/cookbooks/using-main.version/

Name Templates

  1. {{ .Version }}: the version being released
  2. {{ .Commit }}: the git commit hash (deprecated)
  3. {{ .Date }}: current UTC date in RFC 3339 format

https://goreleaser.com/customization/templates/

GitHub Actions

https://goreleaser.com/ci/actions/

How has this work (locally) been tested?

GoReleaser

goreleaser build --snapshot --clean
GoReleaser output
  • starting build...
  • loading                                          path=.goreleaser.yml
  • skipping validate...
  • loading environment variables
  • getting and validating git state
    • git state                                      commit=7bee368435c9fdd8ed8beaf6df4398fd1835cfb9 branch=cicd/goreleaser-version current_tag=v4.7.3 previous_tag=v4.7.2 dirty=true
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • snapshotting
    • building snapshot...                           version=4.7.4-next
  • running before hooks
    • running                                        hook=go fmt ./...
    • running                                        hook=go mod tidy
    • running                                        hook=go generate ./...
    • took: 3s
  • checking distribution directory
    • cleaning dist
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/build_darwin_arm64/dnscontrol
    • building                                       binary=dist/build_darwin_amd64_v1/dnscontrol
    • took: 4s
  • universal binaries
    • creating from 2 binaries                       id=build binary=dist/build_darwin_all/dnscontrol
  • storing release metadata
    • writing                                        file=dist/artifacts.json
    • writing                                        file=dist/metadata.json
  • build succeeded after 7s
  • thanks for using goreleaser!
./dist/build_darwin_all/dnscontrol version
-dnscontrol "4.7.4-next" ("1bbf9c4293f6cd5127bf190ead5ed738dd11c437") built 19 Dec 23 12:28 CET
+DNSControl 4.7.4-next

Go build

go build
./dnscontrol version
-dnscontrol -dev
+DNSControl dev

DNSControl TypeScript

./dist/build_darwin_all/dnscontrol write-types
Successfully wrote types-dnscontrol.d.ts
head types-dnscontrol.d.ts
// This file was automatically generated by DNSControl. Do not edit it directly.
// To update it, run `dnscontrol write-types`.

-// DNSControl version: "4.7.4-next" ("1bbf9c4293f6cd5127bf190ead5ed738dd11c437") built 19 Dec 23 12:28 CET
+// DNSControl 4.7.4-next
// WARNING: These type definitions are experimental and subject to change in future releases.

interface Domain {
    name: string;
    subdomain: string;
    registrar: unknown;

Homebrew

For completeness the reporting of the current Homebrew ldflags configuration

go_ldflags = %W[
  -s -w
  -X main.SHA=#{tap.user}
  -X main.Version=#{version}
  -X main.BuildTime=#{time.iso8601}
]
system "go", "build", *std_go_args(ldflags: go_ldflags)
./dnscontrol version
dnscontrol 4.7.3 (Homebrew)

P.S. This pull request is best reviewed by a commit-by-commit review.

@tlimoncelli
Copy link
Copy Markdown
Contributor

Looks good!

Could you remove the whitespace changes? (I guess we need to standardize on a YAML prettier :) ).

@cafferata cafferata force-pushed the cicd/goreleaser-version branch from 4431f23 to 1602bcb Compare December 19, 2023 17:48
@cafferata
Copy link
Copy Markdown
Collaborator Author

Could you remove the whitespace changes?

Done!

P.S. The reason why this was committed was because my IDE (GoLand) continuously implemented this format.

(I guess we need to standardize on a YAML prettier :) ).

Yes certainly, already discussed and local branch with Prettier is almost ready.

@cafferata cafferata force-pushed the cicd/goreleaser-version branch from 1602bcb to e956385 Compare December 19, 2023 17:51
@tlimoncelli
Copy link
Copy Markdown
Contributor

If we make this change, we're going to have to do a pre-release and let people check it out. We get a lot of complaints when that version string changes or breaks.

@cafferata
Copy link
Copy Markdown
Collaborator Author

That's a great idea! Would you like to arrange this? I am not able to do that myself. 😊

@cafferata cafferata force-pushed the cicd/goreleaser-version branch from e956385 to 3813c25 Compare December 30, 2023 06:49
@tlimoncelli tlimoncelli merged commit 17da0bc into StackExchange:master Jan 2, 2024
tlimoncelli added a commit that referenced this pull request Jan 2, 2024
@tlimoncelli
Copy link
Copy Markdown
Contributor

@cafferata
Copy link
Copy Markdown
Collaborator Author

Sadly I had to revert this because the build broke

That's annoying, I could have seen this by running the GitHub Actions on my GitHub fork repository. Sorry! 😕

I have tried to reproduce this error locally. However, this has not been achieved. The GoReleaser output diff with actions/runs/7390125976/job/20104387012:

 • starting build...
 • loading                                          path=.goreleaser.yml
 • skipping validate...
 • loading environment variables
 • getting and validating git state
-  • git state                                      commit=7fc1d32fbbad5f8eb671397f96533e5e7fb0a0fc branch=cicd/goreleaser-version current_tag=v4.7.3 previous_tag=v4.7.2 dirty=true
+  • accepting to run without a git repository because this is a snapshot
+  • git state                                      commit=none branch=none current_tag=v0.0.0 previous_tag=<unknown> dirty=false
   • pipe skipped                                   reason=disabled during snapshot mode
 • parsing tag
 • setting defaults
 • snapshotting
-  • building snapshot...                           version=4.7.4-next
+  • building snapshot...                           version=0.0.1-next
 • running before hooks
   • running                                        hook=go fmt ./...
   • running                                        hook=go mod tidy
   • running                                        hook=go generate ./...
   • took: 8s
 • checking distribution directory
-  • cleaning dist
 • loading go mod information
 • build prerequisites
 • writing effective config file
   • writing                                        config=dist/config.yaml
 • building binaries

So I've try without the git directory. This GoReleaser build was also successful.

mv .git/ .git-move-directory-for-goreleaser-build/

The suggestion from the GitHub action leads me to the go help build

  ⨯ build failed after 4s                    error=failed to build for windows_amd64_v1: exit status 1: error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping.
The build flags are shared by the build, clean, get, install, list, run,
and test commands:

	-buildvcs
		Whether to stamp binaries with version control information
		("true", "false", or "auto"). By default ("auto"), version control
		information is stamped into a binary if the main package, the main module
		containing it, and the current directory are all in the same repository.
		Use -buildvcs=false to always omit version control information, or
		-buildvcs=true to error out if version control information is available but
		cannot be included due to a missing tool or ambiguous directory structure.
Sources consulted

Captured for archival purposes.

https://github.com/golang/go/issues/49004
https://github.com/golang/go/issues/51748
https://github.com/golang/go/issues/53640
https://github.com/golang/go/issues/54852
https://github.com/pre-commit/pre-commit/issues/2722

Based on that, I started looking further at the current GitHub Actions. I tweaked this and now there is a working set-up. See GitHub pull request #2761 containing a working build: https://github.com/cafferata/dnscontrol/actions/runs/7402715334/job/20141152040?pr=1

The additional commits compared to the previous GitHub pull request:

  1. ab78f8c CICD: GitHub Action: actions/checkout@v4 added fetch-depth: 0.
  2. 63a41d2 CICD: GitHub Action: goreleaser/goreleaser-action@v5 removed the default distribution value.
  3. e0efbc7 CICD: GitHub Action: goreleaser/goreleaser-action@v5 removed the default version value.
  4. 4c976f0 CICD: GitHub Action: actions/setup-go@v4 added Go set-up.

Explanation of the additional commits:

GoReleaser

Fetch depthness

Notice the fetch-depth: 0 option on the Checkout workflow step. It is required for GoReleaser to work properly. Without that, GoReleaser might fail or behave incorrectly.

https://goreleaser.com/ci/actions/#fetch-depthness

GitHub Action

Fetch all history for all tags and branches

- uses: actions/checkout@v4
  with:
    fetch-depth: 0

https://github.com/actions/checkout?tab=readme-ov-file#fetch-all-history-for-all-tags-and-branches

@cafferata cafferata changed the title CICD: GoReleaser version CICD: GoReleaser version - part 1 Jan 6, 2024
PJEilers pushed a commit to realtimeregister/dnscontrol that referenced this pull request Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants