Skip to content

Commit d88e146

Browse files
committed
feat(release): add deploy release
1 parent b589d0b commit d88e146

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

releases/releases.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ func Get(c *drycc.Client, appID string, version int) (api.Release, error) {
4545
return release, nil
4646
}
4747

48+
// Deploy deploy an app's processes. To deploy all app processes, pass empty strings for
49+
// procType and name. To deploy an specific process, pass an procType by leave name empty.
50+
// To deploy a specific instance, pass a procType and a name.
51+
func Deploy(c *drycc.Client, appID string, targets map[string]string) error {
52+
u := fmt.Sprintf("/v2/apps/%s/releases/deploy/", appID)
53+
body, err := json.Marshal(targets)
54+
if err != nil {
55+
return err
56+
}
57+
res, err := c.Request("POST", u, body)
58+
if err != nil && !drycc.IsErrAPIMismatch(err) {
59+
return err
60+
}
61+
defer res.Body.Close()
62+
return err
63+
}
64+
4865
// Rollback rolls back an app to a previous release. If version is -1, this rolls back to
4966
// the previous release. Otherwise, roll back to the specified version.
5067
func Rollback(c *drycc.Client, appID string, version int) (int, error) {

releases/releases_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const releaseFixture string = `
4848
}
4949
`
5050

51+
const deployExpected string = `{"types":"web,task"}`
52+
5153
const rollbackFixture string = `
5254
{"version": 5}
5355
`
@@ -73,6 +75,26 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
7375
return
7476
}
7577

78+
if req.URL.Path == "/v2/apps/example-go/releases/deploy/" && req.Method == "POST" {
79+
body, err := io.ReadAll(req.Body)
80+
81+
if err != nil {
82+
fmt.Println(err)
83+
res.WriteHeader(http.StatusInternalServerError)
84+
res.Write(nil)
85+
}
86+
87+
if string(body) != deployExpected {
88+
fmt.Printf("Expected '%s', Got '%s'\n", deployExpected, body)
89+
res.WriteHeader(http.StatusInternalServerError)
90+
res.Write(nil)
91+
return
92+
}
93+
94+
res.WriteHeader(http.StatusCreated)
95+
return
96+
}
97+
7698
if req.URL.Path == "/v2/apps/example-go/releases/rollback/" && req.Method == "POST" {
7799
body, err := io.ReadAll(req.Body)
78100

@@ -194,6 +216,26 @@ func TestReleasesGet(t *testing.T) {
194216
}
195217
}
196218

219+
func TestDeploy(t *testing.T) {
220+
t.Parallel()
221+
222+
handler := fakeHTTPServer{}
223+
server := httptest.NewServer(handler)
224+
defer server.Close()
225+
226+
drycc, err := drycc.New(false, server.URL, "abc")
227+
if err != nil {
228+
t.Fatal(err)
229+
}
230+
targets := map[string]string{"types": "web,task"}
231+
232+
err = Deploy(drycc, "example-go", targets)
233+
234+
if err != nil {
235+
t.Fatal(err)
236+
}
237+
}
238+
197239
func TestRollback(t *testing.T) {
198240
t.Parallel()
199241

0 commit comments

Comments
 (0)