Skip to content

Commit

Permalink
feat: Migrate to GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Oct 18, 2024
1 parent 87ddd45 commit 01fbbaf
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 249 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/build.yaml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI
on:
pull_request:
push:
branches:
- main
- release/*
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
- name: Verify
run: |
make verify
- name: Test
run: |
make test
- name: Build
env:
TAG: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: build --clean --snapshot
- name: Image Build
run: |
make image
env:
TAG: dev
REPO: cnrancher
21 changes: 0 additions & 21 deletions .github/workflows/lint.yaml

This file was deleted.

69 changes: 69 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Release

on:
push:
tags:
- 'v*'
jobs:
release:
permissions:
contents: write # required for creating GH release
id-token: write # required for reading vault secrets
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: ${{ vars.PUBLIC_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name}}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
- name: Verify
run: |
make verify
- name: Test
run: |
make test
- name: Go Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for creating GH release
TAG: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean --verbose
- name: Image Push
run: |
make image-push
env:
TAG: ${{ github.ref_name }}
REPO: ${{ vars.PUBLIC_REGISTRY }}/${{ secrets.DOCKERHUB_USERNAME }}
- name: Upload Charts
env:
TAG: ${{ github.ref_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for updating GH release
run: |
make chart
for f in $(find dist/artifacts/ -name '*.tgz'); do
echo "Uploading $f to GitHub release $TAG"
gh release upload $TAG $f
done
echo "Charts successfully uploaded to GitHub release $TAG"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ go.work

# Build files
/bin/
/build/
/dist/
/cce-operator

Expand Down
51 changes: 51 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
ldflags:
- -extldflags -static
- -s -w
- -X github.com/cnrancher/cce-operator/pkg/utils.GitCommit={{.Env.COMMIT}}
- -X github.com/cnrancher/cce-operator/pkg/utils.Version={{.Env.TAG}}
main: ./main.go
id: cce-operator
binary: cce-operator

release:
prerelease: auto

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
29 changes: 0 additions & 29 deletions Dockerfile.dapper

This file was deleted.

57 changes: 41 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
SCRIPTS := build test ci validate
.PHONY: $(SCRIPTS) clean generate help
TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" )
COMMIT?=$(shell git rev-parse HEAD)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp
@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper
default: build

$(SCRIPTS): .dapper
@./.dapper $@
.PHONY: generate
generate:
@go generate

.PHONY: build
build:
COMMIT=$(COMMIT) TAG=$(TAG) goreleaser build --snapshot --clean

.PHONY: test
test:
CGO_ENABLED=0 go test -cover --count=1 ./...

.PHONY: clean
clean:
@./scripts/clean.sh
./scripts/clean.sh

generate:
@go generate ./main.go
.PHONY: verify
verify:
./scripts/verify.sh

.PHONY: chart
chart:
TAG=$(TAG) ./scripts/chart.sh

.PHONY: image
image:
TAG=$(TAG) ./scripts/image.sh

.PHONY: image-push
image-push:
TAG=$(TAG) BUILDX_OPTIONS="--push" ./scripts/image.sh

.PHONY: help
help:
@echo "Usage:"
@echo " make build - Build executable files in 'bin' folder"
@echo " make test - Run unit test"
@echo " make generate - Generate codes & CRDs"
@echo " make build build binary files"
@echo " make test run unit tests"
@echo " make generate run code generator"
@echo " make verify verify modules"
@echo " make chart package helm charts"
@echo " make image build container images"
@echo " make image-push build container images and push"
@echo " make clean clean up built files"
@echo " make help show this message"
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ toolchain go1.22.3
require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.104
github.com/rancher/lasso v0.0.0-20240603075835-701e919d08b7
github.com/rancher/wrangler/v3 v3.0.0-rc2
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.118
github.com/rancher/lasso v0.0.0-20240705194423-b2a060d103c1
github.com/rancher/wrangler/v3 v3.0.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
k8s.io/api v0.30.1
Expand Down Expand Up @@ -51,14 +51,14 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/tjfoc/gmsm v1.4.1 // indirect
go.mongodb.org/mongo-driver v1.12.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading

0 comments on commit 01fbbaf

Please sign in to comment.