Skip to content

Commit

Permalink
Merge pull request #37 from traPtitech/config-revamp
Browse files Browse the repository at this point in the history
Config revamp
  • Loading branch information
motoki317 authored Apr 25, 2024
2 parents e2ed0d9 + e17d8e8 commit 1e8b846
Show file tree
Hide file tree
Showing 24 changed files with 889 additions and 885 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
name: Mod
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"
- run: go mod download
Expand All @@ -20,8 +20,8 @@ jobs:
env:
CGO_ENABLED: "0"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"
- run: go build
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v5
with:
args: release --clean
env:
Expand All @@ -33,29 +33,29 @@ jobs:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set IMAGE_TAG env
run: echo "IMAGE_TAG=$(echo ${GITHUB_REF:11})" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Show available platforms
run: echo ${{ steps.buildx.outputs.platforms }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: traptitech
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ builds:
ldflags:
- -s
- -w
- -X main.version={{.Version}}
- -X pkg.utils.version={{.Version}}
goos:
- darwin
- linux
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1-alpine AS builder

ENV CGO_ENABLED 0

Expand All @@ -16,9 +16,9 @@ ARG TARGETARCH
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
go build -o /dev-ops-bot -ldflags="-s -w -X main.version=$VERSION" .
go build -o /dev-ops-bot -ldflags="-s -w -X pkg.utils.version=$VERSION" .

FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS installer
FROM --platform=$BUILDPLATFORM golang:1-alpine AS installer

ENV CGO_ENABLED 0
ARG TARGETOS
Expand Down
98 changes: 0 additions & 98 deletions bot.go

This file was deleted.

46 changes: 46 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/traPtitech/DevOpsBot/pkg/bot"
"github.com/traPtitech/DevOpsBot/pkg/utils"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "DevOpsBot",
Short: "A traQ bot for DevOps command execution",
PreRun: func(cmd *cobra.Command, args []string) {
fmt.Printf("DevOpsBot v%s initializing\n", utils.Version())
},
RunE: func(cmd *cobra.Command, args []string) error {
return bot.Run()
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
rootCmd.AddCommand(serverCmd)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.DevOpsBot.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
20 changes: 20 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/traPtitech/DevOpsBot/pkg/server"
)

var serverCmd = &cobra.Command{
Use: "server",
Short: "ConoHa server manipulation",
SilenceUsage: true, // Do not display command usage when RunE returns error
RunE: func(cmd *cobra.Command, args []string) error {
s, err := server.Compile()
if err != nil {
return err
}
return s.Execute(args)
},
}
117 changes: 0 additions & 117 deletions config.go

This file was deleted.

Loading

0 comments on commit 1e8b846

Please sign in to comment.