Skip to content

Commit

Permalink
Add commit hash as header comment for deployed versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gottfired committed Jun 30, 2021
1 parent a038114 commit 2f20ff4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.3.0

## Added

- For drone builds: add git branch, hash and build time as comment to <head> section

## 1.2.0

## Added
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ docker build . \
--build-arg REACT_APP_API_BASE_URL=http://localhost \
--build-arg REACT_APP_DEPLOYMENT_ENV=dev:optimized \
--build-arg REACT_APP_BASE_NAME=/webapp \
--build-arg REACT_APP_COMMIT_HASH=main_d00faffe \
--build-arg PUBLIC_URL=. \
-t cra-template-aaa-typescript

docker run -p 80:80 cra-template-aaa-typescript
# http://localhost/webapp
# http://localhost

docker run -p 80:80 -e REACT_APP_BASE_NAME="/webapp" cra-template-aaa-typescript
# http://localhost/webapp
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cra-template-aaa-typescript",
"version": "1.2.0",
"version": "1.3.0",
"description": "The base TypeScript template for AAA Create React App.",
"main": "template.json",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion template/.drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ alias:
--build-arg REACT_APP_API_BASE_URL=${REACT_APP_API_BASE_URL} \
--build-arg REACT_APP_DEPLOYMENT_ENV=${REACT_APP_DEPLOYMENT_ENV} \
--build-arg REACT_APP_BASE_NAME=${REACT_APP_BASE_NAME} \
--build-arg REACT_APP_COMMIT_HASH=${DRONE_BRANCH}_${DRONE_COMMIT_SHA:0:10} \
--build-arg PUBLIC_URL=${PUBLIC_URL}
# The actual pipeline building our product
Expand Down Expand Up @@ -97,4 +98,4 @@ services:
when:
branch:
include: *BRANCH_INCLUDE
exclude: *BRANCH_EXCLUDE
exclude: *BRANCH_EXCLUDE
3 changes: 3 additions & 0 deletions template/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ COPY . /app/
ARG REACT_APP_API_BASE_URL
ARG REACT_APP_DEPLOYMENT_ENV
ARG REACT_APP_BASE_NAME
ARG REACT_APP_COMMIT_HASH
ARG PUBLIC_URL
ARG NODE_ENV=production

Expand All @@ -55,6 +56,8 @@ RUN set -e \
&& export REACT_APP_API_BASE_URL=$(sed -e 's/^"//' -e 's/"$//' <<<"$REACT_APP_API_BASE_URL") \
&& export REACT_APP_DEPLOYMENT_ENV=$(sed -e 's/^"//' -e 's/"$//' <<<"$REACT_APP_DEPLOYMENT_ENV") \
&& export REACT_APP_BASE_NAME=$(sed -e 's/^"//' -e 's/"$//' <<<"$REACT_APP_BASE_NAME") \
&& export REACT_APP_COMMIT_HASH=$(sed -e 's/^"//' -e 's/"$//' <<<"$REACT_APP_COMMIT_HASH") \
&& export REACT_APP_BUILD_DATE=$(TZ=":Europe/Vienna" date) \
&& export PUBLIC_URL=$(sed -e 's/^"//' -e 's/"$//' <<<"$PUBLIC_URL") \
&& export NODE_ENV=$(sed -e 's/^"//' -e 's/"$//' <<<"$NODE_ENV") \
&& yarn build
Expand Down
6 changes: 6 additions & 0 deletions template/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ async function polyfill(locale: string) {
const App = require("./App").default;
require("./index.css");

// Add commit hash as header comment for deployed versions
const version = document.createComment(
`Version ${process.env.REACT_APP_COMMIT_HASH} @ ${process.env.REACT_APP_BUILD_DATE}`,
);
document.head.prepend(version);

ReactDOM.render(<App />, document.getElementById("root"));

// If you want your app to work offline and load faster, you can change
Expand Down

0 comments on commit 2f20ff4

Please sign in to comment.