From e55a8f579908dd1dbab639dfbd079d8f30e656cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lker=20G=2E=20=C3=96zt=C3=BCrk?= Date: Thu, 17 Jun 2021 19:10:08 +0300 Subject: [PATCH] feat(templates/ci): add integration to auto release apps (#1239) * feat: add integration to auto release apps through the Github CI. * implemented a cli action under actions/cli. * apps will be scaffold with a release workflow using the new starport cli action and other 3rd party actions. * added instructions about how to install an app through the curl+bash installer. * tweak * docs * Apply suggestions from code review Co-authored-by: Denis Fadeev * fix * Update starport/templates/app/stargate/readme.md.plush Co-authored-by: Denis Fadeev * create/update "latest" release everytime there is a change to the develop branch * use default branch for "latest" release * tweak * tweak * Update starport/templates/app/stargate/.github/workflows/release.yml Co-authored-by: Denis Fadeev * Update starport/templates/app/stargate/readme.md.plush Co-authored-by: Denis Fadeev * Apply suggestions from code review Co-authored-by: Lucas Bertrand Co-authored-by: Denis Fadeev Co-authored-by: Lucas Bertrand --- actions/cli/Dockerfile | 3 ++ actions/cli/action.yml | 5 ++ actions/cli/readme.md | 22 ++++++++ actions/release/vars/action.yml | 50 ++++++++++++++++++ starport/services/scaffolder/init.go | 7 +++ starport/templates/app/app.go | 1 + starport/templates/app/options.go | 1 + .../.github/workflows/build.yml.plush | 39 -------------- .../app/stargate/.github/workflows/pages.yml | 24 --------- .../stargate/.github/workflows/release.yml | 51 +++++++++++++++++++ .../templates/app/stargate/readme.md.plush | 25 +++++++-- 11 files changed, 161 insertions(+), 67 deletions(-) create mode 100644 actions/cli/Dockerfile create mode 100644 actions/cli/action.yml create mode 100644 actions/cli/readme.md create mode 100644 actions/release/vars/action.yml delete mode 100644 starport/templates/app/stargate/.github/workflows/build.yml.plush delete mode 100644 starport/templates/app/stargate/.github/workflows/pages.yml create mode 100644 starport/templates/app/stargate/.github/workflows/release.yml diff --git a/actions/cli/Dockerfile b/actions/cli/Dockerfile new file mode 100644 index 0000000000..1f0915daec --- /dev/null +++ b/actions/cli/Dockerfile @@ -0,0 +1,3 @@ +FROM starport/cli:develop + +USER root diff --git a/actions/cli/action.yml b/actions/cli/action.yml new file mode 100644 index 0000000000..f6322d79da --- /dev/null +++ b/actions/cli/action.yml @@ -0,0 +1,5 @@ +name: cli +description: Starport CLI +runs: + using: docker + image: Dockerfile diff --git a/actions/cli/readme.md b/actions/cli/readme.md new file mode 100644 index 0000000000..3ce8c59360 --- /dev/null +++ b/actions/cli/readme.md @@ -0,0 +1,22 @@ +# Starport CLI Action +This action makes the `starport` CLI available as a Github Action. + +## Quick start + +Add a new workflow to your repo: + +```yml +on: push + +jobs: + help: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Print Help + uses: tendermint/starport/actions/cli@develop + with: + args: -h +``` diff --git a/actions/release/vars/action.yml b/actions/release/vars/action.yml new file mode 100644 index 0000000000..b0c28a5efd --- /dev/null +++ b/actions/release/vars/action.yml @@ -0,0 +1,50 @@ +name: vars +description: Outputs variables that can be useful while creating a release +outputs: + should_release: + description: Indicates whether a release should be created or not + value: ${{ steps.vars.outputs.should_release }} + is_release_type_latest: + description: Shows if release type is latest (not a v* release) + value: ${{ steps.vars.outputs.is_release_type_latest }} + tag_name: + description: Name of the tag that should be used for release + value: ${{ steps.vars.outputs.tag_name }} + tarball_prefix: + description: A prefix to use in tarball asset names + value: ${{ steps.vars.outputs.tarball_prefix }} +runs: + using: "composite" + steps: + - id: vars + run: | + repo_name=${GITHUB_REPOSITORY##*/} + ref_name=${GITHUB_REF##*/} + default_branch=$(git remote show origin | awk '/HEAD branch/ {print $NF}') + + should_release=true + is_release_type_latest=false + tag_name="" + + if [[ $GITHUB_REF == refs/tags/* ]] + then + tag_name=$ref_name + elif [[ $GITHUB_REF == refs/heads/* && $ref_name == $default_branch ]] + then + tag_name=latest + is_release_type_latest=true + else + should_release=false + fi + + echo ::set-output name=should_release::$should_release + echo ::set-output name=is_release_type_latest::$is_release_type_latest + echo ::set-output name=tag_name::$tag_name + echo ::set-output name=tarball_prefix::"$repo_name"_$tag_name + shell: bash + - run: | + echo "- should_release: ${{ steps.vars.outputs.should_release }}" + echo "- is_release_type_latest: ${{ steps.vars.outputs.is_release_type_latest }}" + echo "- tag_name: ${{ steps.vars.outputs.tag_name }}" + echo "- tarball_prefix: ${{ steps.vars.outputs.tarball_prefix }}" + shell: bash diff --git a/starport/services/scaffolder/init.go b/starport/services/scaffolder/init.go index 962cd8a0a5..d9a474d950 100644 --- a/starport/services/scaffolder/init.go +++ b/starport/services/scaffolder/init.go @@ -9,6 +9,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" "github.com/gobuffalo/genny" + "github.com/tendermint/starport/starport/pkg/giturl" "github.com/tendermint/starport/starport/pkg/gomodulepath" "github.com/tendermint/starport/starport/pkg/localfs" "github.com/tendermint/starport/starport/pkg/placeholder" @@ -62,11 +63,17 @@ func (s *Scaffolder) generate( absRoot string, noDefaultModule bool, ) error { + gu, err := giturl.Parse(pathInfo.RawPath) + if err != nil { + return err + } + g, err := app.New(&app.Options{ // generate application template ModulePath: pathInfo.RawPath, AppName: pathInfo.Package, OwnerName: owner(pathInfo.RawPath), + OwnerAndRepoName: gu.UserAndRepo(), BinaryNamePrefix: pathInfo.Root, AddressPrefix: s.options.addressPrefix, }) diff --git a/starport/templates/app/app.go b/starport/templates/app/app.go index 119b093502..58e6eac23e 100644 --- a/starport/templates/app/app.go +++ b/starport/templates/app/app.go @@ -28,6 +28,7 @@ func New(opts *Options) (*genny.Generator, error) { ctx := plush.NewContext() ctx.Set("ModulePath", opts.ModulePath) ctx.Set("AppName", opts.AppName) + ctx.Set("OwnerAndRepoName", opts.OwnerAndRepoName) ctx.Set("OwnerName", opts.OwnerName) ctx.Set("BinaryNamePrefix", opts.BinaryNamePrefix) ctx.Set("AddressPrefix", opts.AddressPrefix) diff --git a/starport/templates/app/options.go b/starport/templates/app/options.go index bbc96720f3..2d5c90bf89 100644 --- a/starport/templates/app/options.go +++ b/starport/templates/app/options.go @@ -4,6 +4,7 @@ package app type Options struct { AppName string OwnerName string + OwnerAndRepoName string BinaryNamePrefix string ModulePath string AddressPrefix string diff --git a/starport/templates/app/stargate/.github/workflows/build.yml.plush b/starport/templates/app/stargate/.github/workflows/build.yml.plush deleted file mode 100644 index 0e6d5f4a93..0000000000 --- a/starport/templates/app/stargate/.github/workflows/build.yml.plush +++ /dev/null @@ -1,39 +0,0 @@ -# This is a basic workflow that is manually triggered - -name: <%= AppName %> - -# Controls when the action will run. Workflow runs when manually triggered using the UI -# or API. -on: [push, pull_request] - -# This workflow makes x86_64 binaries for mac, windows, and linux. - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - arch: [amd64, arm64] - targetos: [windows, darwin, linux] - name: <%= AppName %> ${{ matrix.arch }} for ${{ matrix.targetos }} - steps: - - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v1 - with: - go-version: 1.16 - env: - GOOS: ${{ matrix.targetos }} - GOARCH: ${{ matrix.arch }} - - - name: Compile - run: | - go mod download - cd cmd/<%= AppName %>d - go build . - - - uses: actions/upload-artifact@v2 - with: - name: <%= AppName %>d ${{ matrix.targetos }} ${{ matrix.arch }} - path: cmd/<%= AppName %>d/<%= AppName %>d - diff --git a/starport/templates/app/stargate/.github/workflows/pages.yml b/starport/templates/app/stargate/.github/workflows/pages.yml deleted file mode 100644 index c1a2860048..0000000000 --- a/starport/templates/app/stargate/.github/workflows/pages.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Build and Deploy -on: [push] -jobs: - build-and-deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. - with: - persist-credentials: false - - - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built. - run: | - cd vue - npm install - npm run build - - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@3.7.1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BRANCH: gh-pages # The branch the action should deploy to. - FOLDER: vue/dist # The folder the action should deploy. - CLEAN: true # Automatically remove deleted files from the deploy branch diff --git a/starport/templates/app/stargate/.github/workflows/release.yml b/starport/templates/app/stargate/.github/workflows/release.yml new file mode 100644 index 0000000000..011a2bbc3e --- /dev/null +++ b/starport/templates/app/stargate/.github/workflows/release.yml @@ -0,0 +1,51 @@ +# This workflow is useful if you want to automate the process of: +# +# a) Creating a new prelease when you push a new tag with a "v" prefix (version). +# +# This type of prerelease is meant to be used for production: alpha, beta, rc, etc. types of releases. +# After the prerelease is created, you need to make your changes on the release page at the relevant +# Github page and publish your release. +# +# b) Creating/updating the "latest" prerelease when you push to your default branch. +# +# This type of prelease is useful to make your bleeding-edge binaries available to advanced users. +# +# The workflow will not run if there is no tag pushed with a "v" prefix and no change pushed to your +# default branch. +on: push + +jobs: + might_release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prepare Release Variables + id: vars + uses: tendermint/starport/actions/release/vars@develop + + - name: Issue Release Assets + uses: tendermint/starport/actions/cli@develop + if: ${{ steps.vars.outputs.should_release == 'true' }} + with: + args: build --release --release.prefix ${{ steps.vars.outputs.tarball_prefix }} -t linux:amd64 -t linux:arm64 -t darwin:amd64 -t darwin:arm64 + + - name: Delete the "latest" Release + uses: dev-drprasad/delete-tag-and-release@v0.2.0 + if: ${{ steps.vars.outputs.is_release_type_latest == 'true' }} + with: + tag_name: ${{ steps.vars.outputs.tag_name }} + delete_release: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish the Release + uses: softprops/action-gh-release@v1 + if: ${{ steps.vars.outputs.should_release == 'true' }} + with: + tag_name: ${{ steps.vars.outputs.tag_name }} + files: release/* + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/starport/templates/app/stargate/readme.md.plush b/starport/templates/app/stargate/readme.md.plush index 15c942c56e..8f2c7f1f67 100644 --- a/starport/templates/app/stargate/readme.md.plush +++ b/starport/templates/app/stargate/readme.md.plush @@ -1,5 +1,4 @@ # <%= AppName %> - **<%= AppName %>** is a blockchain built using Cosmos SDK and Tendermint and created with [Starport](https://github.com/tendermint/starport). ## Get started @@ -10,15 +9,15 @@ starport serve `serve` command installs dependencies, builds, initializes, and starts your blockchain in development. -## Configure +### Configure Your blockchain in development can be configured with `config.yml`. To learn more, see the [Starport docs](https://docs.starport.network). -## Launch +### Launch To launch your blockchain live on multiple nodes, use `starport network` commands. Learn more about [Starport Network](https://github.com/tendermint/spn). -## Web Frontend +### Web Frontend Starport has scaffolded a Vue.js-based web app in the `vue` directory. Run the following commands to install dependencies and start the app: @@ -30,6 +29,24 @@ npm run serve The frontend app is built using the `@starport/vue` and `@starport/vuex` packages. For details, see the [monorepo for Starport front-end development](https://github.com/tendermint/vue). +## Release +To release a new version of your blockchain, create and push a new tag with `v` prefix. A new draft release with the configured targets will be created. + +``` +git tag v0.1 +git push origin v0.1 +``` + +After a draft release is created, make your final changes from the release page and publish it. + +### Install +To install the latest version of your blockchain node's binary, execute the following command on your machine: + +``` +curl https://get.starport.network/<%= OwnerAndRepoName %>@latest! | sudo bash +``` +`<%= OwnerAndRepoName %>` should match the `username` and `repo_name` of the Github repository to which the source code was pushed. Learn more about [the install process](https://github.com/allinbits/starport-installer). + ## Learn more - [Starport](https://github.com/tendermint/starport)