From 16a8cb01d450d136b1f010aca5616fef9a5998d4 Mon Sep 17 00:00:00 2001 From: ajmandourah Date: Sat, 12 Oct 2024 23:07:33 +0300 Subject: [PATCH] fix: Bazarr-sync would not work with subpath addresses --- .github/workflows/docker.yml | 56 ++++++++++++++++++++++++++++++++ .github/workflows/goreleaser.yml | 31 ++++++++++++++++++ internal/config/config.go | 13 ++++++-- 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/goreleaser.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..30de9d6 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,56 @@ +name: Create and publish a Docker image + +on: + workflow_dispatch: + push: + tags: + - v* + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v41.0.0 + with: + files: | + go.* + **/*.go + + - name: Log in to the Container registry + if: steps.changed-files.outputs.any_changed == 'true' + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.CR_PAT }} + + - name: Extract metadata (tags, labels) for Docker + if: steps.changed-files.outputs.any_changed == 'true' + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + if: steps.changed-files.outputs.any_changed == 'true' + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..696f046 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,31 @@ +name: goreleaser + +on: + workflow_dispatch: + push: + tags: + - v* + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: false + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/internal/config/config.go b/internal/config/config.go index 32ff13a..13a5588 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,6 +4,7 @@ import ( "fmt" "net/url" "os" + "strings" "github.com/spf13/viper" ) @@ -42,9 +43,17 @@ func InitConfig() { os.Exit(1) } viper.Unmarshal(&cfg) + var ( + baseUrl string + err error + ) + //this is a check in case the Address is a subpath + if strings.Contains(cfg.Address,"/") { + baseUrl, err = url.JoinPath(cfg.Protocol + "://" + cfg.Address) + }else { + baseUrl, err = url.JoinPath(cfg.Protocol + "://" + cfg.Address + ":" + cfg.Port) + } - //Bazarr url - baseUrl, err := url.JoinPath(cfg.Protocol + "://" + cfg.Address + ":" + cfg.Port) if err != nil{ fmt.Fprintln(os.Stderr, "URL Error: ", err) }