fix: fix publisher is creating wrong urls #25

Merged
marcel.henselin merged 1 commit from fix/releaser_false_url_handling into alpha 2026-01-30 15:35:33 +00:00

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"net/url"
"os" "os"
"path" "path"
"strings" "strings"
@ -18,7 +19,7 @@ type Architecture struct {
ShaSumsUrl string `json:"shasums_url"` ShaSumsUrl string `json:"shasums_url"`
ShaSumsSignatureUrl string `json:"shasums_signature_url"` ShaSumsSignatureUrl string `json:"shasums_signature_url"`
ShaSum string `json:"shasum"` ShaSum string `json:"shasum"`
SigningKeys []SigningKey `json:"signing_keys"` SigningKeys SigningKey `json:"signing_keys"`
} }
type SigningKey struct { type SigningKey struct {
@ -46,14 +47,23 @@ func (p *Provider) CreateArchitectureFiles() error {
pathPrefix := path.Join("release", prefix) pathPrefix := path.Join("release", prefix)
// urlPrefix := fmt.Sprintf("https://%s/%s", domain, prefix) // urlPrefix := fmt.Sprintf("https://%s/%s", domain, prefix)
urlPrefix := path.Join("https://", p.Domain, prefix) urlPrefix, err := url.JoinPath("https://", p.Domain, prefix)
if err != nil {
return fmt.Errorf("error creating base url: %w", err)
}
// download url = https://example.com/v1/providers/namespace/provider/0.0.1/download/terraform-provider_0.0.1_darwin_amd64.zip // download url = https://example.com/v1/providers/namespace/provider/0.0.1/download/terraform-provider_0.0.1_darwin_amd64.zip
downloadUrlPrefix := path.Join(urlPrefix, "download") downloadUrlPrefix, err := url.JoinPath(urlPrefix, "download")
if err != nil {
return fmt.Errorf("error crearting download url: %w", err)
}
downloadPathPrefix := path.Join(pathPrefix, "download") downloadPathPrefix := path.Join(pathPrefix, "download")
// shasums url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS // shasums url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS
shasumsUrl := path.Join(urlPrefix, fmt.Sprintf("%s_%s_SHA256SUMS", p.RepoName, p.Version)) shasumsUrl, err := url.JoinPath(urlPrefix, fmt.Sprintf("%s_%s_SHA256SUMS", p.RepoName, p.Version))
if err != nil {
return fmt.Errorf("error creating shasums url: %w", err)
}
// shasums_signature_url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS.sig // shasums_signature_url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS.sig
shasumsSigUrl := shasumsUrl + ".sig" shasumsSigUrl := shasumsUrl + ".sig"
@ -67,7 +77,10 @@ func (p *Provider) CreateArchitectureFiles() error {
return err return err
} }
for _, sum := range shaSums { for _, sum := range shaSums {
downloadUrl := path.Join(downloadUrlPrefix, sum.Path) downloadUrl, err := url.JoinPath(downloadUrlPrefix, sum.Path)
if err != nil {
return fmt.Errorf("error creating url: %w", err)
}
// get os and arch from filename // get os and arch from filename
removeFileExtension := strings.Split(sum.Path, ".zip") removeFileExtension := strings.Split(sum.Path, ".zip")
@ -89,12 +102,10 @@ func (p *Provider) CreateArchitectureFiles() error {
ShaSumsUrl: shasumsUrl, ShaSumsUrl: shasumsUrl,
ShaSumsSignatureUrl: shasumsSigUrl, ShaSumsSignatureUrl: shasumsSigUrl,
ShaSum: sum.Sum, ShaSum: sum.Sum,
SigningKeys: []SigningKey{}, SigningKeys: SigningKey{},
} }
a.SigningKeys = append( a.SigningKeys = SigningKey{
a.SigningKeys,
SigningKey{
GpgPublicKeys: []GpgPublicKey{ GpgPublicKeys: []GpgPublicKey{
{ {
KeyId: p.GpgFingerprint, KeyId: p.GpgFingerprint,
@ -104,8 +115,7 @@ func (p *Provider) CreateArchitectureFiles() error {
SourceUrl: "", SourceUrl: "",
}, },
}, },
}, }
)
// var architectureTemplate = []byte(fmt.Sprintf(` // var architectureTemplate = []byte(fmt.Sprintf(`
//{ //{
// "protocols": [ // "protocols": [
@ -136,7 +146,7 @@ func (p *Provider) CreateArchitectureFiles() error {
log.Printf(" - Arch file: %s", archFileName) log.Printf(" - Arch file: %s", archFileName)
err := WriteArchitectureFile(archFileName, a) err = WriteArchitectureFile(archFileName, a)
if err != nil { if err != nil {
return err return err
} }