Skip to content

Commit

Permalink
switch to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Mar 18, 2021
1 parent de5e428 commit b38d5a4
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 34 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Build

on: [push, pull_request]

env:
DOCKER_HUB_IMAGE_NAME: cenkalti/tcpproxy

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15

- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: go get -v -t -d ./...

- name: Build
run: go build -v ./...

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.30

- name: Test
run: go test -race -v -covermode atomic -coverprofile=covprofile ./...

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: covprofile

goreleaser:
name: Build and release binary
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.15
- uses: goreleaser/goreleaser-action@v2.2.0
with:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.github_token }}

push-docker:
name: Push image to Docker Hub
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2

- name: Prepare
id: prep
run: |
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="${DOCKER_HUB_IMAGE_NAME}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_HUB_IMAGE_NAME}:latest"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=date::$(date --utc +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.prep.outputs.tags }}
build-args: VERSION=${{ steps.prep.outputs.version }}
25 changes: 25 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
env:
- GO111MODULE=on
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
ldflags: -s -w -X github.com/cenkalti/tcpproxy.Version={{.Version}}
goos:
- linux
goarch:
- amd64
main: ./cmd/tcpproxy/main.go
archives:
- format: tar.gz
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}"
checksum:
name_template: 'checksums.txt'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM golang:1.15.6-alpine3.12 AS builder
WORKDIR /go/src/github.com/cenkalti/tcpproxy
COPY . .
RUN CGO_ENABLED=0 go build -o /go/bin/tcpproxy cmd/tcpproxy/main.go
ARG VERSION
RUN CGO_ENABLED=0 go build -o /go/bin/tcpproxy -ldflags="-s -w -X github.com/cenkalti/tcpproxy.Version=$VERSION" cmd/tcpproxy/main.go

FROM alpine:3.12
COPY --from=builder /go/bin/tcpproxy /usr/bin/tcpproxy
Expand Down

0 comments on commit b38d5a4

Please sign in to comment.