Giter VIP home page Giter VIP logo

Comments (4)

robwise avatar robwise commented on May 27, 2024

Another possible option to consider is just using JavaScript to call the GitHub API for the repo, although this assumes continuous deployment.

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 27, 2024

Hi @robwise, the best way to do this is to set an env var as part of a deployment script.

```#!/bin/bash
# Pass in app as either staging or production first -- must match what you seen in git remote -v
# Examples:
# ./deploy staging
# ./deploy staging --force
# ./deploy production

app=$1

shift

sha=`git rev-parse HEAD 2>/dev/null`
current_branch=`git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///'`

# echo "current_branch is $current_branch"
# echo "sha is $sha"
# echo "app is $app"

if [ "$app" == "" ]; then
  echo "You must specify a param value for the app, such as production or staging"
  exit 1
fi

if [[ "$app" == "production" && "$current_branch" != "master" ]]; then
  echo "You can only deploy master to production!"
  exit 1
fi

echo Running:
echo git push $app $current_branch:master $@
git push $app $current_branch:master $@

echo Setting heroku config DEPLOYMENT_SHA
echo heroku config:set DEPLOYMENT_SHA=$sha --remote $app
heroku config:set DEPLOYMENT_SHA=$sha --remote $app

# Run migrations always just in case
heroku run rake db:migrate --remote $app
heroku restart --remote $app

And then add this to application.rb:

  def self.current_sha
    @sha ||= if ENV["DEPLOYMENT_SHA"].present?
               puts "Set SHA to #{ENV['DEPLOYMENT_SHA']}"
               ENV["DEPLOYMENT_SHA"]
             else
               `git rev-parse HEAD 2>/dev/null`.to_s.strip
             end
  end

And then have this in the view:

Deployed Git Commit: <%=  RailsReactTutorial.current_sha %>

from react-webpack-rails-tutorial.

robwise avatar robwise commented on May 27, 2024

Work in progress: #125

from react-webpack-rails-tutorial.

justin808 avatar justin808 commented on May 27, 2024

Boom!

from react-webpack-rails-tutorial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.