Skip to content

Commit 65c21f9

Browse files
committed
Add GIT_COMMIT var to CI build
1 parent f6d2520 commit 65c21f9

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
# Reenable pull_request if we start receiving 3rd party contributions.
6-
# Otherwise all pull_requests will also be push test and we are enforcing
7-
# that code must be up to date with parent in the PRs.
5+
# Re-enable pull_request if we start receiving 3rd party contributions.
6+
# Otherwise, all pull_requests will also be push test and we are enforcing
7+
# that code must be up-to-date with parent in the PRs.
88
#pull_request:
99

1010
jobs:
@@ -76,6 +76,8 @@ jobs:
7676
# the webpack calling on the web container for .dev.yml can take some
7777
# time.
7878
- name: Build and run stack
79+
env:
80+
GIT_COMMIT: ${{ github.sha }}
7981
run: |
8082
printenv
8183
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --build -d worker
@@ -122,6 +124,8 @@ jobs:
122124
poetry-version: 1.2.1
123125

124126
- name: Build and run stack
127+
env:
128+
GIT_COMMIT: ${{ github.sha }}
125129
run: |
126130
printenv
127131
docker-compose up --build -d
@@ -173,6 +177,8 @@ jobs:
173177
poetry-version: 1.2.1
174178

175179
- name: Build and run stack
180+
env:
181+
GIT_COMMIT: ${{ github.sha }}
176182
run: |
177183
export HISTORIAN_ENABLE=true
178184
printenv

alfalfa_web/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
FROM node:16 AS base
2+
ARG GIT_COMMIT
3+
ENV GIT_COMMIT=$GIT_COMMIT
24

35
RUN apt-get update && apt-get install -y \
46
ca-certificates \

alfalfa_web/webpack.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ const WebpackBeforeBuildPlugin = require("before-build-webpack");
1111
const isProd = process.env.NODE_ENV === "production";
1212

1313
const getSha = () => {
14-
const stdout = npmRun.execSync("git rev-parse --short=10 HEAD", { cwd: __dirname });
15-
const sha = stdout.toString().trim();
14+
let sha = process.env.GIT_COMMIT;
15+
if (!sha) {
16+
try {
17+
sha = npmRun.execSync("git rev-parse HEAD", { cwd: __dirname }).toString().trim().substring(0, 7);
18+
} catch (e) {
19+
console.error("Failed to determine git sha");
20+
}
21+
}
1622
fs.writeFileSync(path.resolve(__dirname, "build", "sha.json"), JSON.stringify({ sha }));
1723
};
1824

docker-compose.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ services:
2626
environment:
2727
- AWS_ACCESS_KEY_ID
2828
- AWS_SECRET_ACCESS_KEY
29+
- GIT_COMMIT
2930
- JOB_QUEUE_URL
3031
- MONGO_DB_NAME
3132
- MONGO_URL

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
environment:
2121
- AWS_ACCESS_KEY_ID
2222
- AWS_SECRET_ACCESS_KEY
23+
- GIT_COMMIT
2324
- JOB_QUEUE_URL
2425
- MONGO_DB_NAME
2526
- MONGO_URL

0 commit comments

Comments
 (0)