From b5a6b7c48417dea69a68f0315a8a1b11f8f422dc Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Thu, 31 Aug 2023 11:34:53 -0400 Subject: [PATCH] feat: test passing tag to build step --- .github/workflows/pull-request.yml | 3 +- api/Dockerfile | 3 +- api/package-lock.json | 9 ++++-- api/package.json | 2 +- api/tsup.config.ts | 45 ++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 api/tsup.config.ts diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index fd7c90f89..5f81e76dd 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -150,7 +150,8 @@ jobs: cache-to: type=gha,mode=max - name: Run Docker Compose - run: docker run localhost:5000/unraid-api:builder npm run build-pkg + run: docker run -e GIT_SHA=$(git rev-parse --short HEAD) IS_TAGGED=$(git describe --tags --abbrev=0 --exact-match) localhost:5000/unraid-api:builder npm run build-pkg + - name: Set Hashes id: set-hashes diff --git a/api/Dockerfile b/api/Dockerfile index 1f8745800..29a22ee74 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -6,7 +6,8 @@ FROM node:18.17.1-alpine As development # Install build tools and dependencies RUN apk add --no-cache \ bash \ - alpine-sdk \ + make \ + gcc \ python3 \ libvirt-dev \ jq \ diff --git a/api/package-lock.json b/api/package-lock.json index e325d3679..3e057341f 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -101,7 +101,7 @@ "@types/ini": "^1.3.31", "@types/lodash": "^4.14.192", "@types/mustache": "^4.2.2", - "@types/node": "^18.15.11", + "@types/node": "^18.17.12", "@types/pidusage": "^2.0.2", "@types/pify": "^5.0.1", "@types/semver": "^7.3.13", @@ -3259,7 +3259,8 @@ }, "node_modules/@types/node": { "version": "18.17.12", - "license": "MIT" + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.12.tgz", + "integrity": "sha512-d6xjC9fJ/nSnfDeU0AMDsaJyb1iHsqCSOdi84w4u+SlN/UgQdY5tRhpMzaFYsI4mnpvgTivEaQd0yOUhAtOnEQ==" }, "node_modules/@types/node-fetch": { "version": "2.6.3", @@ -17601,7 +17602,9 @@ "dev": true }, "@types/node": { - "version": "18.17.12" + "version": "18.17.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.12.tgz", + "integrity": "sha512-d6xjC9fJ/nSnfDeU0AMDsaJyb1iHsqCSOdi84w4u+SlN/UgQdY5tRhpMzaFYsI4mnpvgTivEaQd0yOUhAtOnEQ==" }, "@types/node-fetch": { "version": "2.6.3", diff --git a/api/package.json b/api/package.json index b0b2bde13..8f7c3327a 100644 --- a/api/package.json +++ b/api/package.json @@ -146,7 +146,7 @@ "@types/ini": "^1.3.31", "@types/lodash": "^4.14.192", "@types/mustache": "^4.2.2", - "@types/node": "^18.15.11", + "@types/node": "^18.17.12", "@types/pidusage": "^2.0.2", "@types/pify": "^5.0.1", "@types/semver": "^7.3.13", diff --git a/api/tsup.config.ts b/api/tsup.config.ts new file mode 100644 index 000000000..2e8a092d3 --- /dev/null +++ b/api/tsup.config.ts @@ -0,0 +1,45 @@ +import { execSync } from 'child_process'; +import 'dotenv/config'; +import { defineConfig } from 'tsup'; +import { version } from './package.json'; + +const runCommand = (command: string) => { + try { + return execSync(command, { stdio: 'pipe' }).toString().trim(); + } catch { + return; + } +}; + +export default defineConfig({ + name: 'tsup', + target: 'node18', + entry: { + 'unraid-api': 'src/cli.ts', + index: 'src/index.ts', + }, + metafile: true, + splitting: false, + sourcemap: true, + clean: true, + external: ['@vmngr/libvirt'], + esbuildOptions(options) { + if (!options.define) options.define = {}; + console.log('IS TAGGED', process.env.IS_TAGGED); + if (process.env.GIT_SHA && process.env.IS_TAGGED) { + const gitShortSHA = process.env.GIT_SHA; + const isCommitTagged = process.env.IS_TAGGED; + options.define['process.env.VERSION'] = isCommitTagged + ? `"${version}"` + : `"${version}+${gitShortSHA}"`; + } else { + const gitShortSHA = runCommand('git rev-parse --short HEAD'); + const isCommitTagged = + runCommand('git describe --tags --abbrev=0 --exact-match') !== + undefined; + options.define['process.env.VERSION'] = isCommitTagged + ? `"${version}"` + : `"${version}+${gitShortSHA}"`; + } + }, +});