Skip to content

Commit

Permalink
feat: golang binary ci
Browse files Browse the repository at this point in the history
  • Loading branch information
heliannuuthus authored Oct 29, 2023
1 parent 81bbd60 commit c02324d
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/call-call-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/call-containerize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:
default: "./"
type: "string"
description: "Specify all of steps where are run"
target:
required: false
default: "./build"
type: "string"
description: "Specify build base target dir"

permissions:
contents: read
Expand All @@ -25,14 +30,14 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: download target
uses: actions/download-artifact@v3
with:
name: target
path: |
${{ inputs.workdir }}/target/release
${{ inputs.target }}
- run: tree .

Expand All @@ -48,8 +53,8 @@ jobs:
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,enable=${{ github.ref == format('refs/heads/{0}', 'master') }},pattern={{version}}-${{ steps.environments.outputs.timestamp }}rc-${{ steps.environments.outputs.short_sha }},value=${{ inputs.version }}
type=semver,enable=${{ github.ref != format('refs/heads/{0}', 'master') }},pattern={{version}}-${{ steps.environments.outputs.timestamp }}alpha-${{ steps.environments.outputs.short_sha }},value=${{ inputs.version }}
type=semver,enable=${{ github.ref == format('refs/heads/{0}', 'master') }},pattern={{version}}-${{ steps.environments.outputs.timestamp }}rc-${{ steps.environments.outputs.short_sha }},value=${{ inputs.version || 'v0.0.1' }}
type=semver,enable=${{ github.ref != format('refs/heads/{0}', 'master') }},pattern={{version}}-${{ steps.environments.outputs.timestamp }}alpha-${{ steps.environments.outputs.short_sha }},value=${{ inputs.version || 'v0.0.1' }}
- name: authenticate
uses: docker/login-action@v2
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/call-golang-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
on:
workflow_call:
inputs:
workdir:
required: false
default: "./"
type: "string"
description: "Specify all of steps where are run"
GOOS:
required: false
default: "linux"
type: "string"
description: "GOOS target os"
GOARCH:
required: true
type: "string"
description: "GOARCH arch"
ENTRANCE:
required: false
default: "main.go"
type: string
description: "main.go relative path"

outputs:
version:
description: "Rust application version"
value: ${{ jobs.build.outputs.version }}

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: test
run: go test ./... -v -cover -coverprofile=coverage.out && go tool cover -html=coverage.out -o coverage.html
- name: build binary
run: |
echo "$GOOS"
echo "$GOARCH"
mkdir build
CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -a -o build/${{ github.repository }} ${{ inputs.ENTRANCE }}
- id: environments
name: environments
run: |
echo "
project=${{ github.repository }}
version=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)
" >> "$GITHUB_OUTPUT"
- name: upload target
uses: actions/upload-artifact@v3
with:
name: target
path: |
${{ inputs.workdir }}build/${{ steps.environments.outputs.project }}
74 changes: 74 additions & 0 deletions .github/workflows/call-golang-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
on:
workflow_call:
inputs:
workdir:
required: false
default: "./"
type: "string"
description: "Specify all of steps where are run"

jobs:
setup:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: build dependencies
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.1
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.18.2
golangci-lint version
- name: cache dependencies cache
id: heliannuuthus-cargo-cache
uses: actions/cache/save@v3
with:
path: |
~/go
key: ${{ runner.os }}-heliannuuthus-golang-cache

lint:
needs: setup
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: cache registry cache
id: heliannuuthus-golang-cache
uses: actions/cache/restore@v3
with:
path: |
~/go
key: ${{ runner.os }}-heliannuuthus-golang-cache
- name: golangci-lint
run: go version && tree $(go env GOPATH)/bin && golangci-lint -vv

security:
needs: setup
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: cache registry cache
id: heliannuuthus-golang-cache
uses: actions/cache/restore@v3
with:
path: |
~/go
key: ${{ runner.os }}-heliannuuthus-golang-cache
- name: gosec checkout
run: go version && tree $(go env GOPATH)/bin && gosec -fmt=sarif -out=gosec.sarif ./...
2 changes: 1 addition & 1 deletion .github/workflows/call-java-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/call-rust-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
outputs:
version: ${{ steps.environments.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: download registry
uses: actions/download-artifact@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/call-rust-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: setup
run: |
rustup default ${{ inputs.toolchain }}
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: cache registry cache
id: heliannuuthus-cargo-cache
uses: actions/cache/restore@v3
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: cache registry cache
id: heliannuuthus-cargo-cache
uses: actions/cache/restore@v3
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/golang-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
lint:
uses: ./.github/workflows/call-golang-lint.yml
with:
workdir: "tests/golang/"


build:
uses: ./.github/workflows/call-golang-build.yml
with:
workdir: "tests/golang/"
GOOS: linux
GOARCH: amd64
ENTRANCE: cmd/main.go


containeraized:
needs: build
permissions:
contents: read
packages: write
uses: ./.github/workflows/call-containerize.yml
with:
version: ${{ needs.build.outputs.version }}
workdir: "tests/golang/"
target: "tests/golang/build"
3 changes: 2 additions & 1 deletion .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ jobs:
uses: ./.github/workflows/call-containerize.yml
with:
version: ${{ needs.build.outputs.version }}
workdir: "tests/rust/"
workdir: "tests/rust/"
target: "tests/rust/target/release"
117 changes: 117 additions & 0 deletions tests/golang/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
run:
# The default concurrency value is the number of available CPU.
concurrency: 4
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m
# Exit code when at least one issue was found.
# Default: 1
issues-exit-code: 2
go: '1.20'
output:
path-prefix: ""
linters:
# Disable all linters.
# Default: false
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exhaustruct
- exportloopref
- forbidigo
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- ireturn
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- sloglint
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- wrapcheck
- wsl
- zerologlint
fast: true
7 changes: 7 additions & 0 deletions tests/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM rust:latest

WORKDIR /

COPY build/workflow .

CMD ["./workflow"]
Loading

0 comments on commit c02324d

Please sign in to comment.