Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
add release script, fix handling of doc generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MSevey committed Jun 18, 2020
1 parent f29b6fb commit 8d0214b
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# User Generated Content
cover/
tmp/
release/

# Git
.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Nebulous Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
85 changes: 68 additions & 17 deletions cmd/skynet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@ package main

import (
"fmt"
"io"
"os"
"reflect"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

const (
// mainDocFile is the filepath to the top level doc file created by cobra
mainDocFile = "./doc/skynet.md"

// docREADMEFile is the filepath to the README file in /doc
docREADMEFile = "./doc/README.md"
)

// Exit codes.
// inspired by sysexits.h
const (
exitCodeGeneral = 1 // Not in sysexits.h, but is standard practice.
exitCodeUsage = 64 // EX_USAGE in sysexits.h
)

var rootCmd *cobra.Command

var (
// generateDocs will trigger cobra to auto generate the documentation for
// skynet commands
generateDocs bool

// Skynet Flags
//
// skynetPortal will define a Skynet Portal to use instead of the default.
Expand All @@ -32,12 +54,30 @@ var (
customFilename string
)

// Exit codes.
// inspired by sysexits.h
const (
exitCodeGeneral = 1 // Not in sysexits.h, but is standard practice.
exitCodeUsage = 64 // EX_USAGE in sysexits.h
)
// copyDocFile will copy the top level auto generated doc file into a README for
// /doc
func copyDocFile() error {
// Open the main doc file
source, err := os.Open(mainDocFile)
if err != nil {
return err
}
defer source.Close()

// Open the README file
destination, err := os.Create(docREADMEFile)
if err != nil {
return err
}
defer destination.Close()

// Copy the main doc file into the README
_, err = io.Copy(destination, source)
if err != nil {
return err
}
return nil
}

// die prints its arguments to stderr, then exits the program with the default
// error code.
Expand All @@ -46,33 +86,44 @@ func die(args ...interface{}) {
os.Exit(exitCodeGeneral)
}

// generateSkyetDocs will have cobra auto generate the documentation for the
// skynet commands
func generateSkyetDocs() {
// Build the docs
err := doc.GenMarkdownTree(rootCmd, "./doc")
if err != nil {
die(err)
}

// Copy the main skynet.md file to the doc README file
err = copyDocFile()
if err != nil {
die(err)
}
}

func main() {
root := &cobra.Command{
Use: os.Args[0],
rootCmd = &cobra.Command{
Use: "skynet",
Short: "Perform actions related to Skynet",
Long: `Perform actions related to Skynet, a file sharing and data publication platform
on top of Sia.`,
Run: wrap(skynetcmd),
}

// Add Skynet Commands
root.AddCommand(skynetBlacklistCmd, skynetConvertCmd, skynetDownloadCmd, skynetLsCmd, skynetPinCmd, skynetUnpinCmd, skynetUploadCmd)
rootCmd.AddCommand(skynetBlacklistCmd, skynetConvertCmd, skynetDownloadCmd, skynetLsCmd, skynetPinCmd, skynetUnpinCmd, skynetUploadCmd)

// Add Flags
root.PersistentFlags().StringVar(&skynetPortal, "portal", "", "Use a Skynet portal other than the default")
rootCmd.Flags().BoolVarP(&generateDocs, "", "d", false, "Generate the docs for skynet")
rootCmd.PersistentFlags().StringVar(&skynetPortal, "portal", "", "Use a Skynet portal other than the default")
skynetUploadCmd.Flags().StringVar(&portalUploadPath, "upload-path", "", "Relative URL path of the upload endpoint")
skynetUploadCmd.Flags().StringVar(&portalFileFieldName, "file-field-name", "", "Defines the fieldName for the files on the portal")
skynetUploadCmd.Flags().StringVar(&portalDirectoryFileFieldName, "directory-field-name", "", "Defines the fieldName for the directory files on the portal")
skynetUploadCmd.Flags().StringVar(&customFilename, "filename", "", "Custom filename for the uploaded file")

// Build the docs
err := doc.GenMarkdownTree(root, "./tmp")
if err != nil {
die(err)
}

// run
if err := root.Execute(); err != nil {
if err := rootCmd.Execute(); err != nil {
// Since no commands return errors (all commands set Command.Run instead of
// Command.RunE), Command.Execute() should only return an error on an
// invalid command or flag. Therefore Command.Usage() was called (assuming
Expand Down
7 changes: 6 additions & 1 deletion cmd/skynet/skynetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ will pay for storage and repairs until the files are manually deleted.`,

// skynetcmd displays general info about the skynet cli.
func skynetcmd() {
// Check if the user wants to generate the documentation
if generateDocs {
generateSkyetDocs()
}

// Print General Info
fmt.Printf("Use Skynet to upload and share content\n\n")

Expand Down Expand Up @@ -182,7 +187,7 @@ func skynetuploadcmd(sourcePath string) {
if customFilename != "" {
opts.CustomFilename = customFilename
}

fmt.Println("Upload Options", opts)
// Open the source file.
file, err := os.Open(sourcePath)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md → doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ skynet [flags]
### Options

```
-d, -- Generate the docs for skynet
-h, --help help for skynet
--portal string Use a Skynet portal other than the default
```
Expand All @@ -28,4 +29,4 @@ skynet [flags]
* [skynet unpin](skynet_unpin.md) - Needs SDK Implementation
* [skynet upload](skynet_upload.md) - Upload a file or a directory to Skynet.

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
32 changes: 32 additions & 0 deletions doc/skynet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## skynet

Perform actions related to Skynet

### Synopsis

Perform actions related to Skynet, a file sharing and data publication platform
on top of Sia.

```
skynet [flags]
```

### Options

```
-d, -- Generate the docs for skynet
-h, --help help for skynet
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet blacklist](skynet_blacklist.md) - Needs SDK Implementation
* [skynet convert](skynet_convert.md) - Needs SDK Implementation
* [skynet download](skynet_download.md) - Download a skylink from skynet.
* [skynet ls](skynet_ls.md) - Needs SDK Implementation
* [skynet pin](skynet_pin.md) - Needs SDK Implementation
* [skynet unpin](skynet_unpin.md) - Needs SDK Implementation
* [skynet upload](skynet_upload.md) - Upload a file or a directory to Skynet.

###### Auto generated by spf13/cobra on 18-Jun-2020
8 changes: 7 additions & 1 deletion docs/skynet_blacklist.md → doc/skynet_blacklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ skynet blacklist [skylink] [flags]
-h, --help help for blacklist
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
8 changes: 7 additions & 1 deletion docs/skynet_convert.md → doc/skynet_convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ skynet convert [source siaPath] [destination siaPath] [flags]
-h, --help help for convert
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
8 changes: 7 additions & 1 deletion docs/skynet_download.md → doc/skynet_download.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ skynet download [skylink] [destination] [flags]
-h, --help help for download
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
8 changes: 7 additions & 1 deletion docs/skynet_ls.md → doc/skynet_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ skynet ls [flags]
-h, --help help for ls
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
8 changes: 7 additions & 1 deletion docs/skynet_pin.md → doc/skynet_pin.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ skynet pin [skylink] [destination siapath] [flags]
-h, --help help for pin
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
8 changes: 7 additions & 1 deletion docs/skynet_unpin.md → doc/skynet_unpin.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ skynet unpin [siapath] [flags]
-h, --help help for unpin
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
20 changes: 13 additions & 7 deletions docs/skynet_upload.md → doc/skynet_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Upload a file or a directory to Skynet.

### Synopsis

Upload a file or a directory to Skynet. A skylink will be produced which can be
shared and used to retrieve the file. If the given path is a directory all files
under that directory will be uploaded individually and an individual skylink
will be produced for each. All files that get uploaded will be pinned to Skynet
Portal used for the upload, meaning that the portal will pay for storage and
repairs until the files are manually deleted.
Upload a file or a directory to Skynet. A skylink will be produced
which can be shared and used to retrieve the file. If the given path is
a directory all files under that directory will be uploaded individually and
an individual skylink will be produced for each. All files that get uploaded
will be pinned to Skynet Portal used for the upload, meaning that the portal
will pay for storage and repairs until the files are manually deleted.

```
skynet upload [source path] [flags]
Expand All @@ -25,8 +25,14 @@ skynet upload [source path] [flags]
--upload-path string Relative URL path of the upload endpoint
```

### Options inherited from parent commands

```
--portal string Use a Skynet portal other than the default
```

### SEE ALSO

* [skynet](skynet.md) - Perform actions related to Skynet

###### Auto generated by spf13/cobra on 16-Jun-2020
###### Auto generated by spf13/cobra on 18-Jun-2020
15 changes: 15 additions & 0 deletions release-scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang@sha256:1e9c36b3fd7d7f9ab95835fb1ed898293ec0917e44c7e7d2766b4a2d9aa43da6
# golang:1.14.4-buster

ARG branch
ARG version

RUN useradd -ms /bin/bash builder
USER builder
WORKDIR /home/builder

RUN git clone https://github.com/NebulousLabs/skynet-cli
WORKDIR /home/builder/skynet-cli
RUN git fetch --all && git checkout $branch

RUN ./release-scripts/release.sh $version
Loading

0 comments on commit 8d0214b

Please sign in to comment.