Skip to content

Commit

Permalink
feat: add configuration option to enable version overwrites (opt-in)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadilas committed Oct 10, 2021
1 parent bc41cf5 commit c38ee6f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
31 changes: 1 addition & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,4 @@ jobs:
push: true
build-args: TARGET=registry
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
changelog:
name: Generate changelog
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.release.outputs.RELEASE_BODY }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Generate a changelog
uses: orhun/git-cliff-action@v1
id: git-cliff
with:
config: cliff.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGES.md

- name: Set the release body
id: release
shell: bash
run: |
r=$(cat ${{ steps.git-cliff.outputs.changelog }})
r="${r//'%'/'%25'}" # Multiline escape sequences for %
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
echo "::set-output name=RELEASE_BODY::$r"
labels: ${{ steps.meta.outputs.labels }}
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ permissions:
contents: write

jobs:
changelog:
name: Generate changelog
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.release.outputs.RELEASE_BODY }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Generate a changelog
uses: orhun/git-cliff-action@v1
id: git-cliff
with:
config: cliff.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGES.md

- name: Set the release body
id: release
shell: bash
run: |
r=$(cat ${{ steps.git-cliff.outputs.changelog }})
r="${r//'%'/'%25'}" # Multiline escape sequences for %
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
echo "::set-output name=RELEASE_BODY::$r"
goreleaser:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var upCmd = &cobra.Command{
}
logrus.Infof("Using reverse proxy for content with address: %s", reverseProxyAddr)
registry := registry.New(moduleStorage)
server := rpc.NewServer(registry, reverseProxyAddr)
server := rpc.NewServer(registry, reverseProxyAddr, rpc.Opts{})

twirpHandler := moarpb.NewModuleRegistryServer(server, twirp.WithServerPathPrefix(""))
tracedHandler := apmhttp.Wrap(twirpHandler)
Expand Down
20 changes: 15 additions & 5 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ type ModuleRegistry interface {
}

type Server struct {
registry ModuleRegistry
reverseProxy string
logger *logrus.Entry
registry ModuleRegistry
reverseProxy string
logger *logrus.Entry
versionOverwriteEnabled bool
}

func NewServer(registry ModuleRegistry, reverseProxy string) *Server {
return &Server{registry: registry, logger: logrus.WithField("op", "server"), reverseProxy: reverseProxy}
type Opts struct {
VersionOverwriteEnabled bool
}

func NewServer(registry ModuleRegistry, reverseProxy string, opts Opts) *Server {
return &Server{
registry: registry,
logger: logrus.WithField("op", "server"),
reverseProxy: reverseProxy,
versionOverwriteEnabled: opts.VersionOverwriteEnabled,
}
}

func (s *Server) Shutdown() {
Expand Down
4 changes: 2 additions & 2 deletions rpc/upload_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (s *Server) UploadVersion(ctx context.Context, request *moarpb.UploadVersio
return nil, twirp.WrapError(twirp.NotFoundError("module not found: "+request.ModuleName), err)
}

if module.HasVersion(newVersion) {
return nil, twirp.InvalidArgumentError("version", "upload not possible: version already exists")
if module.HasVersion(newVersion) && !s.versionOverwriteEnabled {
return nil, twirp.InvalidArgumentError("version", "overwrite disabled: version already exists")
}
var files []internal.File
for _, file := range request.Files {
Expand Down

0 comments on commit c38ee6f

Please sign in to comment.