Skip to content

Commit

Permalink
Merge pull request #13 from stakater/add-pipeline
Browse files Browse the repository at this point in the history
Add pipeline
  • Loading branch information
ahmedwaleedmalik authored Aug 25, 2020
2 parents 16f6370 + 1b2c183 commit 2b6a241
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 7 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Pull Request

on:
pull_request:
branches:
- master

env:
DOCKER_FILE_PATH: Dockerfile
GOLANG_VERSION: 1.14

jobs:
build:
runs-on: ubuntu-latest
name: Build
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go
id: go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
golangci-lint run --timeout=10m ./...
# - name: Test
# run: GOFLAGS="-count=1" go test -v ./... -coverprofile cover.out

- name: Generate Tag
id: generate_tag
run: |
sha=${{ github.event.pull_request.head.sha }}
tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}"
echo "##[set-output name=GIT_TAG;]$(echo ${tag})"
- name: Build and push Docker images
uses: docker/build-push-action@v1
with:
username: ${{ secrets.STAKATER_NEXUS_USERNAME }}
password: ${{ secrets.STAKATER_NEXUS_PASSWORD }}
registry: ${{ secrets.STAKATER_NEXUS_REGISTRY }}
repository: ${{ env.GITHUB_REPOSITORY }}
add_git_labels: true
dockerfile: ${{ env.DOCKER_FILE_PATH }}
tags: ${{ steps.generate_tag.outputs.GIT_TAG }}


- name: Comment on PR
uses: thollander/actions-comment-pull-request@master
with:
message: '@${{ github.actor }} Image is available for testing. `docker pull ${{ secrets.STAKATER_NEXUS_REGISTRY }}/${{ github.repository }}:${{ steps.generate_tag.outputs.GIT_TAG }}`'
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}

- name: Notify Failure
if: failure()
uses: thollander/actions-comment-pull-request@master
with:
message: '@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!'
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}

- name: Notify Slack
uses: 8398a7/action-slack@v3
if: always() # Pick up events even if the job fails or is canceled.
with:
status: ${{ job.status }}
fields: repo,author,action,eventName,ref,workflow
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}
94 changes: 94 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Push

on:
push:
branches:
- master

env:
DOCKER_FILE_PATH: Dockerfile
GOLANG_VERSION: 1.14
OPERATOR_SDK_VERSION: "0.19.0"

jobs:
build:
name: Build
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go
id: go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
golangci-lint run --timeout=10m ./...
# - name: Test
# run: GOFLAGS="-count=1" go test -v ./... -coverprofile cover.out

- name: Generate Tag
id: generate_tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
DRY_RUN: true

- name: Build and push Docker images
uses: docker/build-push-action@v1
with:
username: ${{ secrets.STAKATER_NEXUS_USERNAME }}
password: ${{ secrets.STAKATER_NEXUS_PASSWORD }}
registry: ${{ secrets.STAKATER_NEXUS_REGISTRY }}
repository: ${{ env.GITHUB_REPOSITORY }}
add_git_labels: true
dockerfile: ${{ env.DOCKER_FILE_PATH }}
tags: ${{ steps.generate_tag.outputs.new_tag }}


##############################
## Add steps to generate required artifacts for a release here(helm chart, operator manifest etc.)
##############################

- name: Install operator-sdk
run: |
curl -fL -o /tmp/operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v${env.OPERATOR_SDK_VERSION}/operator-sdk-v${env.OPERATOR_SDK_VERSION}-x86_64-linux-gnu"
sudo install /tmp/operator-sdk /usr/local/bin && rm -f /tmp/operator-sdk
operator-sdk version
operator-sdk version | grep -q "${env.OPERATOR_SDK_VERSION}"
- name: Generate Bundle
env:
VERSION: ${{ steps.generate_tag.outputs.new_tag }}
run: make bundle

- name: Generate Package Manifests
env:
VERSION: ${{ steps.generate_tag.outputs.new_tag }}
run: make packagemanifests

- name: Push Latest Tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch

- name: Notify Slack
uses: 8398a7/action-slack@v3
if: always() # Pick up events even if the job fails or is canceled.
with:
status: ${{ job.status }}
fields: repo,author,action,eventName,ref,workflow
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release Go project

on:
push:
tags:
- "v*"

env:
GOLANG_VERSION: 1.14

jobs:
build:
name: GoReleaser build
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ env.GOLANG_VERSION }}
id: go

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}

- name: Notify Slack
uses: 8398a7/action-slack@v3
if: always()
with:
status: ${{ job.status }}
fields: repo,author,action,eventName,ref,workflow
env:
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ bin
*~
/_output/
/jira-service-desk-operator
/.local/
28 changes: 28 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
before:
hooks:
- go mod download
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COPY controllers/ controllers/
COPY pkg/ pkg/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -mod=mod -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ $(GOLANGCI_LINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(dir $@) v1.24.0

verify-golangci-lint: $(GOLANGCI_LINT)
GOLANGCI_LINT_CACHE=$(GOLANGCI_LINT_CACHE) $(GOLANGCI_LINT) run --timeout=300s ./api/... ./controllers/... ./test/...
GOLANGCI_LINT_CACHE=$(GOLANGCI_LINT_CACHE) $(GOLANGCI_LINT) run --timeout=300s ./...

verify: verify-fmt verify-golangci-lint
5 changes: 3 additions & 2 deletions pkg/jiraservicedesk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
jiraservicedeskv1alpha1 "github.com/stakater/jira-service-desk-operator/api/v1alpha1"
"io"
"net/http"
"net/url"

logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
jiraservicedeskv1alpha1 "github.com/stakater/jira-service-desk-operator/api/v1alpha1"

logf "sigs.k8s.io/controller-runtime/pkg/log"
)

var Log = logf.Log.WithName("jiraServiceDeskClient")
Expand Down
5 changes: 3 additions & 2 deletions pkg/jiraservicedesk/config/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package config

import (
"os"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/stakater/jira-service-desk-operator/pkg/util"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

var log = logf.Log.WithName("config")
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

var log = logf.Log.WithName("util")
Expand Down

0 comments on commit 2b6a241

Please sign in to comment.