github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/docs/Publish.md (about)

     1  Summary
     2  -------
     3  `./godelw publish` publishes distributions for the products in the project based on the dist configuration.
     4  
     5  Tutorial start state
     6  --------------------
     7  
     8  * `$GOPATH/src/github.com/nmiyake/echgo` exists and is the working directory
     9  * Project contains `godel` and `godelw`
    10  * Project contains `main.go`
    11  * Project contains `.gitignore` that ignores IDEA files
    12  * Project contains `echo/echo.go`, `echo/echo_test.go` and `echo/echoer.go`
    13  * `godel/config/dist.yml` is configured to build `echgo`
    14  * Project is tagged as 0.0.1
    15  * `godel/config/dist.yml` is configured to create distributions for `echgo`
    16  
    17  ([Link](https://github.com/nmiyake/echgo/tree/55182ff79dd28048782fb240920d6f2d90b453da))
    18  
    19  Publish
    20  -------
    21  
    22  Our project is now configured to build binaries and distributions. The next step is to have a way to publish these
    23  distributions so that they can be downloaded and consumed by users.
    24  
    25  The `publish` task can be used to publish the distributions created by the `dist` task. The `publish` task supports
    26  publishing artifacts to the following common distribution platforms:
    27  
    28  * GitHub releases
    29  * Bintray
    30  * Artifactory
    31  
    32  The publish task is most commonly run in a CI environment, but it is possible to run locally as well. We will walk
    33  through an example of publishing this product using GitHub releases.
    34  
    35  In order to publish this product on GitHub, we will need a GitHub repository and a GitHub API token. This tutorial uses
    36  `github.com/nmiyake/echgo` as the GitHub repository. To follow along with this tutorial, create a repository in your own
    37  GitHub space called `echgo`. GitHub provides [instructions](https://help.github.com/articles/create-a-repo/) for this if
    38  you have not done so before.
    39  
    40  Because we already have a repository locally, you can follow the [instructions provided by GitHub](https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/)
    41  for pushing a local Git repository to the newly created repository. The following is an example of pushing the
    42  local repository to the `nmiyake/echgo` GitHub repository set up using SSH:
    43  
    44  ```
    45  ➜ git remote add origin git@github.com:nmiyake/echgo.git
    46  ➜ git push -u origin master
    47  Counting objects: 51, done.
    48  Delta compression using up to 8 threads.
    49  Compressing objects: 100% (41/41), done.
    50  Writing objects: 100% (51/51), 7.29 KiB | 0 bytes/s, done.
    51  Total 51 (delta 16), reused 0 (delta 0)
    52  remote: Resolving deltas: 100% (16/16), done.
    53  To git@github.com:nmiyake/echgo.git
    54   * [new branch]      master -> master
    55  Branch master set up to track remote branch master from origin by rebasing.
    56  ```
    57  
    58  We will perform a release for a 0.0.2 of our product. Create a `0.0.2` tag and push the tags to the repository:
    59  
    60  ```
    61  ➜ git tag 0.0.2
    62  ➜ git push origin --tags
    63  Total 0 (delta 0), reused 0 (delta 0)
    64  To git@github.com:nmiyake/echgo.git
    65   * [new tag]         0.0.1 -> 0.0.1
    66   * [new tag]         0.0.2 -> 0.0.2
    67  ```
    68  
    69  Publishing to GitHub requires an access token. Follow the [GitHub instructions](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)
    70  for creating a personal access token. For this example, the token requires the `public_repo` scope.
    71  
    72  Once you have created the token, run the following command, replacing `nmiyake` with your own username and `<token>`
    73  with your GitHub token:
    74  
    75  ```
    76  ➜ ./godelw publish github --url https://api.github.com/ --user nmiyake --password <token> --owner nmiyake --repository echgo
    77  Building echgo for darwin-amd64 at /Volumes/git/go/src/github.com/nmiyake/echgo/build/0.0.2/darwin-amd64/echgo
    78  Building echgo for linux-amd64 at /Volumes/git/go/src/github.com/nmiyake/echgo/build/0.0.2/linux-amd64/echgo
    79  Finished building echgo for linux-amd64 (0.385s)
    80  Finished building echgo for darwin-amd64 (0.386s)
    81  Creating distribution for echgo at /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2-darwin-amd64.tgz, /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2-linux-amd64.tgz
    82  Finished creating distribution for echgo
    83  Creating distribution for echgo at /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2-darwin-amd64.tgz, /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2-linux-amd64.tgz
    84  Finished creating distribution for echgo
    85  Creating GitHub release 0.0.2 for nmiyake/echgo...done
    86  Uploading /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2-darwin-amd64.tgz to https://uploads.github.com/repos/nmiyake/echgo/releases/8141225/assets?name=echgo-0.0.2-darwin-amd64.tgz
    87   732.31 KB / 732.31 KB [====================================================================================] 100.00% 0s
    88  Uploading /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2-linux-amd64.tgz to https://uploads.github.com/repos/nmiyake/echgo/releases/8141225/assets?name=echgo-0.0.2-linux-amd64.tgz
    89   700.54 KB / 700.54 KB [====================================================================================] 100.00% 0s
    90  ```
    91  
    92  As described by the output, the `publish` task has created a GitHub release called `0.0.2` (the name of the tag) and
    93  has uploaded the distribution artifacts to the release.
    94  
    95  Navigate to the "releases" section of the repository to verify that the distribution artifacts were uploaded:
    96  
    97  ![github release](images/tutorial/github_release.png)
    98  
    99  The publish task can be configured to run in a CI environment on release tags.
   100  
   101  Tutorial end state
   102  ------------------
   103  
   104  * `$GOPATH/src/github.com/nmiyake/echgo` exists and is the working directory
   105  * Project contains `godel` and `godelw`
   106  * Project contains `main.go`
   107  * Project contains `.gitignore` that ignores IDEA files
   108  * Project contains `echo/echo.go`, `echo/echo_test.go` and `echo/echoer.go`
   109  * `godel/config/dist.yml` is configured to build `echgo`
   110  * Project is tagged as 0.0.1
   111  * `godel/config/dist.yml` is configured to create distributions for `echgo`
   112  * Project is tagged as 0.0.2
   113  
   114  ([Link](https://github.com/nmiyake/echgo/tree/55182ff79dd28048782fb240920d6f2d90b453da))
   115  
   116  Tutorial next step
   117  ------------------
   118  
   119  [Generate license headers](https://github.com/palantir/godel/wiki/License-headers)
   120  
   121  More
   122  ----
   123  
   124  ### POM publishing and local publishing
   125  
   126  The `Artifactory` and `Bintray` publish tasks generate Maven-style [POM](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html)
   127  descriptors that are uploaded along with the artifacts. The product name and version for the POM are determined based on
   128  the build configuration and repository state. The group ID must be specified as a separate top-level key called
   129  `group-id`.
   130  
   131  Run the following to add a `group-id` field:
   132  
   133  ```
   134  ➜ echo 'products:
   135    echgo:
   136      build:
   137        main-pkg: .
   138        version-var: main.version
   139        os-archs:
   140          - os: darwin
   141            arch: amd64
   142          - os: linux
   143            arch: amd64
   144      dist:
   145        dist-type:
   146          type: os-arch-bin
   147  group-id: com.palantir.echgo' > godel/config/dist.yml
   148  ```
   149  
   150  It can be helpful to see the exact output that will be generated for a distribution before trying to publish it
   151  remotely. In order to facilitate this for POM-based publishing, publish supports a `local` type. Run the following to
   152  publish artifacts locally:
   153  
   154  ```
   155  ➜ ./godelw publish local
   156  Building echgo for linux-amd64 at /Volumes/git/go/src/github.com/nmiyake/echgo/build/0.0.2.dirty/linux-amd64/echgo
   157  Building echgo for darwin-amd64 at /Volumes/git/go/src/github.com/nmiyake/echgo/build/0.0.2.dirty/darwin-amd64/echgo
   158  Finished building echgo for darwin-amd64 (0.384s)
   159  Finished building echgo for linux-amd64 (0.389s)
   160  Creating distribution for echgo at /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty-darwin-amd64.tgz, /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty-linux-amd64.tgz
   161  Finished creating distribution for echgo
   162  Creating distribution for echgo at /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty-darwin-amd64.tgz, /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty-linux-amd64.tgz
   163  Finished creating distribution for echgo
   164  Copying /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty.pom to /Users/nmiyake/.m2/repository/com/palantir/echgo/echgo/0.0.2.dirty/echgo-0.0.2.dirty.pom
   165  Copying /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty-darwin-amd64.tgz to /Users/nmiyake/.m2/repository/com/palantir/echgo/echgo/0.0.2.dirty/echgo-0.0.2.dirty-darwin-amd64.tgz
   166  Copying /Volumes/git/go/src/github.com/nmiyake/echgo/dist/echgo-0.0.2.dirty-linux-amd64.tgz to /Users/nmiyake/.m2/repository/com/palantir/echgo/echgo/0.0.2.dirty/echgo-0.0.2.dirty-linux-amd64.tgz
   167  ```
   168  
   169  By default, the task uses a Maven-style target and writes the output in a path under `~/.m2/repository`. This can be
   170  customized using the `--path` flag. Verify that the content of the POM is valid:
   171  
   172  ```
   173  ➜ cat ~/.m2/repository/com/palantir/echgo/echgo/"$(./godelw project-version)"/echgo-"$(./godelw project-version)".pom
   174  <?xml version="1.0" encoding="UTF-8"?>
   175  <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
   176  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   177  <modelVersion>4.0.0</modelVersion>
   178  <groupId>com.palantir.echgo</groupId>
   179  <artifactId>echgo</artifactId>
   180  <version>0.0.2.dirty</version>
   181  <packaging>tgz</packaging>
   182  </project>
   183  ```
   184  
   185  Revert these changes by running the following:
   186  
   187  ```
   188  ➜ git checkout -- godel/config/dist.yml
   189  ```
   190  
   191  ### Artifactory publishing
   192  
   193  The `publish` task supports publishing artifacts to Artifactory. The general call looks like the following:
   194  
   195  ```
   196  ./godelw publish artifactory --url https://artifactory.domain.com --repository dist-repo --user <username> --password <password>
   197  ```
   198  
   199  A call of this form results in a publish call of the following form:
   200  
   201  ```
   202  https://artifactory.domain.com/artifactory/dist-repo/<group-id>/echgo/0.0.2/echgo-0.0.2.tgz
   203  ```
   204  
   205  The Artifactory publish task uses the Artifactory API to compute the SHA-256 checksums for the uploaded artifacts.
   206  
   207  ### Bintray publishing
   208  
   209  The `publish` task supports publishing artifacts to Bintray. The general call looks like the following:
   210  
   211  ```
   212  ./godelw publish bintray --url https://api.bintray.com --subject org --repository releases --user <user> --password <password> --publish --downloads-list
   213  ```
   214  
   215  A call of this form results in a publish call of the following form:
   216  
   217  ```
   218  https://api.bintray.com/content/org/releases/echgo/0.0.2/<group-id>/echgo/0.0.2/echgo-0.0.2.tgz
   219  ```
   220  
   221  The `--publish` flag triggers a Bintray "release" action and the `--downloads-list` flag adds the artifact to the
   222  downloads list of the Bintray page.