Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with playbooks: install-go-tools, gotestsum, and dynamic versions #192

Merged
merged 10 commits into from
Jan 23, 2024

Conversation

lieut-data
Copy link
Member

@lieut-data lieut-data commented Dec 12, 2023

Summary

This brings into the starter-template a handful of changes originally introduced with Playbooks:

  • an automatic install-go-tools target that manages a local, versioned copy of any go installed tools needed
  • adoption of gotestsum for improved go testing semantics
  • reverting the embedding of plugin.json, restoring make apply, and shifting to a dynamically generated version number based on the nearest tag.

This last point is easier explained by linking to the original PR: mattermost/mattermost-plugin-playbooks#433, but I note that the reason I reverted embedding plugin.json is that this root file is no longer the final source of truth: rather, it's a (big) input into the final manifest that includes the dynamically generated version. Open to different approaches, but either way we don't have to care about checking in the generated manifests: they remain generated and .gitignored.

In this repository, since we have yet to tag a version, any build will result in v0.0.0+<commit hash>. Any build on a tagged version will be vX.Y.Z exactly. And any downstream commit from there would be vX.Y.Z+<short hash> until we tag a new version.

Ticket Link

None.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (376ea7e) 5.26% compared to head (0ac4026) 5.26%.

Additional details and impacted files
@@          Coverage Diff           @@
##           master    #192   +/-   ##
======================================
  Coverage    5.26%   5.26%           
======================================
  Files           3       3           
  Lines          38      38           
======================================
  Hits            2       2           
  Misses         36      36           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cpoile cpoile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good way to do it, nice!

build/manifest/main.go Outdated Show resolved Hide resolved
Comment on lines 114 to 137
// Update the manifest based on the state of the current commit
// Use the first version we find (to prevent causing errors)
var version string
tags := strings.Fields(BuildTagCurrent)
for _, t := range tags {
if strings.HasPrefix(t, "v") {
version = t
break
}
}
if version == "" {
if BuildTagLatest != "" {
version = BuildTagLatest + "+" + BuildHashShort
} else {
version = "v0.0.0+" + BuildHashShort
}
}
manifest.Version = strings.TrimPrefix(version, "v")

// Update the release notes url to point at the latest tag, if present.
if BuildTagLatest != "" {
manifest.ReleaseNotesURL = manifest.HomepageURL + "releases/tag/" + BuildTagLatest
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

If I understand correctly:

  • if the current commit matches a tag, then we use that
  • If not, use the latest tag and append the latest commit hash
  • If no tag available, use v0.0.0 and append the latest commit hash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com>
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the starter template 🚀

Comment on lines +51 to +55
## Install go tools
install-go-tools:
@echo Installing go tools
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
$(GO) install gotest.tools/gotestsum@v1.7.0
Copy link
Contributor

@hanzei hanzei Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that plugin now own the version of golangci-lint.

## Install go tools
install-go-tools:
@echo Installing go tools
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the impact of this change on CI? AFAIK it also installs a version of golangci-lint. Can we drop that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below: uncertain how to roll out these changes to CI without breaking everything. For now, this at least gives the developer a reliable definition of the version in play. Thoughts?

## Runs any lints and unit tests defined for the server and webapp, if they exist, optimized
## for a CI environment.
.PHONY: test-ci
test-ci: apply webapp/node_modules install-go-tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a follow up ticket to actually use the target in CI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at the moment, but I'm a bit blurry on how to achieve that -- it looks like we import @main, which would make whatever changes we add there affect all plugins at the same time, vs. plugins opting in to updated CI incrementally. Not sure how to crack this nut: thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's time to move to hand-picked CI versions. We have been bitten by the auto-update of @main way too often. Espcecially, updates to golangci-lint caused issues in the past.

cc @mickmister

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mickmister Would you be open to owning that change? Brightscout could surely help with executing it.

build/setup.mk Outdated Show resolved Hide resolved
build/manifest/main.go Outdated Show resolved Hide resolved
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few open discussion points, but nothing blocking

build/manifest/main.go Show resolved Hide resolved
## Install go tools
install-go-tools:
@echo Installing go tools
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to install the binary? Or is

Suggested change
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1

enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that would be convenient! But unfortunately much slower it seems?

CleanShot 2024-01-23 at 09 47 36@2x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the added duration comes from checking the remote go modules DB. The increase is similar running go install.

One downside of go run is, that it errors if the machine is offline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right: I wasn't comparing apples to apples as I thought!

## Runs any lints and unit tests defined for the server and webapp, if they exist, optimized
## for a CI environment.
.PHONY: test-ci
test-ci: apply webapp/node_modules install-go-tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's time to move to hand-picked CI versions. We have been bitten by the auto-update of @main way too often. Espcecially, updates to golangci-lint caused issues in the past.

cc @mickmister

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants