コード例 #1
0
ファイル: main.go プロジェクト: Inza/drone-heroku
func run(workspace *drone.Workspace, build *drone.Build, vargs *Params) error {
	repo.GlobalName(build).Run()
	repo.GlobalUser(build).Run()

	if err := repo.WriteKey(workspace); err != nil {
		return err
	}

	defer func() {
		execute(
			repo.RemoteRemove(
				"deploy"),
			workspace)
	}()

	cmd := repo.RemoteAdd(
		"deploy",
		remote(vargs))

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	if vargs.Commit {
		if err := execute(repo.ForceAdd(), workspace); err != nil {
			return err
		}

		if err := execute(repo.ForceCommit(), workspace); err != nil {
			return err
		}
	}

	cmd = repo.RemotePush(
		"deploy",
		"master",
		vargs.Force)

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	return nil
}
コード例 #2
0
func run(workspace *drone.Workspace, build *drone.Build, vargs *Params) error {
	repo.GlobalName(build).Run()
	repo.GlobalUser(build).Run()

	api := cclib.NewAPI()
	api.SetUrl("https://api.cloudcontrolled.com")

	if err := api.CreateToken(vargs.Email, vargs.Password); err != nil {
		return errors.New("Failed to authenticate with email/password")
	}

	if _, err := api.ReadApplication(vargs.Application); err != nil {
		return errors.New("Failed to find the requested application")
	}

	if workspace.Keys != nil && len(workspace.Keys.Public) > 0 {
		publicKey, err := api.CreateUserKey(
			vargs.Email,
			workspace.Keys.Public)

		if err != nil {
			return errors.New("Failed to create a deployment key")
		}

		defer func() {
			api.DeleteUserKey(
				vargs.Email,
				publicKey.Id)
		}()
	}

	if err := repo.WriteKey(workspace); err != nil {
		return err
	}

	defer func() {
		execute(
			repo.RemoteRemove(
				"deploy"),
			workspace)
	}()

	cmd := repo.RemoteAdd(
		"deploy",
		remote(vargs))

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	if vargs.Commit {
		if err := execute(repo.ForceAdd(), workspace); err != nil {
			return err
		}

		if err := execute(repo.ForceCommit(), workspace); err != nil {
			return err
		}
	}

	cmd = repo.RemotePush(
		"deploy",
		vargs.Deployment,
		vargs.Force)

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	if _, err := api.UpdateDeployment(vargs.Application, vargs.Deployment, "", "", "", 0, 0); err != nil {
		return errors.New("Failed to trigger the final deployment")
	}

	return nil
}