Skip to content

Commit

Permalink
Add github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-petko authored and GitHub Enterprise committed Apr 22, 2023
1 parent 08d771f commit c5259ff
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/configuration/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "Code QL Configuration"

paths:
- ./src
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/src" # Location of package manifests
schedule:
interval: "weekly"
open-pull-requests-limit: 50
76 changes: 76 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: 'Build Docker Image'

on:
push:
branches:
- master
paths:
- "Dockerfile"
- "src/**"
- ".github/workflows/**"

# Allows you to run this workflow manually from the Actions tab. We can override the branch, image name, and docker registry.
workflow_dispatch:
inputs:
ref:
description: 'Ref'
required: false
default: ''
image:
description: 'Image Name'
required: true
default: 'mfdlabs/ns1-github-comparator'
registry:
description: 'Docker Registry'
required: true
default: 'docker.io'

jobs:
build:
if: "!contains(github.event.head_commit.message, '[SKIP IMAGE]')"
runs-on: ubuntu-latest

# If DOCKER_REGISTRY is not set, default to docker.io
env:
DOCKER_REGISTRY: ${{ github.event.inputs.registry || secrets.DOCKER_REGISTRY || 'docker.io' }}
IMAGE_NAME: ${{ github.event.inputs.image || secrets.IMAGE_NAME || 'mfdlabs/ns1-github-comparator' }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

# Pushes 2 identical images to the registry, one with the tag latest and one with the version from git-ref
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.ref || github.ref }}

# Error if IMAGE_NAME is not set
- name: Check IMAGE_NAME
run: |
if [ -z "$IMAGE_NAME" ]; then
echo "IMAGE_NAME is not set"
exit 1
fi
# Error if DOCKER_USERNAME is not set
- name: Check DOCKER_USERNAME
run: |
if [ -z "$DOCKER_USERNAME" ]; then
echo "DOCKER_USERNAME is not set"
exit 1
fi
# Error if DOCKER_PASSWORD is not set
- name: Check DOCKER_PASSWORD
run: |
if [ -z "$DOCKER_PASSWORD" ]; then
echo "DOCKER_PASSWORD is not set"
exit 1
fi
# Login to the registry
- name: Login to registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login ${{ env.DOCKER_REGISTRY }} -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

# Push the image to the registry
- name: Build & Push the image
run: make build-docker IMAGE_NAME=${{ env.IMAGE_NAME }} CI=true
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Go Build

on:
push:
branches:
- "master"
paths:
- "src/**"
- ".github/workflows/**"
pull_request:
paths:
- "src/**"
- ".github/workflows/**"

jobs:
lint:
name: Go lint
if: "!contains(toJSON(github.event.commits.*.message), '[SKIP BUILD]')"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup the Golang environment with version 1.20.x
uses: actions/setup-go@v2
with:
go-version: 1.20.x

- name: Run lint
working-directory: ./src
run: go mod tidy && go mod vendor && go vet ./...

build:
name: Build
if: "!contains(toJSON(github.event.commits.*.message), '[SKIP BUILD]')"
needs: lint
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
os: ["linux", "darwin", "windows"]
arch: ["x86", "x64", "arm", "arm64"]
config: ["debug", "release"]

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

- name: Setup the Golang environment with version 1.20.x
uses: actions/setup-go@v2
with:
go-version: 1.20.x

- name: Run the build-<config>-<arch> make target
run: make build-${{ matrix.config }}-${{ matrix.arch }} GOOS=${{ matrix.os }}

29 changes: 29 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CodeQL Analysis

on:
push:
branches:
- "master"
pull_request:
branches:
- "master"

jobs:
codeql:
if: "!contains(toJSON(github.event.commits.*.message), '[SKIP ANALYSIS]')"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: "go"
config-file: "./.github/configuration/codeql-config.yml"

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Go Test

on:
push:
branches:
- "master"
paths:
- "src/**"
- ".github/workflows/**"
pull_request:
paths:
- "src/**"
- ".github/workflows/**"

jobs:
test:
name: Go Test
if: "!contains(toJSON(github.event.commits.*.message), '[SKIP TEST]')"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup the Golang environment with version 1.20.x
uses: actions/setup-go@v2
with:
go-version: 1.20.x

- name: Run Test
run: make test

0 comments on commit c5259ff

Please sign in to comment.