Skip to content

Commit

Permalink
chore: fix pipeline, add codeql, add goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
robotomize committed May 19, 2021
1 parent 4b6b799 commit fe12816
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 50 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'CodeQL'

on:
schedule:
- cron: '0 0 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: ['go']

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
95 changes: 52 additions & 43 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- '.github/workflows/**'
- 'cmd/**'
- 'internal/**'
- 'tools/**'
- 'docker-init.sh'
- 'Dockerfile'

jobs:
regular_build:
test:
runs-on: ubuntu-latest

steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
access_token: ${{ github.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
Expand All @@ -17,53 +31,48 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: go build ./cmd/sod-srv

- name: Test
run: go test -v ./...

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
- uses: actions/cache@v2
with:
version: latest
args: release --config .goreleaser.yml --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: Upload assets
uses: actions/upload-artifact@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Unit tests
run: go test -count=1 -race -timeout=10m ./... -coverprofile=coverage.out
lint:
runs-on: ubuntu-latest
steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
name: sod-srv
path: dist/*
access_token: ${{ github.token }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build and push
uses: docker/build-push-action@v2
- uses: actions/cache@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
robotomize/sod:latest
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: Send a message to Telegram
uses: robotomize/notify-telegram@v0.2.4
- name: go-lint
uses: golangci/golangci-lint-action@v2
with:
chat: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
status: ${{ job.status }}
message: "SOD build complete"
version: 'v1.40.1'
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true
191 changes: 191 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: SOD
on:
push:
tags:
- 'v*.*.*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
access_token: ${{ github.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: Unit tests
run: go test -count=1 -race -timeout=10m ./... -coverprofile=coverage.out
lint:
runs-on: ubuntu-latest
steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
access_token: ${{ github.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: go-lint
uses: golangci/golangci-lint-action@v2
with:
version: 'v1.40.1'
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true

build-verify:
needs: [ lint, test ]
runs-on: ubuntu-latest

steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
access_token: ${{ github.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: Build
run: go build ./cmd/sod-srv

build-binary:
needs: build-verify
runs-on: ubuntu-latest

steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
access_token: ${{ github.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --config .goreleaser.yml --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload assets
uses: actions/upload-artifact@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: sod
path: dist/*

docker-push:
needs: build-verify
runs-on: ubuntu-latest

steps:
- name: Cancel previous builds
uses: styfle/cancel-workflow-action@0.7.0
with:
access_token: ${{ github.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
${{ runner.os }}-go-
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- 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:
context: .
file: ./Dockerfile
push: true
tags: |
robotomize/sod:latest
50 changes: 50 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
before:
hooks:
- go mod download
- go generate ./...
builds:
- id: sod
main: ./cmd/sod-srv
binary: sod
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- freebsd
- linux
- windows
- darwin
ldflags:
- -s -w -X main.version={{.Version}} -extldflags '-static'
archives:
- id: sod
builds:
- sod
name_template: "sod_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
replacements:
darwin: MacOSX
linux: Linux
windows: Windows
amd64: x86_64

nfpms:
- vendor: sod
homepage: https://github.com/go-sod/sod
maintainer: Nikita Ivanov
description: Recognition of anomalies in the data stream in real time. Identify peaks. Fraud detection.
license: MIT
formats: [ deb, rpm ]
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
release:
github:
owner: go-sod
name: sod
Loading

0 comments on commit fe12816

Please sign in to comment.