Skip to content

Commit

Permalink
Merge branch 'main' into dotnomad/remove-temp-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
dotNomad authored Dec 8, 2023
2 parents 21fd9d4 + 51bbfb9 commit 7d440a5
Show file tree
Hide file tree
Showing 40 changed files with 609 additions and 210 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/archive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Archive
on:
workflow_call:
jobs:
archive:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/setup
- uses: actions/download-artifact@v3
with:
name: bin
path: bin
- run: chmod -R +x ./bin
- run: just archive
- uses: actions/upload-artifact@v3
id: upload
with:
name: archives
path: archives/**/*
22 changes: 14 additions & 8 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@ on:
branches:
- main
jobs:
# Unit Tests
agent:
uses: ./.github/workflows/agent.yaml
web:
uses: ./.github/workflows/web.yaml
jupyterlab:
uses: ./.github/workflows/jupyterlab.yaml
vscode:
uses: ./.github/workflows/vscode.yaml

# Build
build:
uses: ./.github/workflows/build.yaml
package:
uses: ./.github/workflows/package.yaml
archive:
needs: build
uses: ./.github/workflows/archive.yaml

# Integration Tests
bats:
needs: build
uses: ./.github/workflows/bats.yaml
cypress:
needs: build
uses: ./.github/workflows/ui.yaml
package:
uses: ./.github/workflows/package.yaml

# Extensions
jupyterlab:
uses: ./.github/workflows/jupyterlab.yaml
vscode:
uses: ./.github/workflows/vscode.yaml
22 changes: 14 additions & 8 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
jobs:
# Unit Tests
agent:
uses: ./.github/workflows/agent.yaml
web:
uses: ./.github/workflows/web.yaml
jupyterlab:
uses: ./.github/workflows/jupyterlab.yaml
vscode:
uses: ./.github/workflows/vscode.yaml

# Build
build:
uses: ./.github/workflows/build.yaml
package:
uses: ./.github/workflows/package.yaml
archive:
needs: build
uses: ./.github/workflows/archive.yaml

# Integration Tests
bats:
needs: build
uses: ./.github/workflows/bats.yaml
cypress:
needs: build
uses: ./.github/workflows/ui.yaml
package:
uses: ./.github/workflows/package.yaml

# Extensions
jupyterlab:
uses: ./.github/workflows/jupyterlab.yaml
vscode:
uses: ./.github/workflows/vscode.yaml
13 changes: 8 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ jobs:
uses: ./.github/workflows/build.yaml
package:
uses: ./.github/workflows/package.yaml
archive:
needs:
- build
uses: ./.github/workflows/archive.yaml
release:
runs-on: ubuntu-latest
needs:
- build
- archive
- package
steps:
- uses: actions/checkout@v3
Expand All @@ -20,13 +24,12 @@ jobs:
- uses: extractions/setup-just@v1
- uses: actions/download-artifact@v3
with:
name: bin
path: bin
name: archives
path: archives
- uses: actions/download-artifact@v3
with:
name: packages
path: packages
- run: chmod -R +x ./bin ./packages
- id: get-prerelease
run: echo "prerelease=$(just pre-release)" >> "$GITHUB_OUTPUT"
- name: Release
Expand All @@ -35,5 +38,5 @@ jobs:
draft: false
prerelease: ${{ steps.get-prerelease.outputs.prerelease == 'true' }}
files: |
bin/**/*
archives/**/*
packages/**/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.cache/
cover.out

archives/
bin/
certs/
packages/
Expand Down
15 changes: 11 additions & 4 deletions cmd/publisher/commands/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type PublishCmd struct {
Path util.Path `help:"Path to directory containing files to publish." arg:"" default:"."`
AccountName string `name:"account" short:"n" help:"Nickname of destination publishing account."`
ConfigName string `name:"config" short:"c" help:"Configuration name (in .posit/publish/)"`
TargetID string `name:"update" short:"u" help:"ID of deployment to update (in .posit/deployments/)"`
TargetName string `name:"update" short:"u" help:"Name of deployment to update (in .posit/deployments/)"`
SaveName string `name:"save-name" short:"s" help:"Save deployment with this name (in .posit/deployments/)"`
Account *accounts.Account `kong:"-"`
Config *config.Config `kong:"-"`
Target *deployment.Deployment `kong:"-"`
Expand All @@ -29,12 +30,18 @@ type PublishCmd struct {
var errNoAccounts = errors.New("there are no accounts yet; register an account before publishing")

func (cmd *PublishCmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error {
if cmd.SaveName != "" {
err := util.ValidateFilename(cmd.SaveName)
if err != nil {
return err
}
}
err := initialize.InitIfNeeded(cmd.Path, cmd.ConfigName, ctx.Logger)
if err != nil {
return err
}
cmd.TargetID = strings.TrimSuffix(cmd.TargetID, ".toml")
stateStore, err := state.New(cmd.Path, cmd.AccountName, cmd.ConfigName, cmd.TargetID, ctx.Accounts)
cmd.TargetName = strings.TrimSuffix(cmd.TargetName, ".toml")
stateStore, err := state.New(cmd.Path, cmd.AccountName, cmd.ConfigName, cmd.TargetName, cmd.SaveName, ctx.Accounts)
if err != nil {
return err
}
Expand All @@ -45,7 +52,7 @@ func (cmd *PublishCmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext
"Publish",
"configuration", stateStore.ConfigName,
"account", stateStore.AccountName,
"target", stateStore.TargetID)
"target", stateStore.TargetName)
publisher := publish.NewFromState(stateStore)
return publisher.PublishDirectory(ctx.Logger)
}
2 changes: 1 addition & 1 deletion cmd/publisher/commands/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (cmd *PublishUICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIConte
if err != nil {
return err
}
stateStore, err := state.New(cmd.Path, "", config.DefaultConfigName, "", ctx.Accounts)
stateStore, err := state.New(cmd.Path, "", config.DefaultConfigName, "", "", ctx.Accounts)
if err != nil {
return err
}
Expand Down
44 changes: 22 additions & 22 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ type Environment = map[string]string

type Python struct {
Version string `toml:"version" json:"version"`
PackageFile string `toml:"package-file" json:"package-file"`
PackageManager string `toml:"package-manager" json:"package-manager"`
PackageFile string `toml:"package-file" json:"packageFile"`
PackageManager string `toml:"package-manager" json:"packageManager"`
}

type R struct {
Version string `toml:"version" json:"version"`
PackageFile string `toml:"package-file" json:"package-file"`
PackageManager string `toml:"package-manager" json:"package-manager"`
PackageFile string `toml:"package-file" json:"packageFile"`
PackageManager string `toml:"package-manager" json:"packageManager"`
}

type Quarto struct {
Expand Down Expand Up @@ -116,28 +116,28 @@ type Connect struct {
}

type ConnectAccess struct {
RunAs string `toml:"run-as,omitempty" json:"run-as,omitempty"`
RunAsCurrentUser *bool `toml:"run-as-current-user,omitempty" json:"run-as-current-user,omitempty"`
RunAs string `toml:"run-as,omitempty" json:"runAs,omitempty"`
RunAsCurrentUser *bool `toml:"run-as-current-user,omitempty" json:"runAsCurrentUser,omitempty"`
}

type ConnectRuntime struct {
ConnectionTimeout *int32 `toml:"connection-timeout,omitempty" json:"connection-timeout,omitempty"`
ReadTimeout *int32 `toml:"read-timeout,omitempty" json:"read-timeout,omitempty"`
InitTimeout *int32 `toml:"init-timeout,omitempty" json:"init-timeout,omitempty"`
IdleTimeout *int32 `toml:"idle-timeout,omitempty" json:"idle-timeout,omitempty"`
MaxProcesses *int32 `toml:"max-processes,omitempty" json:"max-processes,omitempty"`
MinProcesses *int32 `toml:"min-processes,omitempty" json:"min-processes,omitempty"`
MaxConnsPerProcess *int32 `toml:"max-connections,omitempty" json:"max-connections,omitempty"`
LoadFactor *float64 `toml:"load-factor,omitempty" json:"load-factor,omitempty"`
ConnectionTimeout *int32 `toml:"connection-timeout,omitempty" json:"connectionTimeout,omitempty"`
ReadTimeout *int32 `toml:"read-timeout,omitempty" json:"readTimeout,omitempty"`
InitTimeout *int32 `toml:"init-timeout,omitempty" json:"initTimeout,omitempty"`
IdleTimeout *int32 `toml:"idle-timeout,omitempty" json:"idleTimeout,omitempty"`
MaxProcesses *int32 `toml:"max-processes,omitempty" json:"maxProcesses,omitempty"`
MinProcesses *int32 `toml:"min-processes,omitempty" json:"minProcesses,omitempty"`
MaxConnsPerProcess *int32 `toml:"max-connections,omitempty" json:"maxConnections,omitempty"`
LoadFactor *float64 `toml:"load-factor,omitempty" json:"loadFactor,omitempty"`
}

type ConnectKubernetes struct {
MemoryRequest *int64 `toml:"memory-request,omitempty" json:"memory-request,omitempty"`
MemoryLimit *int64 `toml:"memory-limit,omitempty" json:"memory-limit,omitempty"`
CPURequest *float64 `toml:"cpu-request,omitempty" json:"cpu-request,omitempty"`
CPULimit *float64 `toml:"cpu-limit,omitempty" json:"cpu-limit,omitempty"`
AMDGPULimit *int64 `toml:"amd-gpu-limit,omitempty" json:"amd-gpu-limit,omitempty"`
NvidiaGPULimit *int64 `toml:"nvidia-gpu-limit,omitempty" json:"nvidia-gpu-limit,omitempty"`
ServiceAccountName string `toml:"service-account-name,omitempty" json:"service-account-name,omitempty"`
DefaultImageName string `toml:"image-name,omitempty" json:"image-name,omitempty"`
MemoryRequest *int64 `toml:"memory-request,omitempty" json:"memoryRequest,omitempty"`
MemoryLimit *int64 `toml:"memory-limit,omitempty" json:"memoryLimit,omitempty"`
CPURequest *float64 `toml:"cpu-request,omitempty" json:"cpuRequest,omitempty"`
CPULimit *float64 `toml:"cpu-limit,omitempty" json:"cpuLimit,omitempty"`
AMDGPULimit *int64 `toml:"amd-gpu-limit,omitempty" json:"amdGpuLimit,omitempty"`
NvidiaGPULimit *int64 `toml:"nvidia-gpu-limit,omitempty" json:"nvidiaGpuLimit,omitempty"`
ServiceAccountName string `toml:"service-account-name,omitempty" json:"serviceAccountName,omitempty"`
DefaultImageName string `toml:"image-name,omitempty" json:"imageName,omitempty"`
}
48 changes: 35 additions & 13 deletions internal/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package deployment

import (
"io"
"strings"

"github.com/pelletier/go-toml/v2"
"github.com/rstudio/connect-client/internal/accounts"
Expand All @@ -15,13 +16,14 @@ import (

type Deployment struct {
Schema string `toml:"$schema" json:"$schema"`
ServerType accounts.ServerType `toml:"server-type" json:"server-type"`
ServerURL string `toml:"server-url" json:"server-url"`
ServerType accounts.ServerType `toml:"server-type" json:"serverType"`
ServerURL string `toml:"server-url" json:"serverUrl"`
Id types.ContentID `toml:"id" json:"id"`
ConfigName string `toml:"configuration-name" json:"configuration-name"`
ConfigName string `toml:"configuration-name" json:"configurationName"`
Configuration config.Config `toml:"configuration" json:"configuration"`
Files []string `toml:"files" json:"files"`
DeployedAt string `toml:"deployed-at" json:"deployed-at"`
DeployedAt string `toml:"deployed-at" json:"deployedAt"`
SaveName string `toml:"-" json:"saveName"`
}

func New() *Deployment {
Expand All @@ -37,26 +39,41 @@ func GetDeploymentsPath(base util.Path) util.Path {
return base.Join(".posit", "publish", "deployments")
}

func GetDeploymentPath(base util.Path, id string) util.Path {
return GetDeploymentsPath(base).Join(id + ".toml")
func GetDeploymentPath(base util.Path, name string) util.Path {
return GetDeploymentsPath(base).Join(name + ".toml")
}

func ListDeploymentFiles(base util.Path) ([]util.Path, error) {
dir := GetDeploymentsPath(base)
return dir.Glob("*.toml")
}

func SaveNameFromPath(path util.Path) string {
return strings.TrimSuffix(path.Base(), ".toml")
}

func RenameDeployment(base util.Path, oldName, newName string) error {
err := util.ValidateFilename(newName)
if err != nil {
return err
}
oldPath := GetDeploymentPath(base, oldName)
newPath := GetDeploymentPath(base, newName)
return oldPath.Rename(newPath)
}

func FromFile(path util.Path) (*Deployment, error) {
err := ValidateFile(path)
if err != nil {
return nil, err
}
deployment := New()
err = util.ReadTOMLFile(path, deployment)
d := New()
err = util.ReadTOMLFile(path, d)
if err != nil {
return nil, err
}
return deployment, nil
d.SaveName = SaveNameFromPath(path)
return d, nil
}

func ValidateFile(path util.Path) error {
Expand All @@ -67,12 +84,12 @@ func ValidateFile(path util.Path) error {
return validator.ValidateTOMLFile(path)
}

func (record *Deployment) Write(w io.Writer) error {
func (d *Deployment) Write(w io.Writer) error {
enc := toml.NewEncoder(w)
return enc.Encode(record)
return enc.Encode(d)
}

func (record *Deployment) WriteFile(path util.Path) error {
func (d *Deployment) WriteFile(path util.Path) error {
err := path.Dir().MkdirAll(0777)
if err != nil {
return err
Expand All @@ -82,5 +99,10 @@ func (record *Deployment) WriteFile(path util.Path) error {
return err
}
defer f.Close()
return record.Write(f)
err = d.Write(f)
if err != nil {
return err
}
d.SaveName = SaveNameFromPath(path)
return nil
}
12 changes: 6 additions & 6 deletions internal/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func (s *DeploymentSuite) TestNew() {
}

func (s *DeploymentSuite) TestGetDeploymentPath() {
path := GetDeploymentPath(s.cwd, "myTargetID")
s.Equal(path, s.cwd.Join(".posit", "publish", "deployments", "myTargetID.toml"))
path := GetDeploymentPath(s.cwd, "myTargetName")
s.Equal(path, s.cwd.Join(".posit", "publish", "deployments", "myTargetName.toml"))
}

func (s *DeploymentSuite) TestFromFile() {
expected := s.createDeploymentFile("myTargetID")
path := GetDeploymentPath(s.cwd, "myTargetID")
expected := s.createDeploymentFile("myTargetName")
path := GetDeploymentPath(s.cwd, "myTargetName")
actual, err := FromFile(path)
s.NoError(err)
s.NotNil(actual)
Expand All @@ -72,14 +72,14 @@ func (s *DeploymentSuite) TestFromFileErr() {
}

func (s *DeploymentSuite) TestWriteFile() {
configFile := GetDeploymentPath(s.cwd, "myTargetID")
configFile := GetDeploymentPath(s.cwd, "myTargetName")
deployment := New()
err := deployment.WriteFile(configFile)
s.NoError(err)
}

func (s *DeploymentSuite) TestWriteFileErr() {
configFile := GetDeploymentPath(s.cwd, "myTargetID")
configFile := GetDeploymentPath(s.cwd, "myTargetName")
readonlyFile := util.NewPath(configFile.Path(), afero.NewReadOnlyFs(configFile.Fs()))
deployment := New()
err := deployment.WriteFile(readonlyFile)
Expand Down
Loading

0 comments on commit 7d440a5

Please sign in to comment.