Skip to content

Commit fde3c4d

Browse files
committed
feature(main): add init commit
Signed-off-by: cuisongliu <[email protected]>
1 parent 05c47d9 commit fde3c4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3996
-0
lines changed

.github/gh-bot.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: v1
2+
debug: true
3+
type: action
4+
action:
5+
printConfig: true
6+
release:
7+
retry: 15s
8+
actionName: Release
9+
allowOps:
10+
- cuisongliu
11+
bot:
12+
prefix: /
13+
spe: _
14+
allowOps:
15+
- sealos-ci-robot
16+
- sealos-release-robot
17+
18+
username: sealos-ci-robot
19+
repo:
20+
org: false
21+
22+
message:
23+
success: |
24+
🤖 says: Hooray! The action {{.Body}} has been completed successfully. 🎉
25+
format_error: |
26+
🤖 says: ‼️ There is a formatting issue with the action, kindly verify the action's format.
27+
permission_error: |
28+
🤖 says: ‼️ The action doesn't have permission to trigger.
29+
release_error: |
30+
🤖 says: ‼️ Release action failed.
31+
Error details: {{.Error}}
32+

.github/workflows/bot.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Github Rebot
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
env:
7+
GH_TOKEN: "${{ secrets.GH_PAT }}"
8+
GH_REBOT_VERSION: "v0.0.5"
9+
jobs:
10+
comment:
11+
if: startswith(github.event.comment.body, '/')
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout the latest code
15+
uses: actions/checkout@v3
16+
- name: Gh Rebot for Sealos
17+
uses: labring/[email protected]
18+
with:
19+
version: v0.0.7-rc1
20+
env:
21+
SEALOS_TYPE: "/comment"
22+
GH_TOKEN: "${{ secrets.GH_PAT }}"

.github/workflows/go.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: GO
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ "main" ]
7+
pull_request:
8+
branches: [ "*" ]
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up Go 1.x
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: 1.20.x
18+
19+
- name: Check out code into the Go module directory
20+
uses: actions/checkout@v2
21+
22+
- name: Run GoReleaser
23+
uses: goreleaser/goreleaser-action@v1
24+
with:
25+
version: latest
26+
args: build --snapshot --clean --timeout=1h
27+
- name: Copy file
28+
run: |
29+
cp dist/sreg_linux_amd64_v1/sreg sreg
30+
chmod a+x sreg
31+
sreg version

.github/workflows/release.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- '**'
7+
tags:
8+
- '*'
9+
10+
jobs:
11+
goreleaser:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Go 1.x
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: 1.20.x
23+
24+
- name: Get previous tag
25+
id: previoustag
26+
run: |
27+
PREVIOUS_TAG=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
28+
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
29+
30+
- name: Display previous tag
31+
run: |
32+
echo "Previous tag: ${{ steps.previoustag.outputs.PREVIOUS_TAG }}"
33+
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@master
37+
with:
38+
go-version: 1.20.x
39+
- name: Prepare
40+
id: prepare
41+
run: |
42+
TAG=${GITHUB_REF#refs/tags/}
43+
echo tag_name=${TAG} >> $GITHUB_OUTPUT
44+
- name: Run GoReleaser
45+
uses: goreleaser/goreleaser-action@v4
46+
with:
47+
args: release --timeout=1h --debug
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

.goreleaser.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
before:
2+
hooks:
3+
# You may remove this if you don't use go modules.
4+
- go mod download
5+
# you may remove this if you don't need go generate
6+
- go generate ./...
7+
builds:
8+
- id: gh-rebot
9+
env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
goarch:
14+
- amd64
15+
- arm64
16+
ldflags:
17+
- -s -w
18+
- -X github.com/labring/sreg/pkg/version.gitVersion={{.Version}}
19+
- -X github.com/labring/sreg/pkg/version.gitCommit={{.ShortCommit}}
20+
- -X github.com/labring/sreg/pkg/version.buildDate={{.Date}}
21+
22+
23+
checksum:
24+
name_template: 'checksums.txt'
25+
snapshot:
26+
name_template: "{{ .Tag }}-next"
27+
changelog:
28+
sort: asc
29+
use: github
30+
filters:
31+
exclude:
32+
- '^test:'
33+
- '^chore'
34+
- 'merge conflict'
35+
- Merge pull request
36+
- Merge remote-tracking branch
37+
- Merge branch
38+
- go mod tidy
39+
groups:
40+
- title: Dependency updates
41+
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
42+
order: 300
43+
- title: 'New Features'
44+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
45+
order: 100
46+
- title: 'Security updates'
47+
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
48+
order: 150
49+
- title: 'Bug fixes'
50+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
51+
order: 200
52+
- title: 'Documentation updates'
53+
regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$
54+
order: 400
55+
- title: 'Build process updates'
56+
regexp: ^.*?build(\([[:word:]]+\))??!?:.+$
57+
order: 400
58+
- title: Other work
59+
order: 9999
60+
61+
release:
62+
prerelease: auto

cmd/root.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright © 2021 sealos.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
"github.com/labring/sreg/pkg/registry/commands"
20+
"github.com/labring/sreg/pkg/utils/logger"
21+
"os"
22+
23+
"github.com/spf13/cobra"
24+
)
25+
26+
var (
27+
debug bool
28+
)
29+
30+
// rootCmd represents the base command when called without any subcommands
31+
var rootCmd = &cobra.Command{
32+
Use: "sreg",
33+
Short: "sealos registry related",
34+
// Uncomment the following line if your bare application
35+
// has an action associated with it:
36+
// Run: func(cmd *cobra.Command, args []string) { },
37+
}
38+
39+
// Execute adds all child commands to the root command and sets flags appropriately.
40+
// This is called by main.main(). It only needs to happen once to the rootCmd.
41+
func Execute() {
42+
if err := rootCmd.Execute(); err != nil {
43+
if rootCmd.SilenceErrors {
44+
fmt.Fprintln(os.Stderr, err)
45+
}
46+
os.Exit(1)
47+
}
48+
}
49+
50+
func init() {
51+
cobra.OnInitialize(func() {
52+
logger.CfgConsoleLogger(debug, false)
53+
})
54+
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logger")
55+
56+
}
57+
58+
func init() {
59+
examplePrefix := rootCmd.Name()
60+
rootCmd.AddCommand(commands.NewServeRegistryCommand())
61+
rootCmd.AddCommand(commands.NewRegistryImageSaveCmd(examplePrefix))
62+
rootCmd.AddCommand(commands.NewSyncRegistryCommand(examplePrefix))
63+
rootCmd.AddCommand(commands.NewCopyRegistryCommand(examplePrefix))
64+
}

cmd/version.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright © 2021 sealos.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"encoding/json"
19+
"fmt"
20+
"github.com/labring/sreg/pkg/version"
21+
22+
"github.com/spf13/cobra"
23+
)
24+
25+
var shortPrint bool
26+
27+
func newVersionCmd() *cobra.Command {
28+
var versionCmd = &cobra.Command{
29+
Use: "version",
30+
Short: "version",
31+
Args: cobra.NoArgs,
32+
Example: `sealctl version`,
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
marshalled, err := json.Marshal(version.Get())
35+
if err != nil {
36+
return err
37+
}
38+
if shortPrint {
39+
fmt.Println(version.Get().String())
40+
} else {
41+
fmt.Println(string(marshalled))
42+
}
43+
return nil
44+
},
45+
}
46+
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
47+
return versionCmd
48+
}
49+
50+
func init() {
51+
rootCmd.AddCommand(newVersionCmd())
52+
}

0 commit comments

Comments
 (0)