diff --git a/.github/workflows/generate_changelogs.sh b/.github/workflows/generate_changelogs.sh deleted file mode 100644 index 455579e6..00000000 --- a/.github/workflows/generate_changelogs.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# set -x - -echo "## CHANGELOGS" - -last_commit=$(curl -s https://api.github.com/repos/EverythingSuckz/TG-FileStreamBot/tags | jq -r '.[0].commit.sha') - -resp=$(curl -s https://api.github.com/repos/EverythingSuckz/TG-FileStreamBot/commits?per_page=5) -data=$(echo "${resp}" | jq -c '.[]') -while read -r i; do - if [[ $i == $last_commit ]]; then - break - fi - sha=$(echo $i | jq -r '.sha') - message=$(echo $i | jq -r '.commit.message' | tr '\n' ' ') - commit_url=$(echo $i | jq -r '.html_url') - author_name=$(echo $i | jq -r '.commit.author.name') - author_url=$(echo $i | jq -r '.author.html_url') - echo "- [$(echo $sha | cut -c1-7)]($commit_url) - $message by [$author_name]($author_url)" -done <<< "$data" - -if [[ ! -z "$last_commit" ]]; then - last_commit="main" -fi - -compare_url="https://github.com/EverythingSuckz/TG-FileStreamBot/compare/$(echo $resp | jq -r '.[0].sha')...$last_commit" -echo -e "- [.....]($compare_url)\n\nView Full Changelogs [here]($compare_url)" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0c9de8bc..0f0480f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,32 +1,38 @@ -name: Release +name: Goreleaser + on: - workflow_dispatch: push: + tags: + - "*" +permissions: + contents: write jobs: - Release: - if: "contains(github.event.head_commit.message, 'Bump version')" - runs-on: ubuntu-22.04 + goreleaser: + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - - name: Setup ENV - run: echo "VERSION=$(echo ${{ github.event.head_commit.message }} | sed -r 's/Bump\s+version\s+?(to\s+?)?`?v?([a-z0-9.\-_]+)`?$/\2/')" >> $GITHUB_ENV - - name: Generate CHANGELOGS - run: | - chmod +x .github/workflows/generate_changelogs.sh - ./.github/workflows/generate_changelogs.sh > CHANGELOGS.md - - name: Package Server - run: | - rm -fr .vscode .git* - zip -r ${{ github.WORKSPACE }}/TG-FileStreamBot-v${{ env.VERSION }}-main.zip * - - name: Release - uses: softprops/action-gh-release@v1 with: - name: TG-FileStreamBot-v${{ env.VERSION }} (main) - body_path: CHANGELOGS.md - files: | - ${{ github.WORKSPACE }}/TG-FileStreamBot-v${{ env.VERSION }}-main.zip - prerelease: false - tag_name: v${{ env.VERSION }} + fetch-depth: 0 + - run: git fetch --force --tags + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + - name: Import GPG key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..523bfda4 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,49 @@ +version: 1 + +project_name: TG-FileStreamBot + +before: + hooks: + - go mod tidy + - go generate ./... + +builds: + - main: ./cmd/fsb/main.go + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + +archives: + - format: tar.gz + name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}" + format_overrides: + - goos: windows + format: zip + +signs: + - artifacts: checksum + cms: gpg2 + args: + - "--batch" + - "-u" + - "{{ .Env.GPG_FINGERPRINT }}" + - "--output" + - "${signature}" + - "--detach-sign" + - "${artifact}" + +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/.vscode/launch.json b/.vscode/launch.json index 6deb9a6b..805ef73b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "main.go" + "program": "./cmd/fsb/main.go", } ] } \ No newline at end of file diff --git a/main.go b/cmd/fsb/main.go similarity index 84% rename from main.go rename to cmd/fsb/main.go index c1db528b..c9b32fc2 100644 --- a/main.go +++ b/cmd/fsb/main.go @@ -1,12 +1,12 @@ package main import ( - "EverythingSuckz/fsb/bot" - "EverythingSuckz/fsb/cache" "EverythingSuckz/fsb/config" - "EverythingSuckz/fsb/routes" - "EverythingSuckz/fsb/types" - "EverythingSuckz/fsb/utils" + "EverythingSuckz/fsb/internal/bot" + "EverythingSuckz/fsb/internal/cache" + "EverythingSuckz/fsb/internal/routes" + "EverythingSuckz/fsb/internal/types" + "EverythingSuckz/fsb/internal/utils" "fmt" "net/http" "time" @@ -15,7 +15,7 @@ import ( "go.uber.org/zap" ) -const versionString = "v0.0.0" +const versionString = "3.0.0-alpha1" var startTime time.Time = time.Now() diff --git a/config/config.go b/config/config.go index 6bde978b..bccad093 100644 --- a/config/config.go +++ b/config/config.go @@ -2,12 +2,15 @@ package config import ( "os" + "path" + "path/filepath" "reflect" "regexp" + "runtime" "strconv" "strings" - _ "github.com/joho/godotenv/autoload" + "github.com/joho/godotenv" "github.com/kelseyhightower/envconfig" "go.uber.org/zap" ) @@ -15,14 +18,14 @@ import ( var ValueOf = &config{} type config struct { - ApiID int32 `envconfig:"API_ID" required:"true"` - ApiHash string `envconfig:"API_HASH" required:"true"` - BotToken string `envconfig:"BOT_TOKEN" required:"true"` - LogChannelID int64 `envconfig:"LOG_CHANNEL" required:"true"` - Dev bool `envconfig:"DEV" default:"false"` - Port int `envconfig:"PORT" default:"8080"` - Host string `envconfig:"HOST" default:"http://localhost:8080"` - HashLength int `envconfig:"HASH_LENGTH" default:"6"` + ApiID int32 `envconfig:"API_ID" required:"true"` + ApiHash string `envconfig:"API_HASH" required:"true"` + BotToken string `envconfig:"BOT_TOKEN" required:"true"` + LogChannelID int64 `envconfig:"LOG_CHANNEL" required:"true"` + Dev bool `envconfig:"DEV" default:"false"` + Port int `envconfig:"PORT" default:"8080"` + Host string `envconfig:"HOST" default:"http://localhost:8080"` + HashLength int `envconfig:"HASH_LENGTH" default:"6"` UseSessionFile bool `envconfig:"USE_SESSION_FILE" default:"true"` MultiTokens []string } @@ -30,7 +33,12 @@ type config struct { var botTokenRegex = regexp.MustCompile(`MULTI\_TOKEN[\d+]=(.*)`) func (c *config) setupEnvVars() { - err := envconfig.Process("", c) + envPath := filepath.Join(callerDir(), "fsb.env") + err := godotenv.Load(envPath) + if err != nil { + panic(err) + } + err = envconfig.Process("", c) if err != nil { panic(err) } @@ -79,3 +87,9 @@ func abs(x int) int { } return x } + +func callerDir() string { + _, b, _, _ := runtime.Caller(0) + d := path.Join(path.Dir(b)) + return filepath.Dir(d) +} diff --git a/bot/client.go b/internal/bot/client.go similarity index 94% rename from bot/client.go rename to internal/bot/client.go index bf885cf9..111fca0b 100644 --- a/bot/client.go +++ b/internal/bot/client.go @@ -1,7 +1,7 @@ package bot import ( - "EverythingSuckz/fsb/commands" + "EverythingSuckz/fsb/internal/commands" "EverythingSuckz/fsb/config" "go.uber.org/zap" diff --git a/bot/workers.go b/internal/bot/workers.go similarity index 100% rename from bot/workers.go rename to internal/bot/workers.go diff --git a/cache/cache.go b/internal/cache/cache.go similarity index 97% rename from cache/cache.go rename to internal/cache/cache.go index 772503f2..935c3ec6 100644 --- a/cache/cache.go +++ b/internal/cache/cache.go @@ -1,7 +1,7 @@ package cache import ( - "EverythingSuckz/fsb/types" + "EverythingSuckz/fsb/internal/types" "bytes" "encoding/gob" "sync" diff --git a/commands/commands.go b/internal/commands/commands.go similarity index 100% rename from commands/commands.go rename to internal/commands/commands.go diff --git a/commands/start.go b/internal/commands/start.go similarity index 100% rename from commands/start.go rename to internal/commands/start.go diff --git a/commands/stream.go b/internal/commands/stream.go similarity index 98% rename from commands/stream.go rename to internal/commands/stream.go index 026073b5..d8063eea 100644 --- a/commands/stream.go +++ b/internal/commands/stream.go @@ -4,7 +4,7 @@ import ( "fmt" "EverythingSuckz/fsb/config" - "EverythingSuckz/fsb/utils" + "EverythingSuckz/fsb/internal/utils" "github.com/celestix/gotgproto/dispatcher" "github.com/celestix/gotgproto/dispatcher/handlers" diff --git a/routes/routes.go b/internal/routes/routes.go similarity index 100% rename from routes/routes.go rename to internal/routes/routes.go diff --git a/routes/stream.go b/internal/routes/stream.go similarity index 97% rename from routes/stream.go rename to internal/routes/stream.go index 2fbaf277..5e900366 100644 --- a/routes/stream.go +++ b/internal/routes/stream.go @@ -1,8 +1,8 @@ package routes import ( - "EverythingSuckz/fsb/bot" - "EverythingSuckz/fsb/utils" + "EverythingSuckz/fsb/internal/bot" + "EverythingSuckz/fsb/internal/utils" "fmt" "io" "net/http" diff --git a/types/file.go b/internal/types/file.go similarity index 100% rename from types/file.go rename to internal/types/file.go diff --git a/types/response.go b/internal/types/response.go similarity index 100% rename from types/response.go rename to internal/types/response.go diff --git a/utils/hashing.go b/internal/utils/hashing.go similarity index 92% rename from utils/hashing.go rename to internal/utils/hashing.go index 8a018cf2..4e128235 100644 --- a/utils/hashing.go +++ b/internal/utils/hashing.go @@ -2,7 +2,7 @@ package utils import ( "EverythingSuckz/fsb/config" - "EverythingSuckz/fsb/types" + "EverythingSuckz/fsb/internal/types" ) func PackFile(fileName string, fileSize int64, mimeType string, fileID int64) string { diff --git a/utils/helpers.go b/internal/utils/helpers.go similarity index 97% rename from utils/helpers.go rename to internal/utils/helpers.go index ac0022e9..3be2210d 100644 --- a/utils/helpers.go +++ b/internal/utils/helpers.go @@ -1,9 +1,9 @@ package utils import ( - "EverythingSuckz/fsb/cache" "EverythingSuckz/fsb/config" - "EverythingSuckz/fsb/types" + "EverythingSuckz/fsb/internal/cache" + "EverythingSuckz/fsb/internal/types" "context" "errors" "fmt" diff --git a/utils/logger.go b/internal/utils/logger.go similarity index 100% rename from utils/logger.go rename to internal/utils/logger.go diff --git a/utils/reader.go b/internal/utils/reader.go similarity index 100% rename from utils/reader.go rename to internal/utils/reader.go diff --git a/utils/time_format.go b/internal/utils/time_format.go similarity index 100% rename from utils/time_format.go rename to internal/utils/time_format.go