Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to version my app #2486

Closed
alleroux opened this issue Jun 6, 2017 · 6 comments
Closed

How to version my app #2486

alleroux opened this issue Jun 6, 2017 · 6 comments

Comments

@alleroux
Copy link

alleroux commented Jun 6, 2017

I'm using git flow. I name my releases by version number. For example v1.02. I'd like to be able to run a git command: git rev-parse --abbrev-ref HEAD to get the current branch. Then parse out the version number from the branch and stick that into my page somewhere. What would be the best way to do that?

@heyimalex
Copy link
Contributor

You could make a script that reads the version, then calls react-scripts build with an environment variable set to it. In development mode it could just be a placeholder set in your dotenv.

@peterbe
Copy link

peterbe commented Jun 15, 2017

Do you mean you want the current version number rendered into the HTML?
If so I would suggest you do that with your web server. For example, when you start your Python/Ruby/Go server, you call out to that git rev-parse ... command and load that into memory, then upon rendering the index.html you make a string replacement.

Alternatively, you can do something like this during build:

# First add '<!-- version: %VERSION% -->' to your public/index.html file
$ yarn run build
$ VERSION=`git rev-parse --abbrev-ref HEAD`
$ sed -i -- "s/%VERSION%/$VERSION/g" build/index.html

Now your build/index.html should contain <!-- version: name-of-the-current-branch -->.

@peterbe
Copy link

peterbe commented Jun 15, 2017

Also, see the ideas on #2466 where they use the version in the package.json file. Not sure if that's relevant to you.

@Timer
Copy link
Contributor

Timer commented Jun 15, 2017

I'll close this as answered.

@Timer Timer closed this as completed Jun 15, 2017
@uidevperson
Copy link

@peterbe (apologies for asking on a closed issue) for #2466 do you happen to know of any implementation example of this? #2466 is locked so I cannot ask for an example on how to inject your git version into the index.html :)

@peterbe
Copy link

peterbe commented Aug 29, 2018

@uidevperson There are many different UNIX* ways to do this. What you ultimately need to do is figure out the version of the app and make this string available as an environment variable before running yarn run build. E.g.

REACT_APP_CURRENT_GIT_SHA=`git rev-parse --short HEAD` yarn run build

The other option, as mentioned above is to inject it into the built build/index.html in some way.

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants