docopt / docopts

Shell interpreter for docopt, the command-line interface description language.
Other
494 stars 53 forks source link

build: replace `deploy.sh` with `goreleaser` #65

Open agilgur5 opened 1 year ago

agilgur5 commented 1 year ago

Summary

  1. Replace bespoke deploy.sh script with the goreleaser library

  2. Replace outdated custom dependency management with standard, built-in Go modules

Details

Less hackiness and custom / bespoke scripts now! 🙂

agilgur5 commented 1 year ago

So I'm training myself with github review. So you also received individual comment on this review. 😉

No worries, you seemed to have figured out how to use GH reviews already! 🙂

You did an amazing conversion work on my hacky code! 👍

Thank you! It took a bit of effort but seemed well worth it! 😄

goreleaser seems to have takeover all I was doing by external tool at the time I did start this project.

Yea and it's got lots of other features too -- like it can generate .deb packages for #22, Brew formulae, etc etc etc. I haven't used all of the features yet either.

So lets move forward.

I responded in-line to your comments / questions; let me know what changes you'd like to see from there.

At the very least, I'll have to update the pre-built-binaries.md doc with the new process using goreleaser and Go modules before this can be merged, as I didn't notice that file before.

Sylvain303 commented 1 year ago

:laughing: from CI:

/bin/sh: 1: goreleaser: not found

Wheel and circle!

Sylvain303 commented 1 year ago

Hello, I will be in vacation for a week. So I will pause my brain, including Opensource Software. :wink:

You wont see any more input from me until September 5th. Read you later.

agilgur5 commented 1 year ago

😆 from CI:

/bin/sh: 1: goreleaser: not found

I fixed that! I wrote this PR and #62 simultaneously, so that was a bit of a "merge conflict" of sorts as I wasn't able to use Go 1.17 until a go.mod / go.sum existed. CI passes now 🙂

agilgur5 commented 1 year ago

Added release notes generation now, so I think that addresses all remaining review comments.

agilgur5 commented 1 year ago

@Sylvain303 do you think you'll be ready to merge this soon?

If not, I might split up the Go modules piece into a separate PR to be merged first (and leave this as just goreleaser stuff), as it's currently blocking https://github.com/docopt/docopts/issues/59#issuecomment-1229483738 . That one would be much simpler; then you can take your time with this one as it wouldn't be blocking anything (for now).

I also made a few other tiny, mostly docs PRs 2 weeks ago in case you hadn't seen those.

Sylvain303 commented 1 year ago

Global note of the PR (may be more easy to search for, let's try)

For me to validate this PR

VERSION vs goreleaser main.Version={{.Version}}

Our discussion here: https://github.com/docopt/docopts/pull/65#discussion_r954477423

release notes

According to https://goreleaser.com/customization/release/#custom-release-notes it can be a markdown file.

tools.go

according to cmd/go: clarify best practice for tool dependencies there's some behavior to keep in mind here.

go build only vs make

our conversation https://github.com/docopt/docopts/pull/65#discussion_r966675312

Sylvain303 commented 1 year ago

@agilgur5

do you think you'll be ready to merge this soon?

I made a comment on the PR roadmap steps in my comment above.

Unfortunately, I'm near, or already, at burnout. I'm brain behaving like a colander image

Leaving some information out from the previous day. And progressing in mud disorganized fashion. So I may stop again from being active to rest. :sleeping: :worried:

I will progress on my decision today. Let's see how I organize myself...

I'm lost in PR too, obviously :wink:

I'm waking up and coding, for fun, as usual, let's see that Makefile target with my colander. :yum:

Sylvain303 commented 1 year ago

So, I'm in a resting phase no more than 2h of computer per day. I did my day.

extract ldflags only à la govvv? (#3371)

Sylvain303 commented 1 year ago

Hello @agilgur5

I'm trying to work 1h on the PR. I can't push my changes to your PR branch:

sylvain@lap43: ~/code/go/src/github.com/docopt/docopts$ git push agilgur5 build-with-goreleaser 
To github.com:agilgur5/docopts.git
 ! [rejected]        build-with-goreleaser -> build-with-goreleaser (non-fast-forward)
error: failed to push some refs to 'github.com:agilgur5/docopts.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

May some rebase did happen related to parallel PR on CI or something I don't know.

I add a local branch based on you changes named agilgur5-build-with-goreleaser

I made a new one from your branching history:

git switch master 
git checkout -b 2agilgur5-build-with-goreleaser 94799c5c834be4bd1e96723f3c269604e4c417ae 
git pull agilgur5 build-with-goreleaser 

I really dislike the bloated module thing introduced by goreleaser dependency as from being part of tools.go I think:

tooks > 1m to build because of the go mod tidy or something the builder think he has to download the world for building :thinking: quite strange I already downloaded plenty of time the 133 dependencies of goreleaser

sylvain@lap43: ~/code/go/src/github.com/docopt/docopts$ make clean 
# remove goreleaser dist/ difrectrory recursively
rm -rf dist
rm -f docopts-* docopts README.tmp
sylvain@lap43: ~/code/go/src/github.com/docopt/docopts$ make
GOVERSION=$(go version) goreleaser build --rm-dist --snapshot --single-target -o docopts
  • starting build...
  • loading config file                              file=.goreleaser.yaml
  • building only for linux/amd64                    reason=single target is enabled
  • loading environment variables
  • getting and validating git state
    • ignoring errors because this is a snapshot     error=couldn't get remote URL: fatal: No remote configured to list refs from.
    • building...                                    commit=none latest tag=v0.0.0
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • running before hooks
    • running                                        hook=go mod tidy
    • took: 1m21s
  • snapshotting
    • building snapshot...                           version=0.0.1-next
  • checking distribution directory
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/docopts_linux_amd64_v1/docopts
  • storing release metadata
    • writing                                        file=dist/artifacts.json
    • writing                                        file=dist/metadata.json
  • copying binary to "docopts"
  • build succeeded after 1m21s

I think we missed some step here about tooling and goreleaser invasive behavior on the module side.

I was looking a the make default target and CHANGELOG.md new feature in the Makefile, but the git glitch took all my time. :disappointed:

I still can't push :disappointed:

sylvain@lap43: ~/code/go/src/github.com/docopt/docopts$ git pull agilgur5 build-with-goreleaser 
From github.com:agilgur5/docopts
 * branch            build-with-goreleaser -> FETCH_HEAD
Current branch 2agilgur5-build-with-goreleaser is up to date.
sylvain@lap43: ~/code/go/src/github.com/docopt/docopts$ git push agilgur5 build-with-goreleaser 
To github.com:agilgur5/docopts.git
 ! [rejected]        build-with-goreleaser -> build-with-goreleaser (non-fast-forward)
error: failed to push some refs to 'github.com:agilgur5/docopts.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

My changes:

diff --git a/Makefile b/Makefile
index 8cacfec..fa9240e 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,8 @@ RELEASE_NOTES := $$(awk -v RS='\#\# *|\#\# ' 'NR==2 { print }' CHANGELOG.md)

 # keep docopts: as first target for development

-docopts: docopts.go Makefile
-   go build -o $@
+docopts: docopts.go Makefile VERSION
+   GOVERSION=$(GOVERSION) goreleaser build --single-target --rm-dist --snapshot -o $@

 install_builddep:
    go mod tidy
@@ -34,7 +34,9 @@ README.md: examples/legacy_bash/rock_hello_world.sh examples/legacy_bash/rock_he
    mv README.tmp README.md

 clean:
-   rm -f docopts-* docopts README.tmp dist/*
+   # remove goreleaser dist/ difrectrory recursively
+   rm -rf dist
+   rm -f docopts-* docopts README.tmp

 test_release_notes:
    echo "\n## $(RELEASE_NOTES)"
diff --git a/go.mod b/go.mod
index f096bb9..c6acfc7 100644
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.17

 require (
    github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
+   github.com/gookit/color v1.5.2
    github.com/goreleaser/goreleaser v1.10.3
 )

@@ -120,6 +121,7 @@ require (
    github.com/ulikunitz/xz v0.5.10 // indirect
    github.com/xanzy/go-gitlab v0.68.2 // indirect
    github.com/xanzy/ssh-agent v0.3.1 // indirect
+   github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
    go.opencensus.io v0.23.0 // indirect
    gocloud.dev v0.24.0 // indirect
    golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
diff --git a/go.sum b/go.sum
index df532e0..42058be 100644
--- a/go.sum
+++ b/go.sum
@@ -424,6 +424,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
 github.com/googleapis/gax-go/v2 v2.1.0 h1:6DWmvNpomjL1+3liNSZbVns3zsYzzCjm6pRBO1tLeso=
 github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0=
+github.com/gookit/color v1.5.2 h1:uLnfXcaFjlrDnQDT+NCBcfhrXqYTx/rcCa6xn01Y8yI=
+github.com/gookit/color v1.5.2/go.mod h1:w8h4bGiHeeBpvQVePTutdbERIUf3oJE5lZ8HM0UgXyg=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
 github.com/goreleaser/chglog v0.1.2 h1:tdzAb/ILeMnphzI9zQ7Nkq+T8R9qyXli8GydD8plFRY=
 github.com/goreleaser/chglog v0.1.2/go.mod h1:tTZsFuSZK4epDXfjMkxzcGbrIOXprf0JFp47BjIr3B8=
@@ -682,6 +684,8 @@ github.com/xanzy/ssh-agent v0.3.1/go.mod h1:QIE4lCeL7nkC25x+yA3LBIYfwCc1TFziCtG7
 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
+github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
+github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
 github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

I will see later.

The goal was to share my progress on the Makefile default target (requires goreleaser v1.11.3+)

To be continued.