create-react-app-and-sentry-example icon indicating copy to clipboard operation
create-react-app-and-sentry-example copied to clipboard

Script not working on widnows

Open nikola1970 opened this issue 5 years ago • 3 comments

"release": "(export REACT_APP_SENTRY_RELEASE=$(git rev-parse --short HEAD); react-scripts build && node scripts/sentry.js)"

This part is not working on non unix machines, any idea how to make it work (and that's not switching to mac :D)?

Thanks.

nikola1970 avatar Feb 04 '20 12:02 nikola1970

I hade the same problem as @nikola1970 and ended up just reading the commit hash directly inside the sentry uploader script. Final version here: https://gist.github.com/ninjacarr/4baf92132d31a3d0ab2460d8fb4c15e1

Bonus tip: if by windows you mean an Azure app service, you might run into another problem. sentry-cli.exe might crash with the following error:

error: Could not find home dir
thread 'main' panicked at 'Config not bound yet': src\libcore\option.rs:1188

This is rooted in rust's home_dir() function failing to detect your home directory, as it is not exposed by default in Azure app services. Add the following app service setting to fix this: WEBSITE_LOAD_USER_PROFILE=1

ninjacarr avatar Mar 05 '20 15:03 ninjacarr

I solve this problem with Gitlab CI and Docker help.

Add arg with git hash to build script:

.gitlab-ci.yml

build_webapp:
  stage: build
  script:
    - docker build --build-arg=COMMIT=$(git rev-parse --short HEAD)  -t frontend .

And pass git hash whit Docker

Dockerfile:

WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
ARG COMMIT=""
LABEL commit=${COMMIT}
ENV REACT_APP_COMMIT=${COMMIT}`

And finally in my app I get env var: const release = process.env.REACT_APP_COMMIT;

That's all!

Manumental32 avatar May 05 '21 18:05 Manumental32

The solution I find for Windows is replace that
"release": "(export REACT_APP_SENTRY_RELEASE=$(git rev-parse --short HEAD); react-scripts build && node scripts/sentry.js)"

to this

"release-window": "git rev-parse --short HEAD >head.txt && set /p REACT_APP_SENTRY_RELEASE= < head.txt && del head.txt && react-scripts build && node scripts/sentry.js",

FrankyCode avatar Sep 02 '21 17:09 FrankyCode