Skip to content

Commit

Permalink
Merge pull request #474 from pseudomuto/go_releaser
Browse files Browse the repository at this point in the history
Setting up goreleaser to handle releases
  • Loading branch information
pseudomuto committed Feb 18, 2022
2 parents 2dde019 + 84fae50 commit bc8d652
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 177 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ dist/
examples/
fixtures/
tmp/
!/script
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Tests
run: |
goverage -race -coverprofile=coverage.txt -covermode=atomic
make bench lint
make test/bench test/lint
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
25 changes: 0 additions & 25 deletions .github/workflows/dockerhub.yaml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: pseudomuto
password: ${{ secrets.DOCKER_TOKEN }}
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Release
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/_tools
/bin
/coverage.txt
/dist
/gen_fixtures
/protoc-gen-doc
/test/*.dat
/vendor
/tmp/
2 changes: 0 additions & 2 deletions .gofmtignore

This file was deleted.

48 changes: 48 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
project_name: protoc-gen-doc

before:
hooks:
- go mod tidy

builds:
- main: ./cmd/protoc-gen-doc
env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64

dockers:
- image_templates:
- pseudomuto/{{.ProjectName}}:latest
- pseudomuto/{{.ProjectName}}:{{.Version}}
- pseudomuto/{{.ProjectName}}:{{.Major}}
- pseudomuto/{{.ProjectName}}:{{.Major}}.{{.Minor}}
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/amd64"
extra_files:
- LICENSE.md
- README.md
- script/entrypoint.sh

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased](https://github.com/pseudomuto/protoc-gen-doc/compare/v1.5.0...master)

_**CHANGELOG is now available with each release rather than in this file**_

### Changed

* Escape special characters in markdown anchors [#460](https://github.com/pseudomuto/protoc-gen-doc/pull/460)
Expand Down
43 changes: 21 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ First off, glad you're here and want to contribute! :heart:
In order to work on this project, you'll need to install a few things:

1. A recent version of [Go](https://golang.org/doc/install)
1. [protoc](https://github.com/google/protobuf#protocol-compiler-installation) - The protobuf compiler
1. [Docker](https://www.docker.com/) (only required to if you need/want to build the docker container via `make docker`)
1. [Docker](https://www.docker.com/) (only required to use `make dev/docker`, `make test/docker`, or release targets).
1. [unzip](http://infozip.sourceforge.net/)

Once those are installed, running `make setup` should get you the rest of the way.
Everything else that's needed will be installed as needed and put in `./bin`.

When writing tests, be sure that the package in the test file is suffixed with `_test`. Eg. `protoc_gen_doc_test`. This
ensures that you'll only be testing the public interface.
Expand All @@ -19,13 +19,14 @@ ensures that you'll only be testing the public interface.

Here are some general guidelines for making PRs for this repo.

1. [Fork this repo](https://github.com/pseudomuto/protoc-gen-doc/fork)
1. Make a branch off of master (`git checkout -b <your_branch_name>`)
1. Make focused commits with descriptive messages
1. Add tests that fail without your code, and pass with it
1. GoFmt your code! (see <https://blog.golang.org/go-fmt-your-code> to setup your editor to do this for you)
1. Be sure to run `make examples` so your changes are reflected in the example docs
1. **Ping someone on the PR** (Lots of people, including myself, won't get a notification unless pinged directly)
1. [Fork this repo](https://github.com/pseudomuto/protoc-gen-doc/fork).
1. Make a branch off of master (`git checkout -b <your_branch_name>`).
1. Make focused commits with descriptive messages.
1. Add tests that fail without your code, and pass with it.
1. GoFmt your code! (see <https://blog.golang.org/go-fmt-your-code> to setup your editor to do this for you).
1. Be sure to run `make build/examples` so your changes are reflected in the example docs.
1. Running `make test/docker` should produce the same output as `make build/examples`.
1. **Ping someone on the PR** (Lots of people, including myself, won't get a notification unless pinged directly).

Every PR should have a well detailed summary of the changes being made and the reasoning behind them. Make sure to add
at least three sections.
Expand All @@ -47,10 +48,10 @@ How has this change been tested? In your opinion what is the risk, if any, of me
#### Reviewers should:

1. Identify anything that the PR author may have missed from above.
2. Test the PR through whatever means necessary, including manually, to verify it is safe to be deployed.
3. Question everything. Never assume that something was tested or fully understood, always question and ask if there is
1. Test the PR through whatever means necessary, including manually, to verify it is safe to be deployed.
1. Question everything. Never assume that something was tested or fully understood, always question and ask if there is
any uncertainty.
4. Before merging the PR make sure it has _**one**_ of the `Major release`, `Minor release`, or `Patch release` labels
1. Before merging the PR make sure it has _**one**_ of the `Major release`, `Minor release`, or `Patch release` labels
applied to it (useful for the changelog and determining the version for the next release).

## Release Process
Expand All @@ -66,14 +67,12 @@ Look through the new (since the last release) PRs that are included in this rele

### Now that we've got the version:

* Run `make docker_test` to build the image and generate the examples. There should be no diff after this.
* Update the version in `version.go`
* Update CHANGELOG.md. Be sure to include links to PRs and highlight new features, bug fixes, and any breaking changes.
* Run `make release`
From an up-to-date master, do the following:

Now that the tag is on GitHub, we have a couple more things to do:
1. Run `make test/docker` to build the image and generate the examples. There should be no diff after this.
1. Update the version in `version.go` appropriately.
1. `git commit -am "Bump to version v<version>`.
1. `git tag -s v<version>`.
1. `git push origin master --tags`.

* Create a release based on the tag and copy the entry in CHANGELOG.md into the notes.
* Run `make dist` and add the tar files (in `./dist`) to the release.

Once CI has run for the tag, Travis will push the image to DockerHub.
Once the tag is on GitHub, the release action will handle pushing to docker and creating a release in GitHub.
29 changes: 7 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
FROM golang:1.17-alpine AS builder
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o protoc-gen-doc ./cmd/protoc-gen-doc

FROM debian:bookworm-slim AS final
LABEL maintainer="pseudomuto <david.muto@gmail.com>" protoc_version="3.18.1"

FROM alpine:3.15.0
WORKDIR /

ADD https://github.com/google/protobuf/releases/download/v3.18.1/protoc-3.18.1-linux-x86_64.zip ./
RUN apt-get -q -y update && \
apt-get -q -y install unzip && \
unzip protoc-3.18.1-linux-x86_64.zip -d ./usr/local && \
rm protoc-3.18.1-linux-x86_64.zip && \
apt-get remove --purge -y unzip && \
apt-get autoremove && \
rm -rf /var/lib/apt/lists/*
RUN apk --update add bash protoc protobuf-dev && rm -rf /var/cache/apk/*

COPY --from=builder /build/protoc-gen-doc /usr/local/bin
COPY script/entrypoint.sh ./
COPY LICENSE.md README.md script/entrypoint.sh ./
COPY protoc-gen-doc /usr/bin/

VOLUME ["/out", "/protos"]
VOLUME ["/out"]
VOLUME ["/protos"]

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["./entrypoint.sh"]
CMD ["--doc_opt=html,index.html"]
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 David Muto (pseudomuto)
Copyright (c) 2022 David Muto (pseudomuto)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit bc8d652

Please sign in to comment.