Skip to content

Commit 9de5001

Browse files
Add pipeline
1 parent 0745426 commit 9de5001

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
env:
9+
DOCKER_FILE_PATH: Dockerfile
10+
GOLANG_VERSION: 1.14
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
name: Build
16+
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
17+
steps:
18+
- name: Check out code
19+
uses: actions/checkout@v2
20+
21+
- name: Set up Go
22+
id: go
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: ${{ env.GOLANG_VERSION }}
26+
27+
- name: Lint
28+
run: |
29+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
30+
golangci-lint run --timeout=10m ./...
31+
32+
# - name: Test
33+
# run: GOFLAGS="-count=1" go test -v ./... -coverprofile cover.out
34+
35+
- name: Generate Tag
36+
id: generate_tag
37+
run: |
38+
sha=${{ github.event.pull_request.head.sha }}
39+
tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}"
40+
echo "##[set-output name=GIT_TAG;]$(echo ${tag})"
41+
42+
- name: Build and push Docker images
43+
uses: docker/build-push-action@v1
44+
with:
45+
username: ${{ secrets.STAKATER_NEXUS_USERNAME }}
46+
password: ${{ secrets.STAKATER_NEXUS_PASSWORD }}
47+
registry: ${{ secrets.STAKATER_NEXUS_REGISTRY }}
48+
repository: ${{ env.GITHUB_REPOSITORY }}
49+
add_git_labels: true
50+
dockerfile: ${{ env.DOCKER_FILE_PATH }}
51+
tags: ${{ steps.generate_tag.outputs.GIT_TAG }}
52+
53+
54+
- name: Comment on PR
55+
uses: thollander/actions-comment-pull-request@master
56+
with:
57+
message: '@${{ github.actor }} Image is available for testing. `docker pull ${{ secrets.STAKATER_NEXUS_REGISTRY }}/${{ github.repository }}:${{ steps.generate_tag.outputs.GIT_TAG }}`'
58+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
59+
60+
- name: Notify Failure
61+
if: failure()
62+
uses: thollander/actions-comment-pull-request@master
63+
with:
64+
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!'
65+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
66+
67+
- name: Notify Slack
68+
uses: 8398a7/action-slack@v3
69+
if: always() # Pick up events even if the job fails or is canceled.
70+
with:
71+
status: ${{ job.status }}
72+
fields: repo,author,action,eventName,ref,workflow
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
75+
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

.github/workflows/push.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Push
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
DOCKER_FILE_PATH: Dockerfile
10+
GOLANG_VERSION: 1.14
11+
OPERATOR_SDK_VERSION: "0.19.0"
12+
KUSTOMIZE_VERSION: "3.5.4"
13+
14+
jobs:
15+
build:
16+
name: Build
17+
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Check out code
22+
uses: actions/checkout@v2
23+
24+
- name: Set up Go
25+
id: go
26+
uses: actions/setup-go@v2
27+
with:
28+
go-version: ${{ env.GOLANG_VERSION }}
29+
30+
- name: Lint
31+
run: |
32+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
33+
golangci-lint run --timeout=10m ./...
34+
35+
# - name: Test
36+
# run: GOFLAGS="-count=1" go test -v ./... -coverprofile cover.out
37+
38+
- name: Generate Tag
39+
id: generate_tag
40+
uses: anothrNick/[email protected]
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
43+
WITH_V: true
44+
DEFAULT_BUMP: patch
45+
DRY_RUN: true
46+
47+
- name: Build and push Docker images
48+
uses: docker/build-push-action@v1
49+
with:
50+
username: ${{ secrets.STAKATER_NEXUS_USERNAME }}
51+
password: ${{ secrets.STAKATER_NEXUS_PASSWORD }}
52+
registry: ${{ secrets.STAKATER_NEXUS_REGISTRY }}
53+
repository: ${{ env.GITHUB_REPOSITORY }}
54+
add_git_labels: true
55+
dockerfile: ${{ env.DOCKER_FILE_PATH }}
56+
tags: ${{ steps.generate_tag.outputs.new_tag }}
57+
58+
59+
##############################
60+
## Add steps to generate required artifacts for a release here(helm chart, operator manifest etc.)
61+
##############################
62+
63+
# Generate tag for operator without "v"
64+
- name: Generate Operator Tag
65+
id: generate_operator_tag
66+
uses: anothrNick/[email protected]
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
69+
WITH_V: false
70+
DEFAULT_BUMP: patch
71+
DRY_RUN: true
72+
73+
# Install operator-sdk
74+
- name: Install operator-sdk
75+
env:
76+
OPERATOR_SDK_VERSION: ${{ env.OPERATOR_SDK_VERSION }}
77+
run: |
78+
curl -fL -o /tmp/operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk-v${OPERATOR_SDK_VERSION}-x86_64-linux-gnu"
79+
sudo install /tmp/operator-sdk /usr/local/bin && rm -f /tmp/operator-sdk
80+
operator-sdk version
81+
operator-sdk version | grep -q "${OPERATOR_SDK_VERSION}"
82+
83+
# Install kustomize
84+
- uses: imranismail/setup-kustomize@v1
85+
with:
86+
kustomize-version: ${{ env.KUSTOMIZE_VERSION }}
87+
88+
- name: Generate Bundle
89+
env:
90+
VERSION: ${{ steps.generate_operator_tag.outputs.new_tag }}
91+
run: make bundle
92+
93+
- name: Generate Package Manifests
94+
env:
95+
VERSION: ${{ steps.generate_operator_tag.outputs.new_tag }}
96+
run: make packagemanifests
97+
98+
# Commit back changes
99+
- uses: stefanzweifel/git-auto-commit-action@v4
100+
with:
101+
commit_message: "[skip-ci] Update artifacts"
102+
commit_user_name: stakater-user
103+
commit_user_email: [email protected]
104+
105+
- name: Push Latest Tag
106+
uses: anothrNick/[email protected]
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
109+
WITH_V: true
110+
DEFAULT_BUMP: patch
111+
112+
- name: Notify Slack
113+
uses: 8398a7/action-slack@v3
114+
if: always() # Pick up events even if the job fails or is canceled.
115+
with:
116+
status: ${{ job.status }}
117+
fields: repo,author,action,eventName,ref,workflow
118+
env:
119+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
120+
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release Go project
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
GOLANG_VERSION: 1.14
10+
11+
jobs:
12+
build:
13+
name: GoReleaser build
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/
21+
22+
- name: Set up Go 1.x
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: ${{ env.GOLANG_VERSION }}
26+
id: go
27+
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@master
30+
with:
31+
version: latest
32+
args: release --rm-dist
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
35+
36+
- name: Notify Slack
37+
uses: 8398a7/action-slack@v3
38+
if: always()
39+
with:
40+
status: ${{ job.status }}
41+
fields: repo,author,action,eventName,ref,workflow
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
44+
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

.goreleaser.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
- go generate ./...
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
archives:
13+
- replacements:
14+
darwin: Darwin
15+
linux: Linux
16+
windows: Windows
17+
386: i386
18+
amd64: x86_64
19+
checksum:
20+
name_template: 'checksums.txt'
21+
snapshot:
22+
name_template: "{{ .Tag }}-next"
23+
changelog:
24+
sort: asc
25+
filters:
26+
exclude:
27+
- '^docs:'
28+
- '^test:'

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ else
106106
KUSTOMIZE=$(shell which kustomize)
107107
endif
108108

109+
# Options for "packagemanifests".
110+
ifneq ($(origin FROM_VERSION), undefined)
111+
PKG_FROM_VERSION := --from-version=$(FROM_VERSION)
112+
endif
113+
ifneq ($(origin CHANNEL), undefined)
114+
PKG_CHANNELS := --channel=$(CHANNEL)
115+
endif
116+
ifeq ($(IS_CHANNEL_DEFAULT), 1)
117+
PKG_IS_DEFAULT_CHANNEL := --default-channel
118+
endif
119+
PKG_MAN_OPTS ?= $(FROM_VERSION) $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL)
120+
121+
# Generate package manifests.
122+
packagemanifests: manifests
123+
operator-sdk generate kustomize manifests -q
124+
$(KUSTOMIZE) build config/manifests | operator-sdk generate packagemanifests -q --version $(VERSION) $(PKG_MAN_OPTS)
125+
109126
# Generate bundle manifests and metadata, then validate generated files.
110127
bundle: manifests
111128
operator-sdk generate kustomize manifests -q

0 commit comments

Comments
 (0)