mirror of
https://github.com/diced/zipline.git
synced 2026-06-12 19:01:18 -07:00
feat: expose git sha in versioning api
This commit is contained in:
@@ -46,6 +46,8 @@ jobs:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
provenance: false
|
||||
build-args: |
|
||||
ZIPLINE_GIT_SHA=${{ steps.sha.outputs.short_sha }}
|
||||
tags: |
|
||||
ghcr.io/diced/zipline:${{ steps.version.outputs.zipline_version }}-${{ matrix.arch }}
|
||||
ghcr.io/diced/zipline:${{ steps.version.outputs.zipline_version }}-${{ steps.sha.outputs.short_sha }}-${{ matrix.arch }}
|
||||
|
||||
@@ -40,6 +40,8 @@ jobs:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
provenance: false
|
||||
build-args: |
|
||||
ZIPLINE_GIT_SHA=${{ steps.sha.outputs.short_sha }}
|
||||
tags: |
|
||||
ghcr.io/diced/zipline:trunk-${{ matrix.arch }}
|
||||
ghcr.io/diced/zipline:trunk-${{ steps.sha.outputs.short_sha }}-${{ matrix.arch }}
|
||||
|
||||
@@ -42,6 +42,7 @@ COPY --from=builder /zipline/mimes.json ./mimes.json
|
||||
COPY --from=builder /zipline/code.json ./code.json
|
||||
COPY --from=builder /zipline/generated ./generated
|
||||
|
||||
|
||||
RUN pnpm build:prisma
|
||||
|
||||
# clean
|
||||
@@ -49,4 +50,7 @@ RUN rm -rf /tmp/* /root/*
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
ARG ZIPLINE_GIT_SHA
|
||||
ENV ZIPLINE_GIT_SHA=${ZIPLINE_GIT_SHA:-"unknown"}
|
||||
|
||||
CMD ["node", "--enable-source-maps", "build/server"]
|
||||
|
||||
+2
-1
@@ -19,7 +19,8 @@
|
||||
"db:prototype": "prisma db push --skip-generate && prisma generate --no-hints",
|
||||
"db:migrate": "prisma migrate dev --create-only",
|
||||
"docker:engine": "colima start --mount $PWD/themes:w --mount $PWD/uploads:w --mount $PWD/public:w",
|
||||
"docker:compose:dev:up": "docker-compose --file docker-compose.dev.yml up --build -d",
|
||||
"docker:compose:dev:build": "docker-compose --file docker-compose.dev.yml build --build-arg ZIPLINE_GIT_SHA=$(git rev-parse HEAD)",
|
||||
"docker:compose:dev:up": "docker-compose --file docker-compose.dev.yml up -d",
|
||||
"docker:compose:dev:down": "docker-compose --file docker-compose.dev.yml down",
|
||||
"docker:compose:dev:logs": "docker-compose --file docker-compose.dev.yml logs -f"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// TODO: implement version checking against the API at https://zipline.diced.sh
|
||||
|
||||
import { version } from '../../package.json';
|
||||
|
||||
export function gitSha() {
|
||||
const envValue = process.env.ZIPLINE_GIT_SHA;
|
||||
if (envValue && envValue !== 'unknown') return envValue;
|
||||
|
||||
try {
|
||||
const { execSync } = require('child_process');
|
||||
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
|
||||
return commitHash;
|
||||
} catch (error) {
|
||||
console.error('Error getting git commit hash:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getVersion(): {
|
||||
version: string;
|
||||
sha: string | null;
|
||||
} {
|
||||
const sha = gitSha();
|
||||
|
||||
return {
|
||||
version,
|
||||
sha,
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { administratorMiddleware } from '@/server/middleware/administrator';
|
||||
import { userMiddleware } from '@/server/middleware/user';
|
||||
import fastifyPlugin from 'fastify-plugin';
|
||||
import { version } from '../../../../package.json';
|
||||
import { getVersion } from '@/lib/version';
|
||||
|
||||
export type ApiVersionResponse = {
|
||||
version: string;
|
||||
@@ -10,10 +9,10 @@ export type ApiVersionResponse = {
|
||||
export const PATH = '/api/version';
|
||||
export default fastifyPlugin(
|
||||
(server, _, done) => {
|
||||
server.get(PATH, { preHandler: [userMiddleware, administratorMiddleware] }, async (_, res) => {
|
||||
return res.send({
|
||||
version,
|
||||
});
|
||||
server.get(PATH, { preHandler: [userMiddleware] }, async (_, res) => {
|
||||
const details = getVersion();
|
||||
|
||||
return res.send(details);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user