Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jürgen Etzlstorfer committed Mar 25, 2021
0 parents commit 57af16c
Show file tree
Hide file tree
Showing 30 changed files with 2,292 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .ci_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DOCKER_ORGANIZATION="keptnsandbox"
IMAGE="keptn-service-template-go"
Empty file added .dockerignore
Empty file.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
177 changes: 177 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: CI
on:
# always execute docker build when something is pushed to master or release-* branches
push:
branches:
- 'master'
- 'release-*'
# in addition, execute for pull requests to those branches
pull_request:
branches:
- 'master'
- 'release-*'
defaults:
run:
shell: bash
jobs:
prepare_ci_run:
name: Prepare CI Run
# Prepare CI Run looks at what has been changed in this commit/PR/... and determines which artifacts should be
# built afterwards (in other jobs that depend on this one).
runs-on: ubuntu-20.04
outputs: # declare what this job outputs (so it can be re-used for other jobs)
# build config
# metadata
GIT_SHA: ${{ steps.extract_branch.outputs.GIT_SHA }}
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }}
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
DATE: ${{ steps.get_datetime.outputs.DATE }}
TIME: ${{ steps.get_datetime.outputs.TIME }}
DATETIME: ${{ steps.get_datetime.outputs.DATETIME }}

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0 # need to checkout "all commits" for certain features to work (e.g., get all changed files)

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- name: Extract branch name
id: extract_branch
# see https://github.com/keptn/gh-action-extract-branch-name for details
uses: keptn/gh-action-extract-branch-name@main

- name: 'Get Previous tag'
id: get_previous_tag
uses: "WyriHaximus/[email protected]"
- name: 'Get next patch version'
id: get_next_semver_tag
uses: "WyriHaximus/[email protected]"
with:
version: ${{ steps.get_previous_tag.outputs.tag }}
- name: Get the version
id: get_version
env:
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }}
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
shell: bash
run: |
# determine version
GIT_LAST_TAG=${{ steps.get_previous_tag.outputs.tag }}
GIT_NEXT_TAG=${{ steps.get_next_semver_tag.outputs.patch }}
echo "GIT_LAST_TAG=${GIT_LAST_TAG}, GIT_NEXT_TAG=${GIT_NEXT_TAG}"
if [[ "$BRANCH" == "release-"* ]]; then
# Release Branch: extract version from branch name
VERSION=${BRANCH#"release-"}
else
if [[ "$BRANCH" == "master" ]]; then
# master branch = latest
VERSION="${GIT_NEXT_TAG}-dev"
else
# Feature/Development Branch - use last tag with branch slug
VERSION="${GIT_NEXT_TAG}-dev-${BRANCH_SLUG}"
fi
fi
echo "VERSION=${VERSION}"
echo "##[set-output name=VERSION;]$(echo ${VERSION})"
- name: Get current date and time
id: get_datetime
run: |
echo "::set-output name=DATE::$(date +'%Y%m%d')"
echo "::set-output name=TIME::$(date +'%H%M')"
echo "::set-output name=DATETIME::$(date +'%Y%m%d')$(date +'%H%M')"
############################################################################
# Unit tests #
############################################################################
unit-tests:
name: Unit Tests
needs: prepare_ci_run
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
- name: Checkout Code
uses: actions/checkout@v2

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- name: Test
run: go test -coverprofile=coverage.txt -covermode=atomic -v ./...
working-directory: .


############################################################################
# Build Docker Image #
############################################################################
docker_build:
needs: [prepare_ci_run, unit-tests]
name: Docker Build
runs-on: ubuntu-20.04
env:
BRANCH: ${{ needs.prepare_ci_run.outputs.BRANCH }}
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATE }}${{ needs.prepare_ci_run.outputs.TIME }}
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- id: docker_login
name: Docker Login
# only run docker login on pushes; also for PRs, but only if this is not a fork
if: (github.event_name == 'push') || (github.event.pull_request.head.repo.full_name == github.repository)
# note: GH does not allow to access secrets for PRs from a forked repositories due to security reasons
# that's fine, but it means we can't push images to dockerhub
uses: docker/login-action@v1
with:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- id: docker_build
name: Docker Build
uses: keptn/gh-action-build-docker-image@master
with:
VERSION: ${{ env.VERSION }}
IMAGE_NAME: "${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}"
DATETIME: ${{ env.DATETIME }}

- id: create_docker_build_report
name: Create Docker Build Report
run: |
echo "The following Docker Images have been built: " > docker_build_report_final.txt
cat docker_build_report.txt >> docker_build_report_final.txt || echo "* No images have been built or uploaded" >> docker_build_report_final.txt
echo "---"
cat docker_build_report_final.txt
- id: report_docker_build_to_pr
# Comment the docker build report to the PR
# This only works for PRs coming from inside of the repo, not from forks
name: Report Docker Build to PR
if: (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.repository)
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
path: docker_build_report_final.txt
recreate: true
24 changes: 24 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: reviewdog
on: [pull_request]
jobs:
reviewdog:
name: reviewdog
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.13
id: go
- name: Check out code.
uses: actions/checkout@v1
- name: Install linters
run: '( mkdir linters && cd linters && go get golang.org/x/lint/golint )'
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
reviewdog -reporter=github-pr-review
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

vendor/*
.DS_Store

# binaries (created by go build on Linux/OSX)
main
keptn-service-template-go

# IDE specific folders
.vscode

# only ignore contents of local .idea
.idea/*
# but allow .idea shared run configurations
!.idea/runConfigurations/
16 changes: 16 additions & 0 deletions .idea/runConfigurations/Build_Dockerfile.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/runConfigurations/Develop_on_Kubernetes.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/runConfigurations/Run_on_Kubernetes.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
runner:
golint:
cmd: golint ./...
errorformat:
- "%f:%l:%c: %m"
level: warning
gofmt:
cmd: gofmt -l -s .|xargs -I{} echo {}:1 file {} is not gofmted
errorformat:
- "%f:%l %m"
govet:
cmd: go vet -all .
10 changes: 10 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##############################################################
#
# Lists the owners of this project
#
##############################################################
#
# Learn about CODEOWNERS file format:
# https://help.github.com/en/articles/about-code-owners
#

Loading

0 comments on commit 57af16c

Please sign in to comment.