Skip to content

Commit

Permalink
ci: added sdlc pipeline and dagger source
Browse files Browse the repository at this point in the history
Signed-off-by: William Artero <git@artero.dev>
  • Loading branch information
wwmoraes committed Jan 2, 2024
1 parent 6c5e904 commit 118ea6b
Show file tree
Hide file tree
Showing 19 changed files with 1,210 additions and 3 deletions.
60 changes: 60 additions & 0 deletions .github/actions/sdlc/build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: sdlc-build
description: compiles a Dagger Go application
author: William Artero

branding:
icon: activity
color: blue

inputs:
go-version:
description: Go runtime version
required: true
source-dir:
description: Path with the Dagger Go client source code
required: true
output-dir:
description: Path where to generate the compiled binary
default: ./bin
output-bin:
description: Name of the final compiled binary
default: sdlc

runs:
using: composite

steps:
- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}

- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master

- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOMODCACHE}
key: ${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: download modules
run: go mod download
working-directory: ${{ inputs.source-dir }}
shell: sh

- name: build
uses: wwmoraes/actions/golang/build@master
with:
packages: ./${{ inputs.source-dir }}
output-dir: ${{ inputs.output-dir }}
output-bin: ${{ inputs.output-bin }}

- name: upload
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.output-bin }}
path: ${{ inputs.output-dir }}/${{ inputs.output-bin }}
35 changes: 35 additions & 0 deletions .github/actions/sdlc/run/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: sdlc-run
description: runs a compiled Dagger Go application
author: William Artero

branding:
icon: activity
color: blue

inputs:
output-dir:
description: Path where to generate the compiled binary
default: ./bin
output-bin:
description: Name of the final compiled binary
default: sdlc
dagger-version:
description: Dagger CLI version
required: true

runs:
using: composite

steps:
- name: download sdlc
uses: actions/download-artifact@v3
with:
name: ${{ inputs.output-bin }}
path: ${{ inputs.output-dir }}

- name: run
uses: dagger/dagger-for-github@v5
with:
verb: run
args: ${{ inputs.output-dir }}/${{ inputs.output-bin }} ${{ github.job }}
version: ${{ inputs.dagger-version }}
41 changes: 41 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ jobs:
metadata:
runs-on: ubuntu-latest
steps:

- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: calculate version
uses: paulhatch/semantic-version@v5.0.3
id: version
Expand All @@ -68,6 +70,7 @@ jobs:
search_commit_body: true
user_format_type: csv
version_format: ${major}.${minor}.${patch}-rc.${increment}

- name: generate container meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -89,6 +92,7 @@ jobs:
type=raw,value=${{ env.BRANCH }}
type=semver,pattern={{version}}
github-token: ${{ github.token }}

outputs:
major: ${{ steps.version.outputs.major }}
minor: ${{ steps.version.outputs.minor }}
Expand All @@ -101,18 +105,23 @@ jobs:
authors: ${{ steps.version.outputs.authors }}
container-labels: ${{ steps.meta.outputs.labels }}
container-tags: ${{ steps.meta.outputs.tags }}

build:
runs-on: ubuntu-latest
needs: metadata
steps:

- name: checkout
uses: actions/checkout@v3

- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master

- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
Expand All @@ -121,8 +130,10 @@ jobs:
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: download modules
run: go mod download

- name: cache build
uses: pat-s/always-upload-cache@v2.1.5
with:
Expand All @@ -131,24 +142,29 @@ jobs:
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('**/*.go') }}
${{ runner.os }}-build-
- name: build
run: make build
env:
VERSION: ${{ needs.metadata.outputs.version }}+${{ github.sha }}

# - name: generate
# run: go generate ./...
# env:
# VERSION: ${{ needs.metadata.outputs.version }}+${{ github.sha }}

# - name: build
# uses: wwmoraes/actions/packages/golang/build@develop
# with:
# flags: -race -mod=readonly

lint:
runs-on: ubuntu-latest
env:
CONTAINER_LINT_REPORT_FILE: hadolint-report.json
GOLANGCI_LINT_REPORT_FILE: golangci-lint-report.json
steps:

- name: checkout
uses: actions/checkout@v3

Expand Down Expand Up @@ -201,29 +217,36 @@ jobs:
with:
name: source-lint-report
path: ${{ steps.lint.outputs.report-file }}

- name: lint container source
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
format: sonarqube
output-file: ${{ env.CONTAINER_LINT_REPORT_FILE }}

- name: upload container lint report
uses: actions/upload-artifact@v3
if: always()
with:
name: container-lint-report
path: ${{ env.CONTAINER_LINT_REPORT_FILE }}

test:
runs-on: ubuntu-latest
steps:

- name: checkout
uses: actions/checkout@v3

- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master

- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
Expand All @@ -232,8 +255,10 @@ jobs:
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: download modules
run: go mod download

- name: cache test
uses: pat-s/always-upload-cache@v2.1.5
with:
Expand All @@ -242,8 +267,10 @@ jobs:
restore-keys: |
${{ runner.os }}-test-${{ hashFiles('**/*.go') }}
${{ runner.os }}-test-
- name: coverage test
run: make coverage

# - name: integration test
# uses: wwmoraes/actions/golang/integration@master
# with:
Expand All @@ -253,34 +280,40 @@ jobs:
# coverage-packages: |-
# github.com/${{ github.repository }}/internal/usecases
# github.com/${{ github.repository }}/internal/adapters

# - name: unit test
# uses: wwmoraes/actions/golang/test@master
# with:
# flags: -race -mod=readonly
# cover-profile: ${{ runner.temp }}/unit.txt

# - name: aggregate test results
# run: >-
# go run github.com/wadey/gocovmerge@latest
# ${{ runner.temp }}/integration.txt
# ${{ runner.temp }}/unit.txt
# > ${{ runner.temp }}/merged.txt

- name: upload coverage report
uses: actions/upload-artifact@v3
if: always()
with:
name: coverage-report
path: ${{ env.GOLANG_MERGED_GOCOV_FILE }}

- name: upload run report
uses: actions/upload-artifact@v3
if: always()
with:
name: run-report
path: ${{ env.GOLANG_RUN_REPORT_FILE }}

report:
runs-on: ubuntu-latest
needs: [lint, test]
if: always()
steps:

- name: checkout
uses: actions/checkout@v3

Expand Down Expand Up @@ -374,19 +407,24 @@ jobs:
# ${{ env.GOLANG_RUN_REPORT_FILE }}
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

container:
runs-on: ubuntu-latest
needs: metadata
env:
# runner context is not available here...
GRYPE_DB_CACHE_TEMP_PATH: .cache/grype/db/
steps:

- name: checkout
uses: actions/checkout@v3

- name: set up QEMU
uses: docker/setup-qemu-action@v2

- name: set up docker buildx
uses: docker/setup-buildx-action@v2

- name: cache buildx
uses: pat-s/always-upload-cache@v2.1.5
with:
Expand All @@ -398,6 +436,7 @@ jobs:
${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
${{ runner.os }}-buildx-
# yamllint enable rule:line-length

- name: build single-arch test image
uses: docker/build-push-action@v3
env:
Expand All @@ -417,13 +456,15 @@ jobs:
build-args: |
GOLANG_VERSION=${{ env.GOLANG_VERSION }}
VERSION=${{ needs.metadata.outputs.version }}
# fix to prevent ever-growing caches
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf ${{ runner.temp }}/.buildx-cache
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
- name: test structure
uses: brpaz/structure-tests-action@v1.1.2
with:
Expand Down

0 comments on commit 118ea6b

Please sign in to comment.