enable gitea actions

This commit is contained in:
Aleksandr Trushkin
2024-02-02 18:24:00 +03:00
parent 4ceeba1608
commit d18d1d44dd
9 changed files with 124 additions and 44 deletions

View File

@ -0,0 +1,19 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: linux_arm64
steps:
- run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "This job's status is ${{ job.status }}."

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
database database
bin bin
*.xml *.xml
Makefile

36
buildinfo.go Normal file
View File

@ -0,0 +1,36 @@
package eway
import (
"sync"
"time"
)
var (
version string = "v0.0.0"
commit string = "0000000"
buildTimeStr string
buildTime time.Time
parseOnce sync.Once
)
func Version() string {
return version
}
func Commit() string {
return commit
}
func BuildTime() time.Time {
parseOnce.Do(func() {
if buildTimeStr == "" {
return
}
buildTime, _ = time.Parse(buildTimeStr, time.RFC3339)
})
return buildTime
}

View File

@ -2,8 +2,10 @@ package components
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"os"
"time" "time"
"git.loyso.art/frx/eway/internal/config" "git.loyso.art/frx/eway/internal/config"
@ -40,6 +42,11 @@ func GetLogger() (zerolog.Logger, error) {
func SetupDI(ctx context.Context, cfgpath string) error { func SetupDI(ctx context.Context, cfgpath string) error {
cfg, err := parseSettings(cfgpath) cfg, err := parseSettings(cfgpath)
if err != nil { if err != nil {
// if no settings provided allow cli to run without them.
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err return err
} }
@ -98,6 +105,10 @@ func SetupDI(ctx context.Context, cfgpath string) error {
} }
func Shutdown() error { func Shutdown() error {
if diInjector == nil {
return nil
}
return diInjector.Shutdown() return diInjector.Shutdown()
} }

View File

@ -19,6 +19,7 @@ import (
"strconv" "strconv"
"time" "time"
rooteway "git.loyso.art/frx/eway"
"git.loyso.art/frx/eway/cmd/cli/components" "git.loyso.art/frx/eway/cmd/cli/components"
"git.loyso.art/frx/eway/internal/crypto" "git.loyso.art/frx/eway/internal/crypto"
"git.loyso.art/frx/eway/internal/encoding/fbs" "git.loyso.art/frx/eway/internal/encoding/fbs"
@ -68,23 +69,7 @@ func setupDI() cli.BeforeFunc {
func releaseDI() cli.AfterFunc { func releaseDI() cli.AfterFunc {
return func(ctx context.Context, c *cli.Command) error { return func(ctx context.Context, c *cli.Command) error {
log, err := components.GetLogger()
if err != nil {
return fmt.Errorf("getting logger: %w", err)
}
start := time.Now()
defer func() {
since := time.Since(start)
if err == nil {
return
}
log.Err(err).Dur("elapsed", since).Msg("shutdown finished")
}()
return components.Shutdown() return components.Shutdown()
} }
} }
@ -92,6 +77,7 @@ func setupCLI() *cli.Command {
app := &cli.Command{ app := &cli.Command{
Name: "cli", Name: "cli",
Description: "a cli for running eway logic", Description: "a cli for running eway logic",
Version: fmt.Sprintf("%s (%s) %s", rooteway.Version(), rooteway.Commit(), rooteway.BuildTime()),
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "config", Name: "config",
@ -117,6 +103,12 @@ func setupCLI() *cli.Command {
return app return app
} }
func newVersionCmd() *cli.Command {
return &cli.Command{
Name: "version",
}
}
func newCryptoCmd() *cli.Command { func newCryptoCmd() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "crypto", Name: "crypto",
@ -143,21 +135,6 @@ func newCryptoEncyptCmd() *cli.Command {
} }
} }
func newCryptoDecryptCmd() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt incoming text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Required: true,
},
},
Action: cryptoDeEncryptAction(false),
}
}
func newAppCmd() *cli.Command { func newAppCmd() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "app", Name: "app",
@ -1022,6 +999,7 @@ func testFBSAction(ctx context.Context, c *cli.Command) error {
func appYMLExporterAction(ctx context.Context, cmd *cli.Command) error { func appYMLExporterAction(ctx context.Context, cmd *cli.Command) error {
port := cmd.Int("port") port := cmd.Int("port")
src := cmd.String("src") src := cmd.String("src")
log, err := components.GetLogger() log, err := components.GetLogger()
if err != nil { if err != nil {
return fmt.Errorf("getting logger: %w", err) return fmt.Errorf("getting logger: %w", err)

27
cmd/cli/main_encoff.go Normal file
View File

@ -0,0 +1,27 @@
//go:build !encon
// +build !encon
package main
import (
"context"
"github.com/urfave/cli/v3"
)
func newCryptoDecryptCmd() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt incoming text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Required: true,
},
},
Action: func(context.Context, *cli.Command) error {
return cli.Exit("decryption is turned off", -1)
},
}
}

21
cmd/cli/main_encon.go Normal file
View File

@ -0,0 +1,21 @@
//go:build encon
// +build encon
package main
import "github.com/urfave/cli/v3"
func newCryptoDecryptCmd() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt incoming text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Required: true,
},
},
Action: cryptoDeEncryptAction(false),
}
}

View File

@ -1,6 +1,3 @@
//go:build encon
// +build encon
package crypto package crypto
import ( import (

View File

@ -1,10 +0,0 @@
//go:build !encon
// +build !encon
package crypto
import "git.loyso.art/frx/eway/internal/entity"
func Decrypt(hexedcipher string) (plaintext string, err error) {
return "", entity.SimpleError("this feature turned off")
}