Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
tangbo committed Apr 2, 2024
1 parent 5e67d5c commit ba80cee
Show file tree
Hide file tree
Showing 23 changed files with 2,142 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/tmp/call-containerize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
on:
workflow_call:
inputs:
version:
required: true
type: "string"
description: "Container basic version"
workdir:
required: false
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
packages: write

jobs:
containerized:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

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

- id: environments
name: environments
run: |
echo "timestamp=$(date +%Y%m%d | cut -c 3-8)" >> "$GITHUB_OUTPUT"
echo "short_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- id: meta
name: container meta
uses: docker/metadata-action@v5
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 || '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@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: push github
uses: docker/build-push-action@v5
with:
context: ${{ inputs.workdir }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
144 changes: 144 additions & 0 deletions .github/tmp/call-golang-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
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: false
default: "amd64"
type: "string"
description: "GOARCH arch"
ENTRANCE:
required: false
default: "main.go"
type: string
description: "main.go relative path"

secrets:
SONAR_HOST_URL:
required: false
description: "sonar-scanner -Dsonar.token"
SONAR_TOKEN:
required: false
description: "sonar-scanner -Dsonar.token"

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

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
outputs:
version: ${{ steps.environments.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version: "1.20"
cache: false

- name: restore golang cache
uses: actions/cache/restore@v4
id: cache-restore-golang
env:
cache-name: cache-gomod
with:
path: |
~/go
key: ${{ runner.os }}-golang-store-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-store-${{ env.cache-name }}-
- id: sonar-restore-cache
name: restore sonar cache
uses: actions/cache@v4
with:
path: |
~/sonar-scanner
~/.sonar
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: setup-sonar
if: ${{ steps.sonar-restore-cache.outputs.cache-hit != 'true' }}
run: |
mkdir -p ~/sonar-scanner/.sonar
curl -L -o sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
unzip -q -o sonar-scanner.zip -d ~/
mv ~/sonar-scanner-5.0.1.3006-linux/* ~/sonar-scanner
rm -r ~/sonar-scanner-5.0.1.3006-linux
shell: bash

- name: download gosec report
uses: actions/download-artifact@v4
with:
name: gosec-report
path: |
${{ inputs.workdir }}build/gosec-report.json
- id: environments
name: environments
run: |
version=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.1.0")
version=${version#v}
version="$version-$(git rev-parse --short HEAD)"
project=$(go list -m)
echo "
project=${project##*/}
version=$version
sonar_enabled=${{ secrets.SONAR_TOKEN != '' && secrets.SONAR_HOST_URL != ''}}
" >> "$GITHUB_OUTPUT"
shell: bash

- name: build binary
run: |
mkdir -p build
CGO_ENABLE=0 GOOS=${{ inputs.GOOS }} GOARCH=${{ inputs.GOARCH }} go build -a -o build/${{ steps.environments.outputs.project }} ${{ inputs.ENTRANCE }}
- name: test
run: |
go test -gcflags="all=-N -l" -coverprofile=build/coverage.out -covermode count -json -v ./... 2>&1 | tee build/test.json | gotestfmt
go-junit-report -parser gojson -in build/test.json -out build/report.xml
- name: sonar
if: ${{ steps.environments.outputs.sonar_enabled == 'true'}}
run:
~/sonar-scanner/bin/sonar-scanner
-Dsonar.projectBaseDir=./
-Dsonar.host.url=${{ secrets.SONAR_HOST_URL }}
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.pullrequest.key=${{github.event.pull_request.number}}
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
-Dsonar.projectKey=${{ steps.environments.outputs.project }}
-Dsonar.projectVersion=${{ steps.environments.outputs.version }}
-Dsonar.language=go
-Dsonar.sourceEncoding=UTF-8
-Dsonar.exclusions=**/*_test.go,**/vendor/**
-Dsonar.test.inclusions=**/*_test.go
-Dsonar.test.exclusions=**/vendor/**
-Dsonar.go.test.reportPaths=build/report.xml
-Dsonar.go.coverage.reportPaths=build/coverage.out

- name: upload target
uses: actions/upload-artifact@v4
with:
name: target
path: |
${{ inputs.workdir }}build/
75 changes: 75 additions & 0 deletions .github/tmp/call-golang-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
on:
workflow_call:
inputs:
workdir:
required: false
default: "./"
type: "string"
description: "Specify all of steps where are run"

jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
cache: false

- name: restore rust cache
uses: actions/cache/restore@v4
id: cache-restore-golang
env:
cache-name: cache-gomod
with:
path: |
~/go
key: ${{ runner.os }}-golang-store-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-store-${{ env.cache-name }}-
- name: golangci-lint
run: |
go version
golangci-lint -vv
security:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.workdir }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
cache: false

- name: restore rust cache
uses: actions/cache/restore@v4
id: cache-restore-golang
env:
cache-name: cache-gomod
with:
path: |
~/go
key: ${{ runner.os }}-golang-store-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-store-${{ env.cache-name }}-
- name: gosec checkout
run: |
mkdir -p build
gosec -fmt=json -out=build/gosec-report.json -stdout -verbose=text *.go
tree
- name: upload target
uses: actions/upload-artifact@v4
with:
name: gosec-report
path: |
${{ inputs.workdir }}build/gosec-report.json
52 changes: 52 additions & 0 deletions .github/tmp/call-golang-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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@v5
with:
go-version: "1.20"
cache: false

- name: restore rust cache
uses: actions/cache/restore@v4
id: cache-restore-golang
env:
cache-name: cache-gomod
with:
path: |
~/go
key: ${{ runner.os }}-golang-store-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-store-${{ env.cache-name }}-
- name: setup
if: ${{ steps.cache-restore-golang.outputs.cache-hit != 'true'}}
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
go install github.com/gotesttools/gotestfmt/v2/cmd/[email protected]
go install github.com/jstemmer/go-junit-report/[email protected]
- name: cache gomod cache
if: ${{ steps.cache-restore-golang.outputs.cache-hit != 'true'}}
id: cache-save-golang
uses: actions/cache/save@v4
env:
cache-name: cache-gomod
with:
path: |
~/go
key: ${{ runner.os }}-golang-store-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
Loading

0 comments on commit ba80cee

Please sign in to comment.