Skip to content

Commit 51e4317

Browse files
ccojocarCosmin Cojocar
authored andcommitted
Automate the release process using a GitHub workflow
The release will trigger when a new tag is pushed. Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent 341059e commit 51e4317

File tree

6 files changed

+55
-33
lines changed

6 files changed

+55
-33
lines changed

.github/workflows/main.yml renamed to .github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: GoSec CI
1+
name: CI
22
on:
33
push:
44
branches:

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
env:
10+
GO111MODULE: on
11+
steps:
12+
- name: Checkout Source
13+
uses: actions/checkout@v2
14+
- name: Unshallow
15+
run: git fetch --prune --unshallow
16+
- name: Set up Go
17+
uses: actions/setup-go@v1
18+
with:
19+
go-version: 1.14.x
20+
- name : Get release version
21+
id: get_version
22+
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
23+
- name: Release Binaries
24+
uses: goreleaser/goreleaser-action@v1
25+
with:
26+
version: latest
27+
args: release --rm-dist
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Release Docker Image
31+
uses: elgohr/Publish-Docker-Github-Action@master
32+
with:
33+
name: securego/gosec
34+
username: ${{ secrets.DOCKER_USERNAME }}
35+
password: ${{ secrets.DOCKER_PASSWORD }}
36+
buildargs: GO_VERSION=1.14
37+
tags: "latest,${{ env.RELEASE_VERSION }}"
38+
tag_names: true

.goreleaser.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,3 @@ builds:
1818
ldflags: -X main.Version={{.Version}} -X main.GitTag={{.Tag}} -X main.BuildDate={{.Date}}
1919
env:
2020
- CGO_ENABLED=0
21-
22-
archive:
23-
files:
24-
- README.md
25-
- LICENSE.txt

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG GO_VERSION=1.13
1+
ARG GO_VERSION
22
FROM golang:${GO_VERSION}-alpine AS builder
33
RUN apk add --update --no-cache ca-certificates make git curl gcc libc-dev
44
RUN mkdir -p /build

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ GOBIN ?= $(GOPATH)/bin
1111
GOLINT ?= $(GOBIN)/golint
1212
GOSEC ?= $(GOBIN)/gosec
1313
GINKGO ?= $(GOBIN)/ginkgo
14+
GO_VERSION = 1.14
1415

1516
default:
1617
$(MAKE) build
@@ -58,7 +59,7 @@ build-linux:
5859

5960
image:
6061
@echo "Building the Docker image..."
61-
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) .
62+
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) --build-arg GO_VERSION=$(GO_VERSION) .
6263
docker tag $(IMAGE_REPO)/$(BIN):$(GIT_TAG) $(IMAGE_REPO)/$(BIN):latest
6364
touch image
6465

README.md

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ gosec -tag debug,ignore ./...
240240

241241
### Output formats
242242

243-
gosec currently supports text, json, yaml, csv, sonarqube, JUnit XML and golint output formats. By default
243+
gosec currently supports `text`, `json`, `yaml`, `csv`, `sonarqube`, `JUnit XML`, `html` and `golint` output formats. By default
244244
results will be reported to stdout, but can also be written to an output
245-
file. The output format is controlled by the '-fmt' flag, and the output file is controlled by the '-out' flag as follows:
245+
file. The output format is controlled by the `-fmt` flag, and the output file is controlled by the `-out` flag as follows:
246246

247247
```bash
248248
# Write output in json format to results.json
@@ -253,51 +253,39 @@ $ gosec -fmt=json -out=results.json *.go
253253

254254
### Build
255255

256+
You can build the binary with:
256257
```bash
257258
make
258259
```
259260

260261
### Tests
261262

263+
You can run all unit tests using:
262264
```bash
263265
make test
264266
```
265267

266-
### Release Build
268+
### Release
267269

268-
Make sure you have installed the [goreleaser](https://github.com/goreleaser/goreleaser) tool and then you can release gosec as follows:
270+
You can create a release by tagging the version as follows:
269271

270-
```bash
271-
git tag v1.0.0
272-
export GITHUB_TOKEN=<YOUR GITHUB TOKEN>
273-
make release
274-
```
275-
276-
The released version of the tool is available in the `dist` folder. The build information should be displayed in the usage text.
277-
278-
```bash
279-
./dist/darwin_amd64/gosec -h
280-
gosec - Golang security checker
281-
282-
gosec analyzes Go source code to look for common programming mistakes that
283-
284-
285-
VERSION: 1.0.0
286-
GIT TAG: v1.0.0
287-
BUILD DATE: 2018-04-27T12:41:38Z
272+
``` bash
273+
git tag v1.0.0 -m "Release version v1.0.0"
274+
git push origin v1.0.0
288275
```
289276

290-
Note that all released archives are also uploaded to GitHub.
277+
The GitHub [release workflow](.github/workflows/release.yml) triggers immediately after the tag is pushed upstream. This flow will
278+
release the binaries using the [goreleaser](https://goreleaser.com/actions/) action and then it will build and publish the docker image into Docker Hub.
291279

292280
### Docker image
293281

294-
You can build the docker image as follows:
282+
You can also build locally the docker image by using the command:
295283

296284
```bash
297285
make image
298286
```
299287

300-
You can run the `gosec` tool in a container against your local Go project. You just have to mount the project
288+
You can run the `gosec` tool in a container against your local Go project. You only have to mount the project
301289
into a volume as follows:
302290

303291
```bash

0 commit comments

Comments
 (0)