Skip to content

Commit

Permalink
ci: add release.yml for the gha
Browse files Browse the repository at this point in the history
Signed-off-by: saltbo <[email protected]>
  • Loading branch information
saltbo committed Mar 24, 2023
1 parent da6e134 commit c3f36e4
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
# 并将其链接到词根库

# 统计单词量、词根数以及词根覆盖度
name: release

on:
push:
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: release

on:
push:
# run only against tags
tags:
- '*'

permissions:
contents: write
packages: write
# issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: stable
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# Dependency directories (remove the comment below to include it)
# vendor/

data
data
build
24 changes: 24 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dist: ./build/release
before:
hooks:
- go mod download
builds:
- id: server
main: ./main.go
binary: bin/{{ .ProjectName }}
ldflags:
- -s -w
- -X github.com/bonaysoft/{{ .ProjectName }}/cmd.release={{.Version}}
- -X github.com/bonaysoft/{{ .ProjectName }}/cmd.commit={{.Commit}}
- -X github.com/bonaysoft/{{ .ProjectName }}/cmd.repo={{.GitURL}}
goos:
- linux
goarch:
- amd64

dockers:
- image_templates:
- "ghcr.io/bonaysoft/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}"
- "ghcr.io/bonaysoft/{{ .ProjectName }}:latest"
extra_files:
- dict/roots
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian:10

ENV APP_HOME /srv
WORKDIR $APP_HOME

COPY engra $APP_HOME
COPY dict $APP_HOME/dict

CMD ["./engra", "serve"]
13 changes: 2 additions & 11 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,15 @@ THE SOFTWARE.
package cmd

import (
"fmt"

"github.com/bonaysoft/engra/pkg/serve"
"github.com/spf13/cobra"
)

// serveCmd represents the serve command
var serveCmd = &cobra.Command{
Use: "serve",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("serve called")
},
RunE: serve.Run,
}

func init() {
Expand Down
11 changes: 5 additions & 6 deletions pkg/serve/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package serve

import (
"log"
Expand All @@ -9,27 +9,26 @@ import (
"github.com/99designs/gqlgen/graphql/playground"
"github.com/bonaysoft/engra/apis/graph"
"github.com/bonaysoft/engra/pkg/dict"
"github.com/spf13/cobra"
)

const defaultPort = "8081"

func main() {
func Run(cmd *cobra.Command, args []string) error {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}

dicts, err := dict.NewDict()
if err != nil {
log.Fatalln(err)
return
return err
}

srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{Dict: dicts}}))

http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", srv)

log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
return http.ListenAndServe(":"+port, nil)
}

0 comments on commit c3f36e4

Please sign in to comment.