Skip to content

Commit f0efe64

Browse files
authored
Merge pull request #7 from github/releasing
Add infrastructure for making releases
2 parents 368ed15 + 552fd71 commit f0efe64

File tree

5 files changed

+141
-30
lines changed

5 files changed

+141
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.gopath
22
/bin
3+
/releases

Makefile

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ export GOPATH
66
GO := $(CURDIR)/script/go
77
GOFMT := $(CURDIR)/script/gofmt
88

9-
GOFLAGS := \
10-
-ldflags "-X main.BuildVersion=$(shell git rev-parse HEAD) -X main.BuildDescribe=$(shell git describe --tags --always --dirty)"
9+
GO_LDFLAGS := -X main.BuildVersion=$(shell git rev-parse HEAD)
10+
GO_LDFLAGS += -X main.BuildDescribe=$(shell git describe --tags --always --dirty)
11+
GOFLAGS := -ldflags "$(GO_LDFLAGS)"
1112

1213
ifdef USE_ISATTY
1314
GOFLAGS := $(GOFLAGS) --tags isatty
1415
endif
1516

16-
GO_SRCS := $(shell cd $(GOPATH)/src/$(PACKAGE) && $(GO) list -f '{{$$ip := .ImportPath}}{{range .GoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}{{range .CgoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}{{range .TestGoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}{{range .XTestGoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}' ./...)
17+
GO_SRCS := $(sort $(shell cd $(GOPATH)/src/$(PACKAGE) && $(GO) list -f ' \
18+
{{$$ip := .ImportPath}} \
19+
{{range .GoFiles }}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
20+
{{range .CgoFiles }}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
21+
{{range .TestGoFiles }}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
22+
{{range .XTestGoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
23+
' ./...))
1724

1825
.PHONY: all
1926
all: bin/git-sizer
@@ -26,13 +33,15 @@ bin/git-sizer:
2633
# Cross-compile for a bunch of common platforms. Note that this
2734
# doesn't work with USE_ISATTY:
2835
.PHONY: common-platforms
29-
common-platforms: \
30-
bin/git-sizer-linux-amd64 \
31-
bin/git-sizer-linux-386 \
32-
bin/git-sizer-darwin-amd64 \
33-
bin/git-sizer-darwin-386 \
34-
bin/git-sizer-windows-amd64.exe \
35-
bin/git-sizer-windows-386.exe
36+
common-platforms:
37+
38+
# Create releases for a bunch of common platforms. Note that this
39+
# doesn't work with USE_ISATTY, and VERSION must be set on the command
40+
# line; e.g.,
41+
#
42+
# make releases VERSION=1.2.3
43+
.PHONY: releases
44+
releases:
3645

3746
# Define rules for a bunch of common platforms that are supported by go; see
3847
# https://golang.org/doc/install/source#environment
@@ -44,6 +53,20 @@ define PLATFORM_template =
4453
bin/git-sizer-$(1)-$(2)$(3):
4554
mkdir -p bin
4655
cd $$(GOPATH)/src/$$(PACKAGE) && GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -o $$(ROOTDIR)/$$@ $$(PACKAGE)
56+
common-platforms: bin/git-sizer-$(1)-$(2)$(3)
57+
58+
# Note that releases don't include code from vendor (they're only used
59+
# for testing), so no license info is needed from those projects.
60+
.PHONY: releases/git-sizer-$$(VERSION)-$(1)-$(2).zip
61+
releases/git-sizer-$$(VERSION)-$(1)-$(2).zip: bin/git-sizer-$(1)-$(2)$(3)
62+
if test -z "$$(VERSION)"; then echo "Please set VERSION to make releases"; exit 1; fi
63+
mkdir -p releases/tmp-$$(VERSION)-$(1)-$(2)
64+
cp README.md LICENSE.md releases/tmp-$$(VERSION)-$(1)-$(2)
65+
cp bin/git-sizer-$(1)-$(2)$(3) releases/tmp-$$(VERSION)-$(1)-$(2)/git-sizer$(3)
66+
rm -f $$@
67+
zip -j $$@ releases/tmp-$$(VERSION)-$(1)-$(2)/*
68+
rm -rf releases/tmp-$$(VERSION)-$(1)-$(2)
69+
releases: releases/git-sizer-$$(VERSION)-$(1)-$(2).zip
4770
endef
4871

4972
$(eval $(call PLATFORM_template,linux,amd64))
@@ -78,6 +101,7 @@ govet:
78101
clean:
79102
rm -rf bin
80103

104+
# List all of this project's Go sources, excluding vendor, within .gopath:
81105
.PHONY: srcs
82106
srcs:
83107
@printf "%s\n" $(GO_SRCS)

README.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,41 @@ Is your Git repository bursting at the seams?
6767

6868
## Getting started
6969

70-
1. [Install the Git command-line client](https://git-scm.com/) and put it in your `PATH`. (`git-sizer` invokes `git` commands to examine the contents of your repository.)
70+
1. Make sure that you have the [Git command-line client](https://git-scm.com/) installed. NOTE: `git-sizer` invokes `git` commands to examine the contents of your repository, so **it is required that the `git` command be in your `PATH`** when you run `git-sizer`.
7171

72-
2. Build:
72+
2. Install `git-sizer`. Either:
7373

74-
* On Linux or OS X:
74+
a. Install a released version of `git-sizer` (recommended):
7575

76-
script/bootstrap
77-
make
76+
* Go to [the releases page](https://github.com/github/git-sizer/releases) and download the ZIP file corresponding to your platform.
7877

79-
The executable file is written to `bin/git-sizer`. If you copy it to your `PATH`, you can run the program by typing `git sizer`; otherwise, you need to type the full path and filename to run it; e.g., `bin/git-sizer`.
78+
* Unzip the file.
8079

81-
* On other platforms: TBD
80+
* Move the executable file (`git-sizer` or `git-sizer.exe`) into your `PATH`.
8281

83-
3. Change to the directory containing the Git repository, then run
82+
b. Build and install from source. See the instructions in [`docs/BUILDING.md`](docs/BUILDING.md).
8483

85-
git sizer [<opt>...]
84+
3. Change to the directory containing the Git repository that you'd like to analyze, then run
8685

87-
To get a summary of the current repository, all you need is
86+
git sizer [<option>...]
8887

89-
git sizer
88+
No options are required. You can learn about available options by typing `git sizer -h` or by reading on.
9089

91-
Use the `--json` option to get output in JSON format, including the raw numbers.
90+
(The above command assumes that you have added `git-sizer` to your `PATH`. If you don't add it to your `PATH`, you need to type its full path and filename to run it; e.g., `/path/to/bin/git-sizer`.)
9291

9392

9493
## Usage
9594

96-
By default, `git-sizer` outputs its results in tabular format. For example, let's use it to check [the Linux repository](https://github.com/torvalds/linux), using the `--verbose` option to cause all statistics to be output:
95+
By default, `git-sizer` outputs its results in tabular format. For example, let's use it to analyze [the Linux repository](https://github.com/torvalds/linux), using the `--verbose` option so that all statistics are output:
9796

9897
```
9998
$ git-sizer --verbose
99+
Processing blobs: 1652370
100+
Processing trees: 3396199
101+
Processing commits: 722647
102+
Matching commits to trees: 722647
103+
Processing annotated tags: 534
104+
Processing references: 539
100105
| Name | Value | Level of concern |
101106
| ---------------------------- | --------- | ------------------------------ |
102107
| Overall repository size | | |
@@ -149,21 +154,19 @@ $ git-sizer --verbose
149154
[10] f29a5ea76884ac37e1197bef1941f62fda3f7b99 (f5308d1b83eba20e69df5e0926ba7257c8dd9074^{tree})
150155
```
151156

152-
`git-sizer` has to traverse all of the history, so the analysis can take a while.
153-
154-
The output is a table showing the thing that was measured, its numerical value, and a rough indication of which values might be a cause for concern.
157+
The output is a table showing the thing that was measured, its numerical value, and a rough indication of which values might be a cause for concern. In all cases, only objects that are reachable from references are included (i.e., not unreachable objects, nor objects that are reachable only from the reflogs).
155158

156159
The "Overall repository size" section includes repository-wide statistics about distinct objects, not including repetition. "Total size" is the sum of the sizes of the corresponding objects in their uncompressed form, measured in bytes.
157160

158161
The "Biggest objects" section provides information about the biggest single objects of each type, anywhere in the history.
159162

160163
In the "History structure" section, "maximum history depth" is the longest chain of commits in the history, and "maximum tag depth" reports the longest chain of annotated tags that point at other annotated tags.
161164

162-
The "Biggest checkouts" section is about the sizes of commits as checked out into a working copy. "Maximum path depth" is the largest number of path components within the repository, and "maximum path length" is the longest path in terms of bytes. "Total size of files" is the sum of all file sizes in the single biggest commit, including multiplicities if the same file appears multiple times.
165+
The "Biggest checkouts" section is about the sizes of commits as checked out into a working copy. "Maximum path depth" is the largest number of path components for files in the working copy, and "maximum path length" is the longest path in terms of bytes. "Total size of files" is the sum of all file sizes in the single biggest commit, including multiplicities if the same file appears multiple times.
163166

164167
The "Value" column displays counts, using units "k" (thousand), "M" (million), "G" (billion) etc., and sizes, using units "B" (bytes), "KiB" (1024 bytes), "MiB" (1024 KiB), etc. Note that if a value overflows its counter (which should only happen for malicious repositories), the corresponding value is displayed as `` in tabular form, or truncated to 2³²-1 or 2⁶⁴-1 (depending on the size of the counter) in JSON mode.
165168

166-
The "Level of concern" column uses asterisks to indicate values that seem high compared with "typical" Git repositories. The more asterisks, the more inconvenience this value might be expected to cause. Exclamation points indicate values that are extremely high (i.e., equivalent to more than 30 asterisks).
169+
The "Level of concern" column uses asterisks to indicate values that seem high compared with "typical" Git repositories. The more asterisks, the more inconvenience this aspect of your repository might be expected to cause. Exclamation points indicate values that are extremely high (i.e., equivalent to more than 30 asterisks).
167170

168171
The footnotes list the SHA-1s of the "biggest" objects referenced in the table, along with a more human-readable `<commit>:<path>` description of where that object is located in the repository's history. Given the name of a large object, you could, for example, type
169172

@@ -173,16 +176,19 @@ at the command line to view the contents of the object. (Use `--names=none` if y
173176

174177
By default, only statistics above a minimal level of concern are reported. Use `--verbose` (as above) to request that all statistics be output. Use `--threshold=<value>` to suppress the reporting of statistics below a specified level of concern. (`<value>` is interpreted as a numerical value corresponding to the number of asterisks.) Use `--critical` to report only statistics with a critical level of concern (equivalent to `--threshold=30`).
175178

179+
If you'd like the output in machine-readable format, including exact numbers, use the `--json` option.
180+
176181
To get a list of other options, run
177182

178-
git sizer --help
183+
git sizer -h
179184

180-
The Linux repository is large by most standards, and as you can see, it is pushing some of Git's limits. And indeed, some Git operations on the Linux repository (e.g., `git fsck`, `git gc`) take a while. But due to its sane structure, none of its dimensions are wildly out of proportion to the size of the code base, so it can be managed successfully using Git.
185+
The Linux repository is large by most standards. As you can see, it is pushing some of Git's limits. And indeed, some Git operations on the Linux repository (e.g., `git fsck`, `git gc`) do take a while. But due to its sane structure, none of its dimensions are wildly out of proportion to the size of the code base, so the kernel project is managed successfully using Git.
181186

182187
Here is the non-verbose output for one of the famous ["git bomb"](https://kate.io/blog/git-bomb/) repositories:
183188

184189
```
185190
$ git-sizer
191+
[...]
186192
| Name | Value | Level of concern |
187193
| ---------------------------- | --------- | ------------------------------ |
188194
| Biggest checkouts | | |

docs/BUILDING.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Building `git-sizer` from source
2+
3+
Most people can just install a released version of `git-sizer`, [as described in the `README.md`](../README.md#getting-started). However, if you want to test a non-release version, or if you might want to contribute to `git-sizer`, you can also build it from source.
4+
5+
6+
## Build and install using `go get`
7+
8+
1. Make sure that you have a recent version of the [Go language toolchain](https://golang.org/doc/install) installed and that you have set `GOPATH`.
9+
10+
2. Get `git-sizer` using `go get`:
11+
12+
go get github.com/github/git-sizer
13+
14+
This should fetch and compile the source code and write the executable file to `$GOPATH/bin/`.
15+
16+
3. Either add `$GOPATH/bin` to your `PATH`, or copy the executable file (`git-sizer` or `git-sizer.exe`) to a directory that is already in your `PATH`.
17+
18+
19+
## Build using `make`
20+
21+
This procedure is intended for experts and people who want to help develop `git-sizer`. It should work on Linux or OS X. On other Unix-like systems, this procedure is also likely to work, provided you first [install Go manually](https://golang.org/doc/install).
22+
23+
1. Clone the `git-sizer` Git repository and switch to that directory:
24+
25+
git clone https://github.com/github/git-sizer.git
26+
cd git-sizer
27+
28+
2. Install Go if necessary and create and prepare a project-local `GOPATH`:
29+
30+
script/bootstrap
31+
32+
3. (Optional) Run the automated tests:
33+
34+
make test
35+
36+
4. Build `git-sizer`:
37+
38+
make
39+
40+
If you have a C toolchain set up, you can enable support for `isatty()` (which turns off `--progress` by default if output is not to a TTY) by running
41+
42+
make USE_ISATTY=true
43+
44+
5. Copy the resulting executable file (`bin/git-sizer`) to a directory in your `PATH`.
45+
46+
It is also possible to cross-compile for other platforms that are supported by Go. See the comments in the `Makefile` for more information.
47+
48+
Note that this procedure uses a project-local `GOPATH`. This means that you can clone the repository anywhere. The disadvantage is that Go tools need to know about this `GOPATH`. The `Makefile` and the scripts under `scripts/` take care of this automatically. But if you want to run `go` commands by hand, either first set your `GOPATH`:
49+
50+
export GOPATH="$(pwd)/.gopath"
51+
52+
Or use `script/go` and `script/gofmt` rather than `go` and `gofmt`, respectively.
53+
54+
Unfortunately, some Go tools get confused by the symlink that is used to make the project-local `GOPATH` work. If you have this problem, it sometimes helps to run such commands from `.gopath/src/github.com/github/git-sizer/`. Alternatively, clone the project into the traditional place in your normal `GOPATH`.
55+
56+
57+
## Making a release
58+
59+
See [`RELEASING.md`](RELEASING.md).

docs/RELEASING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Creating releases of `git-sizer`
2+
3+
1. Create a release tag and push it to GitHub:
4+
5+
VERSION=1.2.3
6+
git tag -a v$VERSION
7+
git push origin v$VERSION
8+
9+
2. Build the release for the major platforms:
10+
11+
make releases VERSION=$VERSION
12+
13+
The output is a bunch of ZIP files written to directory `releases/`.
14+
15+
3. Go to the [releases page](https://github.com/github/git-sizer/releases).
16+
17+
4. Click on "Draft a new release".
18+
19+
5. Select the tag, add the required information, and upload the zip files.
20+
21+
6. Click "Publish release".

0 commit comments

Comments
 (0)