Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): display app version again #14844

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app-shell-odd/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import pkg from './package.json'
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import postCssImport from 'postcss-import'
import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'
import type {UserConfig} from 'vite'

export default defineConfig(
async (): Promise<UserConfig> => {
Expand Down
5 changes: 3 additions & 2 deletions app-shell/electron-builder.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const path = require('path')
const { versionForProject } = require('../scripts/git-version')

const {
OT_APP_DEPLOY_BUCKET,
Expand Down Expand Up @@ -45,7 +44,9 @@ module.exports = async () => ({
},
],
extraMetadata: {
version: await versionForProject(project),
version: await (
await import('../scripts/git-version.mjs')
).versionForProject(project),
productName: project === 'robot-stack' ? 'Opentrons' : 'Opentrons-OT3',
},
extraResources: USE_PYTHON ? ['python'] : [],
Expand Down
5 changes: 3 additions & 2 deletions app-shell/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import pkg from './package.json'
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
import { defineConfig } from 'vite'
import type { UserConfig } from 'vite'

export default defineConfig(
async (): Promise<UserConfig> => {
Expand Down
109 changes: 59 additions & 50 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,66 @@ import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'
import { versionForProject } from '../scripts/git-version.mjs'
import type { UserConfig } from 'vite'

export default defineConfig({
// this makes imports relative rather than absolute
base: '',
build: {
// Relative to the root
outDir: 'dist',
},
plugins: [
react({
include: '**/*.tsx',
babel: {
// Use babel.config.js files
configFile: true,
export default defineConfig(
async(): Promise<UserConfig> => {
const project = process.env.OPENTRONS_PROJECT ?? 'robot-stack'
const version = await versionForProject(project)
return {
// this makes imports relative rather than absolute
base: '',
build: {
// Relative to the root
outDir: 'dist',
},
}),
],
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
},
},
css: {
postcss: {
plugins: [
postCssImport({ root: 'src/' }),
postCssApply(),
postColorModFunction(),
postCssPresetEnv({ stage: 0 }),
lostCss(),
react({
include: '**/*.tsx',
babel: {
// Use babel.config.js files
configFile: true,
},
}),
],
},
},
define: {
'process.env': process.env,
global: 'globalThis',
},
resolve: {
alias: {
'@opentrons/components/styles': path.resolve(
'../components/src/index.module.css'
),
'@opentrons/components': path.resolve('../components/src/index.ts'),
'@opentrons/shared-data': path.resolve('../shared-data/js/index.ts'),
'@opentrons/step-generation': path.resolve(
'../step-generation/src/index.ts'
),
'@opentrons/api-client': path.resolve('../api-client/src/index.ts'),
'@opentrons/react-api-client': path.resolve(
'../react-api-client/src/index.ts'
),
},
},
})
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
},
},
css: {
postcss: {
plugins: [
postCssImport({ root: 'src/' }),
postCssApply(),
postColorModFunction(),
postCssPresetEnv({ stage: 0 }),
lostCss(),
],
},
},
define: {
'process.env': process.env,
global: 'globalThis',
_PKG_VERSION_: JSON.stringify(version),
_OPENTRONS_PROJECT_: JSON.stringify(project),
},
resolve: {
alias: {
'@opentrons/components/styles': path.resolve(
'../components/src/index.module.css'
),
'@opentrons/components': path.resolve('../components/src/index.ts'),
'@opentrons/shared-data': path.resolve('../shared-data/js/index.ts'),
'@opentrons/step-generation': path.resolve(
'../step-generation/src/index.ts'
),
'@opentrons/api-client': path.resolve('../api-client/src/index.ts'),
'@opentrons/react-api-client': path.resolve(
'../react-api-client/src/index.ts'
),
},
},
}
})
7 changes: 4 additions & 3 deletions discovery-client/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import pkg from './package.json'
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import postCssImport from 'postcss-import'
import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'

import type { UserConfig } from 'vite
'
export default defineConfig(
async (): Promise<UserConfig> => {
const project = process.env.OPENTRONS_PROJECT ?? 'robot-stack'
Expand Down
2 changes: 1 addition & 1 deletion discovery-client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const webpackMerge = require('webpack-merge')
const { DefinePlugin } = require('webpack')
const { nodeBaseConfig } = require('@opentrons/webpack-config')
const { versionForProject } = require('../scripts/git-version')
const { versionForProject } = require('../scripts/git-version.mjs')

const ENTRY_INDEX = path.join(__dirname, 'src/index.ts')
const ENTRY_CLI = path.join(__dirname, 'src/cli.ts')
Expand Down
2 changes: 1 addition & 1 deletion labware-library/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { baseConfig } = require('@opentrons/webpack-config')
// const {baseConfig, DEV_MODE} = require('@opentrons/webpack-config')
const pkg = require('./package.json')

const { versionForProject } = require('../scripts/git-version')
const { versionForProject } = require('../scripts/git-version.mjs')

const JS_ENTRY = path.join(__dirname, 'src/index.tsx')
const HTML_ENTRY = path.join(__dirname, 'src/index.hbs')
Expand Down
5 changes: 3 additions & 2 deletions protocol-designer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import postCssImport from 'postcss-import'
import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import type { UserConfig } from 'vite'

const testAliases: {} | { 'file-saver': string } =
process.env.CYPRESS === '1'
Expand Down
55 changes: 38 additions & 17 deletions scripts/deploy/create-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ const parseArgs = require('./lib/parseArgs')
const conventionalChangelog = require('conventional-changelog')
const semver = require('semver')
const { Octokit } = require('@octokit/rest')
const {
detailsFromTag,
tagFromDetails,
prefixForProject,
monorepoGit,
} = require('../git-version')

const USAGE =
'\nUsage:\n node ./scripts/deploy/create-release <token> <tag> [--deploy] [--allow-old]'
Expand Down Expand Up @@ -81,9 +75,35 @@ function versionPrevious(currentVersion, previousVersions) {
return releasesOfGEQKind.length === 0 ? null : releasesOfGEQKind[0]
}

async function gitVersion() {
let imported
if (imported === undefined) {
imported = await import('../git-version.mjs')
}
return imported
}

async function monorepoGit() {
return await (await gitVersion()).monorepoGit()
}

async function detailsFromTag(tag) {
return await (await gitVersion()).detailsFromTag(tag)
}

async function tagFromDetails(project, version) {
return (await gitVersion()).tagFromDetails(project, version)
}

async function prefixForProject(project) {
return (await gitVersion()).prefixForProject(project)
}

async function versionDetailsFromGit(tag, allowOld) {
if (!allowOld) {
const last100 = await monorepoGit().log({ from: 'HEAD~100', to: 'HEAD' })
const git = await monorepoGit()
const last100 = await git.log({ from: 'HEAD~100', to: 'HEAD' })

if (!last100.all.some(commit => commit.refs.includes('tag: ' + tag))) {
throw new Error(
`Cannot find tag ${tag} in last 100 commits. You must run this script from a ref with ` +
Expand All @@ -94,9 +114,8 @@ async function versionDetailsFromGit(tag, allowOld) {
}

const [project, currentVersion] = detailsFromTag(tag)

const allTags = (await monorepoGit().tags([prefixForProject(project) + '*']))
.all
const prefix = await prefixForProject(project)
const allTags = (await monorepoGit().tags([prefix + '*'])).all
if (!allTags.includes(tag)) {
throw new Error(
`Tag ${tag} does not exist - create it before running this script`
Expand All @@ -123,14 +142,15 @@ async function buildChangelog(project, currentVersion, previousVersion) {
`## ${currentVersion}` + `\nFirst release for ${titleForProject(project)}`
)
}
const previousTag = tagFromDetails(project, previousVersion)

const previousTag = await tagFromDetails(project, previousVersion)
const currentTag = await tagFromDetails(project, currentVersion)
const prefix = await prefixForProject(Project)
const changelogStream = conventionalChangelog(
{ preset: 'angular', tagPrefix: prefixForProject(project) },
{ preset: 'angular', tagPrefix: prefix },
{
version: currentVersion,
currentTag: tagFromDetails(project, currentVersion),
previousTag: previousTag,
currentTag,
previousTag,
host: 'https://github.com',
owner: REPO_DETAILS.owner,
repository: REPO_DETAILS.repo,
Expand Down Expand Up @@ -203,6 +223,7 @@ async function main() {
currentVersion,
previousVersion,
] = await versionDetailsFromGit(tag, allowOld)
const prefix = await prefixForProject(project)
const changelog = await buildChangelog(
project,
currentVersion,
Expand All @@ -211,8 +232,8 @@ async function main() {
const truncatedChangelog = truncateAndAnnotate(
changelog,
10000,
prefixForProject(project) + previousVersion,
prefixForProject(project) + currentVersion
prefix + previousVersion,
prefix + currentVersion
)
return await createRelease(
token,
Expand Down
28 changes: 10 additions & 18 deletions scripts/git-version.js → scripts/git-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
// What that all boils down to is that we need, and this module provides, an interface to get the version of a
// given project that currently exists in the monorepo.

const git = require('simple-git')
const { dirname } = require('path')
const REPO_BASE = dirname(__dirname)
import git from 'simple-git'
import { dirname } from 'path'
import { fileURLToPath } from 'url'
const REPO_BASE = dirname(dirname(fileURLToPath(import.meta.url)))

function monorepoGit() {
export function monorepoGit() {
return git({ baseDir: REPO_BASE })
}

const detailsFromTag = tag =>
export const detailsFromTag = tag =>
tag.includes('@') ? tag.split('@') : ['robot-stack', tag.substring(1)]

function tagFromDetails(project, version) {
export function tagFromDetails(project, version) {
const prefix = prefixForProject(project)
return `${prefix}${version}`
}

function prefixForProject(project) {
export function prefixForProject(project) {
if (project === 'robot-stack') {
return 'v'
} else {
return `${project}@`
}
}

async function latestTagForProject(project) {
export async function latestTagForProject(project) {
return (
await monorepoGit().raw([
'describe',
Expand All @@ -50,7 +51,7 @@ async function latestTagForProject(project) {
).trim()
}

async function versionForProject(project) {
export async function versionForProject(project) {
return latestTagForProject(project)
.then(tag => detailsFromTag(tag)[1])
.catch(error => {
Expand All @@ -60,12 +61,3 @@ async function versionForProject(project) {
return '0.0.0-dev'
})
}

module.exports = {
detailsFromTag,
tagFromDetails,
prefixForProject,
latestTagForProject,
versionForProject,
monorepoGit,
}
2 changes: 1 addition & 1 deletion scripts/update-releases-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs/promises')

// Updates a releases historical manifest with a release's version.

const versionFinder = require('./git-version')
const versionFinder = require('./git-version.mjs')

const parseArgs = require('./deploy/lib/parseArgs')
const USAGE =
Expand Down
2 changes: 1 addition & 1 deletion usb-bridge/node-client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const webpackMerge = require('webpack-merge')
const { DefinePlugin } = require('webpack')
const { nodeBaseConfig } = require('@opentrons/webpack-config')
const { versionForProject } = require('../../scripts/git-version')
const { versionForProject } = require('../../scripts/git-version.mjs')

const ENTRY_INDEX = path.join(__dirname, 'src/index.ts')
const ENTRY_CLI = path.join(__dirname, 'src/cli.ts')
Expand Down
Loading