-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
285 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: release-kubernetes | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'kubernetes/v*' | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- name: Cache Go modules | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Tests | ||
run: | | ||
go mod tidy | ||
go test -v ./... | ||
- name: Docker Login | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
if: success() && startsWith(github.ref, 'refs/tags/') | ||
with: | ||
workdir: ./kubernetes | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
project_name: atomix-gen-kubernetes | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- id: atomix-gen-kubernetes | ||
main: . | ||
binary: atomix-gen-kubernetes | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
env: | ||
- CC=gcc | ||
- CXX=g++ | ||
flags: | ||
- -mod=readonly | ||
- -trimpath | ||
gcflags: | ||
- all=-N -l | ||
ldflags: | ||
- -s | ||
- -X github.com/atomix/codegen/pkg/version.shortCommit={{ .ShortCommit }} | ||
- -X github.com/atomix/codegen/pkg/version.commit={{ .FullCommit }} | ||
- -X github.com/atomix/codegen/pkg/version.version=v{{ .Version }} | ||
- -X github.com/atomix/codegen/pkg/version.buildType={{ if .IsSnapshot }}snapshot{{ else }}release{{ end }} | ||
|
||
dockers: | ||
- id: codegen-kubernetes | ||
ids: | ||
- atomix-gen-kubernetes | ||
image_templates: | ||
- "atomix/codegen:kubernetes-latest" | ||
- "{{ if (not .IsSnapshot) }}atomix/codegen:kubernetes-{{ .Tag }}{{ end }}" | ||
- "{{ if (not .IsSnapshot) }}atomix/codegen:kubernetes-v{{ .Major }}.{{ .Minor }}{{ end }}" | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
snapshot: | ||
name_template: "{{ incpatch .Version }}-{{.ShortCommit}}" | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-FileCopyrightText: 2022-present Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
ARG VERSION=latest | ||
|
||
FROM atomix/codegen:$VERSION | ||
|
||
COPY atomix-gen-kubernetes /usr/local/bin/atomix-gen-kubernetes | ||
|
||
ENTRYPOINT ["atomix-gen-kubernetes"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SPDX-FileCopyrightText: 2022-present Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
GOLANG_CROSS_VERSION := v1.18.1 | ||
|
||
build: | ||
goreleaser release --snapshot --rm-dist | ||
|
||
reuse-tool: # @HELP install reuse if not present | ||
command -v reuse || python3 -m pip install reuse | ||
|
||
license: reuse-tool # @HELP run license checks | ||
reuse lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-FileCopyrightText: 2022-present Open Networking Foundation <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GetCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "atomix-gen-kubernetes", | ||
Args: cobra.NoArgs, | ||
RunE: run, | ||
} | ||
cmd.Flags().StringP("input-path", "p", ".", "the relative path to the API root") | ||
cmd.Flags().StringP("output-path", "o", "", "the relative path to the output directory") | ||
cmd.Flags().StringP("group-version", "g", "", "the group:version tuple") | ||
cmd.Flags().Bool("deepcopy", false, "generate deepcopy files") | ||
cmd.Flags().Bool("client", false, "generate API clients") | ||
cmd.Flags().String("boilerplate", "", "the path to a boilerplate file") | ||
_ = cmd.MarkFlagRequired("input-path") | ||
_ = cmd.MarkFlagRequired("input-path") | ||
_ = cmd.MarkFlagRequired("group-version") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-FileCopyrightText: 2022-present Open Networking Foundation <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/atomix/codegen/internal/exec" | ||
"github.com/spf13/cobra" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func run(cmd *cobra.Command, _ []string) error { | ||
inputPath, err := cmd.Flags().GetString("input-path") | ||
if err != nil { | ||
return err | ||
} | ||
outputPath, err := cmd.Flags().GetString("output-path") | ||
if err != nil { | ||
return err | ||
} | ||
if outputPath == "" { | ||
outputPath = inputPath | ||
} | ||
groupVersion, err := cmd.Flags().GetString("group-version") | ||
if err != nil { | ||
return err | ||
} | ||
deepcopy, err := cmd.Flags().GetBool("deepcopy") | ||
if err != nil { | ||
return err | ||
} | ||
client, err := cmd.Flags().GetBool("client") | ||
if err != nil { | ||
return err | ||
} | ||
boilerplate, err := cmd.Flags().GetString("boilerplate") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tmpDir, err := ioutil.TempDir("", "code-generator") | ||
if err != nil { | ||
return err | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
err = exec.Run("git", "clone", "https://github.com/kubernetes/code-generator.git", tmpDir) | ||
if err != nil { | ||
return err | ||
} | ||
err = exec.RunIn(tmpDir, "git", "checkout", "release-1.24") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var generators []string | ||
if deepcopy { | ||
generators = append(generators, "deepcopy") | ||
} | ||
if client { | ||
generators = append(generators, "client") | ||
} | ||
|
||
var args []string | ||
args = append(args, filepath.Join(tmpDir, "generate-groups.sh")) | ||
args = append(args, strings.Join(generators, ",")) | ||
args = append(args, inputPath, outputPath, groupVersion) | ||
if boilerplate != "" { | ||
args = append(args, "--go-header-file", boilerplate) | ||
} | ||
err = exec.Run("bash", args...) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/atomix/codegen/kubernetes | ||
|
||
go 1.18 | ||
|
||
require github.com/spf13/cobra v1.4.0 | ||
|
||
require ( | ||
github.com/atomix/codegen v0.0.0-20220508094714-cc2cae885ff9 | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) | ||
|
||
replace github.com/atomix/codegen => ../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= | ||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= | ||
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-FileCopyrightText: 2022-present Open Networking Foundation <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/atomix/codegen/kubernetes/cmd" | ||
"os" | ||
) | ||
|
||
func main() { | ||
cmd := cmd.GetCommand() | ||
if err := cmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |