From 22e1467c40834959a90d4438cd63f05b16c01315 Mon Sep 17 00:00:00 2001 From: Christian Benincasa Date: Mon, 5 Jan 2026 20:47:50 -0500 Subject: [PATCH] chore: more changes and improvements around tunarr versioning --- .github/workflows/build-and-push-docker.yml | 10 ++++++---- .github/workflows/build-and-release-binary.yml | 15 +++++++++------ Dockerfile | 2 ++ server/scripts/bundle-old.ts | 1 + server/scripts/bundle.ts | 1 + server/src/util/env.ts | 4 +++- server/src/util/index.ts | 6 ------ server/src/util/version.ts | 15 ++++++++------- shared/src/util/env.ts | 11 ----------- web/vite.config.ts | 2 +- 10 files changed, 31 insertions(+), 36 deletions(-) delete mode 100644 shared/src/util/env.ts diff --git a/.github/workflows/build-and-push-docker.yml b/.github/workflows/build-and-push-docker.yml index 6bf2b26c..6eec09cf 100644 --- a/.github/workflows/build-and-push-docker.yml +++ b/.github/workflows/build-and-push-docker.yml @@ -7,8 +7,8 @@ on: push: tags: - v[0-9]+.[0-9]+.[0-9]+* - schedule: - - cron: "0 13-21/2 * * *" # every 2 hours during US Eastern daytime + # schedule: + # - cron: "0 13-21/2 * * *" # every 2 hours during US Eastern daytime jobs: typecheck: @@ -120,7 +120,8 @@ jobs: - name: Generate Version Number run: | - echo "TUNARR_VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "TUNARR_VERSION=${{github.ref_name}}" >> $GITHUB_ENV + echo "TUNARR_BUILD=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: Build and push uses: docker/build-push-action@v5 @@ -131,7 +132,8 @@ jobs: build-args: | base_image_tag=${{ matrix.builds.base_tag }} is_edge_build=${{github.ref == format('refs/heads/{0}', 'dev') && github.event_name == 'schedule'}} - tunarr_build=${{ env.TUNARR_VERSION }} + tunarr_version=${{ env.TUNARR_VERSION }} + tunarr_build=${{ env.TUNARR_BUILD }} exec_target=${{ matrix.builds.target }} target: full-stack tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/build-and-release-binary.yml b/.github/workflows/build-and-release-binary.yml index ceba08c9..fbc2b9df 100644 --- a/.github/workflows/build-and-release-binary.yml +++ b/.github/workflows/build-and-release-binary.yml @@ -7,8 +7,8 @@ on: push: tags: - v[0-9]+.[0-9]+.[0-9]+* - schedule: - - cron: "0 13-21/2 * * *" # every 2 hours during US Eastern daytime + #schedule: + # - cron: "0 13-21/2 * * *" # every 2 hours during US Eastern daytime jobs: typecheck: @@ -73,6 +73,7 @@ jobs: - name: "Create env file" run: | touch .env + echo TUNARR_VERSION="${{github.ref_name}}" >> .env echo TUNARR_BUILD="$(git rev-parse --short ${{ github.sha }})" >> .env echo TUNARR_EDGE_BUILD=${{github.ref == format('refs/heads/{0}', 'dev') && (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')}} >> .env echo NODE_ENV=production >> .env @@ -155,7 +156,8 @@ jobs: echo NODE_ENV=production >> .env echo TUNARR_BIND_ADDR=0.0.0.0 >> .env - tunarr_version="$(jq -r .version package.json)" + tunarr_version="${{github.ref_name}}" + tunarr_full_version="${tunarr_version}" if [[ "$TUNARR_EDGE_BUILD" == "true" || "$TUNARR_EDGE_BUILD" == "1" ]]; then is_edge_build=true else @@ -163,9 +165,10 @@ jobs: fi if [[ -n "$TUNARR_BUILD" && "$TUNARR_EDGE_BUILD" == true ]]; then - tunarr_version+="-${build}" + tunarr_full_version+="-${build}" fi echo "TUNARR_VERSION=${tunarr_version}" >> .env + echo "TUNARR_FULL_VERSION=${tunarr_full_version}" >> .env if [[ "$TUNARR_EDGE_BUILD" == true ]]; then release_name="Tunarr-${tunarr_version}-${{ matrix.os.target }}" @@ -189,8 +192,8 @@ jobs: shell: bash run: | brew install coreutils - plutil -replace CFBundleShortVersionString -string "$TUNARR_VERSION" macos/Tunarr/Tunarr/Info.plist - plutil -replace CFBundleVersion -string "$TUNARR_VERSION" macos/Tunarr/Tunarr/Info.plist + plutil -replace CFBundleShortVersionString -string "$TUNARR_FULL_VERSION" macos/Tunarr/Tunarr/Info.plist + plutil -replace CFBundleVersion -string "$TUNARR_FULL_VERSION" macos/Tunarr/Tunarr/Info.plist if [[ "$TUNARR_EDGE_BUILD" == "true" || "$TUNARR_EDGE_BUILD" == "1" ]]; then scripts/bundle-macos.sh "tunarr-${{ matrix.os.target }}" "${{ matrix.os.arch }}" "${{matrix.os.target}}" diff --git a/Dockerfile b/Dockerfile index 107b09c4..e412fc72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,11 +85,13 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-l FROM sources AS build-full-stack ARG exec_target=linux-x64 ARG is_edge_build +ARG tunarr_version ARG tunarr_build ARG exec_target=linux-x64 # Build common modules RUN <> .env echo TUNARR_BUILD="${tunarr_build}" >> .env echo TUNARR_EDGE_BUILD=${is_edge_build} >> .env echo TUNARR_BUILD_BASE_TAG=${base_image_tag} >> .env diff --git a/server/scripts/bundle-old.ts b/server/scripts/bundle-old.ts index 60f89b3a..29594425 100644 --- a/server/scripts/bundle-old.ts +++ b/server/scripts/bundle-old.ts @@ -74,6 +74,7 @@ const result = await esbuild.build({ metafile: true, define: { 'process.env.NODE_ENV': '"production"', + 'process.env.TUNARR_VERSION': `"${process.env.TUNARR_VERSION}"`, 'process.env.TUNARR_BUILD': `"${process.env.TUNARR_BUILD}"`, 'process.env.TUNARR_EDGE_BUILD': `"${isEdgeBuild}"`, 'import.meta.url': '__import_meta_url', diff --git a/server/scripts/bundle.ts b/server/scripts/bundle.ts index a7bfcecc..f0ae34bf 100644 --- a/server/scripts/bundle.ts +++ b/server/scripts/bundle.ts @@ -88,6 +88,7 @@ const result = await esbuild.build({ metafile: true, define: { 'process.env.NODE_ENV': '"production"', + 'process.env.TUNARR_VERSION': `"${process.env.TUNARR_VERSION}"`, 'process.env.TUNARR_BUILD': `"${process.env.TUNARR_BUILD}"`, 'process.env.TUNARR_EDGE_BUILD': `"${isEdgeBuild}"`, 'import.meta.url': '__import_meta_url', diff --git a/server/src/util/env.ts b/server/src/util/env.ts index 7fbb438d..9d34402e 100644 --- a/server/src/util/env.ts +++ b/server/src/util/env.ts @@ -7,7 +7,8 @@ export const SERVER_PORT_ENV_VAR = 'TUNARR_SERVER_PORT'; export const PRINT_ROUTES_ENV_VAR = 'TUNARR_SERVER_PRINT_ROUTES'; export const TRUST_PROXY_ENV_VAR = 'TUNARR_SERVER_TRUST_PROXY'; export const BIND_ADDR_ENV_VAR = 'TUNARR_BIND_ADDR'; -export const BUILD_ENV_VAR = 'TUNARR_BUILD'; +export const BUILD_ENV_VAR = 'TUNARR_VERSION'; +export const COMMIT_SHA_ENV_VAR = 'TUNARR_BUILA_SHA'; export const BASE_IMAGE_TAG_ENV_VAR = 'TUNARR_BUILD_BASE_TAG'; export const IS_EDGE_BUILD_ENV_VAR = 'TUNARR_EDGE_BUILD'; export const USE_WORKER_POOL_ENV_VAR = 'TUNARR_USE_WORKER_POOL'; @@ -33,6 +34,7 @@ export const TUNARR_ENV_VARS = { TRUST_PROXY_ENV_VAR, BIND_ADDR_ENV_VAR, BUILD_ENV_VAR, + COMMIT_SHA_ENV_VAR, IS_EDGE_BUILD_ENV_VAR, BASE_IMAGE_TAG_ENV_VAR, USE_WORKER_POOL_ENV_VAR, diff --git a/server/src/util/index.ts b/server/src/util/index.ts index ce222933..4241772a 100644 --- a/server/src/util/index.ts +++ b/server/src/util/index.ts @@ -34,7 +34,6 @@ import { format, inspect } from 'node:util'; import { isPromise } from 'node:util/types'; import type { DeepReadonly, DeepWritable, NonEmptyArray } from 'ts-essentials'; import type { NewProgramDao, ProgramDao } from '../db/schema/Program.ts'; -import { getBooleanEnvVar, TUNARR_ENV_VARS } from './env.ts'; dayjs.extend(duration); @@ -467,11 +466,6 @@ export const currentEnv = once(() => { export const isProduction = currentEnv() === 'production'; export const isDev = currentEnv() === 'development'; export const isTest = currentEnv() === 'test'; -export const isEdgeBuild = getBooleanEnvVar( - TUNARR_ENV_VARS.IS_EDGE_BUILD_ENV_VAR, - false, -); -export const tunarrBuild = process.env.TUNARR_BUILD; export const zipWithIndex = ( seq: readonly T[], diff --git a/server/src/util/version.ts b/server/src/util/version.ts index 888bceba..879236eb 100644 --- a/server/src/util/version.ts +++ b/server/src/util/version.ts @@ -1,11 +1,6 @@ import tunarrPackage from '../../package.json' with { type: 'json' }; -import { getEnvVar, TUNARR_ENV_VARS } from './env.ts'; -import { - isEdgeBuild, - isNonEmptyString, - isProduction, - tunarrBuild, -} from './index.js'; +import { getBooleanEnvVar, getEnvVar, TUNARR_ENV_VARS } from './env.ts'; +import { isNonEmptyString, isProduction } from './index.js'; let tunarrVersion: string; export const getTunarrVersion = () => { @@ -14,6 +9,12 @@ export const getTunarrVersion = () => { tunarrVersion = getEnvVar(TUNARR_ENV_VARS.BUILD_ENV_VAR) ?? tunarrPackage.version ?? ''; + const isEdgeBuild = getBooleanEnvVar( + TUNARR_ENV_VARS.IS_EDGE_BUILD_ENV_VAR, + false, + ); + const tunarrBuild = getEnvVar(TUNARR_ENV_VARS.COMMIT_SHA_ENV_VAR); + if (isNonEmptyString(tunarrBuild) && isEdgeBuild) { tunarrVersion += `-${tunarrBuild}`; } diff --git a/shared/src/util/env.ts b/shared/src/util/env.ts deleted file mode 100644 index b98cee7b..00000000 --- a/shared/src/util/env.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Duplicated from server - reference these instead. -// export const currentEnv = once(() => { -// const env = process.env['NODE_ENV']; -// return env ?? 'production'; -// }); - -// export const isProduction = currentEnv() === 'production'; -// export const isDev = currentEnv() === 'development'; -// export const isTest = currentEnv() === 'test'; -// export const isEdgeBuild = process.env['TUNARR_EDGE_BUILD'] === 'true'; -// export const tunarrBuild = process.env['TUNARR_BUILD']; diff --git a/web/vite.config.ts b/web/vite.config.ts index f725d2f6..43b19562 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -13,7 +13,7 @@ export const IS_EDGE_BUILD_ENV_VAR = 'TUNARR_EDGE_BUILD'; const packageVersion = packageDef.version; const version = (() => { - let tunarrVersion = packageVersion; + let tunarrVersion = process.env.TUNARR_VERSION ?? packageVersion; const build = process.env[BUILD_ENV_VAR] ?? ''; const isEdgeBuildValue = process.env[IS_EDGE_BUILD_ENV_VAR]; const isEdgeBuild = isEdgeBuildValue === 'true' || isEdgeBuildValue === '1';