feat: test passing tag to build step

This commit is contained in:
Eli Bosley
2023-08-31 11:34:53 -04:00
parent 878ad60a50
commit b5a6b7c484
5 changed files with 56 additions and 6 deletions

View File

@@ -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

View File

@@ -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 \

9
api/package-lock.json generated
View File

@@ -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",

View File

@@ -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",

45
api/tsup.config.ts Normal file
View File

@@ -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}"`;
}
},
});