diff --git a/build-tools/packages/build-cli/src/test/commands/release/fromTag.test.ts b/build-tools/packages/build-cli/src/test/commands/release/fromTag.test.ts index 18fa2216d3bb..a226e13eb57c 100644 --- a/build-tools/packages/build-cli/src/test/commands/release/fromTag.test.ts +++ b/build-tools/packages/build-cli/src/test/commands/release/fromTag.test.ts @@ -3,45 +3,86 @@ * Licensed under the MIT License. */ -import type { ReleaseVersion, VersionBumpType } from "@fluid-tools/version-tools"; +import { Config } from "@oclif/core"; import { runCommand } from "@oclif/test"; import * as chai from "chai"; import { expect } from "chai"; import assertArrays from "chai-arrays"; import { describe, it } from "mocha"; - -import type { ReleaseGroup, ReleasePackage } from "../../../releaseGroups.js"; +import type { TaskOptions } from "simple-git"; +import FromTagCommand from "../../../commands/release/fromTag.js"; chai.use(assertArrays); -interface jsonOutput { - packageOrReleaseGroup: ReleaseGroup | ReleasePackage; - title: string; - tag: string; - date?: Date; - releaseType: VersionBumpType; - version: ReleaseVersion; - previousVersion?: ReleaseVersion; - previousTag?: string; -} - describe("flub release fromTag", () => { - const expected = { - version: "0.26.1", - date: "2023-10-26T19:35:13.000Z", - packageOrReleaseGroup: "build-tools", - previousTag: "build-tools_v0.26.0", - previousVersion: "0.26.0", - releaseType: "patch", - tag: "build-tools_v0.26.1", - title: "build-tools v0.26.1 (patch)", - }; - - it("--json", async () => { - const { stdout } = await runCommand(["release:fromTag", "build-tools_v0.26.1", "--json"], { - root: import.meta.url, + // Test both against a mocked git repo and the real one. + // The real case is skipped by default to avoid test failures in environments where the git repo is not present or the tags are not checked out. + for (const mock of [true, false]) { + // When mocking the git repo, pick a tag that does not (and will never) exist, to ensure mocking works. + const tagOffset = mock ? 50 : 0; + const previousVersion = `0.26.${tagOffset}`; + const version = `0.26.${tagOffset + 1}`; + const previousTag = `build-tools_v${previousVersion}`; + const tag = `build-tools_v${version}`; + const date = new Date("2023-10-26T19:35:13.000Z"); + + const expected = { + version, + date, + packageOrReleaseGroup: "build-tools", + previousTag, + previousVersion, + releaseType: "patch", + tag, + title: `build-tools v${version} (patch)`, + }; + + // Mocha's skip functionality (via `this`) does not work with arrow functions. + // eslint-disable-next-line prefer-arrow-callback + it(`--json (Mock: ${mock})`, async function () { + let output: Awaited>; + if (mock) { + const config = await Config.load({ root: import.meta.url }); + const command = new FromTagCommand([tag, "--json"], config); + await command.init(); + const context = await command.getContext(); + const gitRepo = await context.getGitRepository(); + const simpleGit = gitRepo.gitClient; + + // Mock gitClient.tags to return a fixed set of build-tools tags, so the test + // does not depend on git tags being present in the local checkout. + simpleGit.tags = (async (options: TaskOptions = []) => { + expect(options).to.deep.equal(["--list", "build-tools_v*"]); + return { + all: [previousTag, tag], + latest: tag, + }; + }) as unknown as (typeof simpleGit)["tags"]; + + // Mock gitClient.show to return fixed commit dates for each tag. + simpleGit.show = (async (options: TaskOptions = []) => { + const tagDates: Record = { + [tag]: date, + // This date is not used, but we set it to a different value to ensure the command pulls the date from the correct tag. + [previousTag]: new Date("2000-01-14T00:00:00.000Z"), + }; + const queriedTag = (options as string[]).at(-1) ?? ""; + expect(options).to.deep.equal(["-s", "--format=%cI", queriedTag]); + return tagDates[queriedTag]?.toISOString() ?? ""; + }) as unknown as (typeof simpleGit)["show"]; + + output = await command.run(); + } else { + // Skip real git test by default, as it requires specific tags to be present in the local repo, which may not be the case in all environments. + // Disable this skip if you want to test against the actual git repo and tags. + this.skip(); + const { stdout } = await runCommand(["release:fromTag", tag, "--json"], { + root: import.meta.url, + }); + output = JSON.parse(stdout); + } + + expect(JSON.stringify(output)).to.equal(JSON.stringify(expected)); }); - const output: jsonOutput = JSON.parse(stdout) as jsonOutput; - expect(output).to.deep.equal(expected); - }); + } }); diff --git a/tools/pipelines/build-docs.yml b/tools/pipelines/build-docs.yml index adc7a0f4135b..64c20ee318e6 100644 --- a/tools/pipelines/build-docs.yml +++ b/tools/pipelines/build-docs.yml @@ -100,6 +100,8 @@ stages: path: $(FluidFrameworkDirectory) submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-install-build-tools.yml@self parameters: @@ -168,6 +170,8 @@ stages: - checkout: self submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self @@ -226,6 +230,8 @@ stages: - checkout: self submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self @@ -293,6 +299,8 @@ stages: path: $(FluidFrameworkDirectory) submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self @@ -345,6 +353,8 @@ stages: - checkout: self submodules: false clean: true + fetchDepth: 1 + fetchTags: false - task: DownloadPipelineArtifact@2 displayName: 'Copy fluidframework-docs to "build" folder' diff --git a/tools/pipelines/build-performance-observability.yml b/tools/pipelines/build-performance-observability.yml index dc3177e44ca8..2340fceb34b1 100644 --- a/tools/pipelines/build-performance-observability.yml +++ b/tools/pipelines/build-performance-observability.yml @@ -94,6 +94,8 @@ extends: steps: - checkout: self clean: true + fetchDepth: 1 + fetchTags: false path: ${{ variables.FluidFrameworkDirectory }} - template: /tools/pipelines/templates/include-use-node-version.yml@self diff --git a/tools/pipelines/deploy-website.yml b/tools/pipelines/deploy-website.yml index 3551f072562b..7732d6db1de4 100644 --- a/tools/pipelines/deploy-website.yml +++ b/tools/pipelines/deploy-website.yml @@ -127,6 +127,8 @@ stages: path: ${{ variables.FluidFrameworkDirectory }} submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self @@ -199,6 +201,8 @@ stages: path: ${{ variables.FluidFrameworkDirectory }} submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self @@ -266,6 +270,8 @@ stages: path: ${{ variables.FluidFrameworkDirectory }} submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self @@ -319,6 +325,8 @@ stages: path: ${{ variables.FluidFrameworkDirectory }} submodules: false clean: true + fetchDepth: 1 + fetchTags: false - task: DownloadPipelineArtifact@2 displayName: 'Copy fluidframework-docs to "build" folder' diff --git a/tools/pipelines/publish-api-model-artifact.yml b/tools/pipelines/publish-api-model-artifact.yml index a4d3864694dd..c64beee82f22 100644 --- a/tools/pipelines/publish-api-model-artifact.yml +++ b/tools/pipelines/publish-api-model-artifact.yml @@ -113,6 +113,8 @@ stages: path: ${{ variables.FluidFrameworkDirectory }} submodules: false clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-install-build-tools.yml@self parameters: @@ -257,6 +259,8 @@ stages: - checkout: self submodules: false clean: true + fetchDepth: 1 + fetchTags: false - task: TriggerBuild@4 condition: eq(variables['shouldDeploy'], 'true') inputs: diff --git a/tools/pipelines/repo-policy-check.yml b/tools/pipelines/repo-policy-check.yml index 7618f5ec4419..44c5afeab066 100644 --- a/tools/pipelines/repo-policy-check.yml +++ b/tools/pipelines/repo-policy-check.yml @@ -89,6 +89,8 @@ extends: " - checkout: self path: ${{ variables.FluidFrameworkDirectory }} + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self - template: /tools/pipelines/templates/include-install-pnpm.yml@self parameters: diff --git a/tools/pipelines/templates/build-docker-service.yml b/tools/pipelines/templates/build-docker-service.yml index aa18cd88333b..e24195ca034b 100644 --- a/tools/pipelines/templates/build-docker-service.yml +++ b/tools/pipelines/templates/build-docker-service.yml @@ -200,6 +200,8 @@ extends: clean: true lfs: false submodules: false + fetchDepth: 1 + fetchTags: false - task: Bash@3 displayName: Parameters diff --git a/tools/pipelines/templates/build-npm-client-package.yml b/tools/pipelines/templates/build-npm-client-package.yml index 7a464f931192..02cdf4fde203 100644 --- a/tools/pipelines/templates/build-npm-client-package.yml +++ b/tools/pipelines/templates/build-npm-client-package.yml @@ -229,6 +229,8 @@ extends: clean: true lfs: '${{ parameters.checkoutSubmodules }}' submodules: '${{ parameters.checkoutSubmodules }}' + fetchDepth: 1 + fetchTags: false - script: | echo "commit sha: $(Build.SourceVersion)" @@ -589,6 +591,8 @@ extends: clean: true lfs: '${{ parameters.checkoutSubmodules }}' submodules: '${{ parameters.checkoutSubmodules }}' + fetchDepth: 1 + fetchTags: false - script: | echo "commit: $(COMMIT_SHA)" @@ -753,6 +757,8 @@ extends: clean: true lfs: '${{ parameters.checkoutSubmodules }}' submodules: '${{ parameters.checkoutSubmodules }}' + fetchDepth: 1 + fetchTags: false - script: | echo "commit: $(COMMIT_SHA)" diff --git a/tools/pipelines/templates/build-npm-package.yml b/tools/pipelines/templates/build-npm-package.yml index 6ba51216b205..d0df92814e8b 100644 --- a/tools/pipelines/templates/build-npm-package.yml +++ b/tools/pipelines/templates/build-npm-package.yml @@ -218,6 +218,8 @@ extends: clean: true lfs: '${{ parameters.checkoutSubmodules }}' submodules: '${{ parameters.checkoutSubmodules }}' + fetchDepth: 1 + fetchTags: false - task: Bash@3 displayName: Parameters diff --git a/tools/pipelines/templates/include-policy-check.yml b/tools/pipelines/templates/include-policy-check.yml index fabfae50e000..167fb2113861 100644 --- a/tools/pipelines/templates/include-policy-check.yml +++ b/tools/pipelines/templates/include-policy-check.yml @@ -35,6 +35,8 @@ stages: steps: - checkout: self path: $(FluidFrameworkDirectory) + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self - template: /tools/pipelines/templates/include-install-pnpm.yml@self diff --git a/tools/pipelines/templates/include-publish-docker-service-steps.yml b/tools/pipelines/templates/include-publish-docker-service-steps.yml index 09fb1584fb9d..397b4935e856 100644 --- a/tools/pipelines/templates/include-publish-docker-service-steps.yml +++ b/tools/pipelines/templates/include-publish-docker-service-steps.yml @@ -93,6 +93,8 @@ jobs: steps: - checkout: self clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-git-tag-steps.yml@self parameters: tagName: ${{ parameters.tagName }} diff --git a/tools/pipelines/templates/include-publish-npm-package-deployment.yml b/tools/pipelines/templates/include-publish-npm-package-deployment.yml index 64eefcf1f9e3..b8d86e51a9cc 100644 --- a/tools/pipelines/templates/include-publish-npm-package-deployment.yml +++ b/tools/pipelines/templates/include-publish-npm-package-deployment.yml @@ -161,6 +161,8 @@ jobs: steps: - checkout: self clean: true + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-git-tag-steps.yml@self parameters: tagName: ${{ parameters.tagName }} diff --git a/tools/pipelines/templates/include-test-real-service.yml b/tools/pipelines/templates/include-test-real-service.yml index ebd66f036a58..116cdc6a43f7 100644 --- a/tools/pipelines/templates/include-test-real-service.yml +++ b/tools/pipelines/templates/include-test-real-service.yml @@ -177,6 +177,8 @@ stages: - checkout: ff_pipeline_host path: $(FFPipelineHostDirectory) clean: true + fetchDepth: 1 + fetchTags: false # ADO doesn't support checking out refs that are determined at pipeline queue time as ours likely would be # (where the ref is a function of one of the pipeline resource inputs). See docs here: @@ -185,6 +187,8 @@ stages: - checkout: self path: $(FluidFrameworkDirectory) clean: true + fetchDepth: 1 + fetchTags: false - bash: | git fetch --depth=1 origin $FF_SOURCE_VERSION diff --git a/tools/pipelines/templates/upload-dev-manifest.yml b/tools/pipelines/templates/upload-dev-manifest.yml index 86219bab572f..897530f10b93 100644 --- a/tools/pipelines/templates/upload-dev-manifest.yml +++ b/tools/pipelines/templates/upload-dev-manifest.yml @@ -15,6 +15,8 @@ jobs: steps: - checkout: self path: $(FluidFrameworkDirectory) + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self - template: /tools/pipelines/templates/include-install-build-tools.yml@self parameters: diff --git a/tools/pipelines/templates/upload-server-manifest.yml b/tools/pipelines/templates/upload-server-manifest.yml index 5a037ef0193f..6da61baa18b2 100644 --- a/tools/pipelines/templates/upload-server-manifest.yml +++ b/tools/pipelines/templates/upload-server-manifest.yml @@ -20,6 +20,8 @@ jobs: steps: - checkout: self path: $(FluidFrameworkDirectory) + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self - template: /tools/pipelines/templates/include-install-build-tools.yml@self parameters: diff --git a/tools/pipelines/templates/upload-telemetry/include-stage-upload-telemetry.yml b/tools/pipelines/templates/upload-telemetry/include-stage-upload-telemetry.yml index 3d85a3709adf..85b24692549a 100644 --- a/tools/pipelines/templates/upload-telemetry/include-stage-upload-telemetry.yml +++ b/tools/pipelines/templates/upload-telemetry/include-stage-upload-telemetry.yml @@ -42,6 +42,8 @@ stages: steps: - checkout: ff_pipeline_host path: $(FFPipelineHostDirectory) + fetchDepth: 1 + fetchTags: false - template: /tools/pipelines/templates/include-use-node-version.yml@self diff --git a/tools/pipelines/test-perf-benchmarks.yml b/tools/pipelines/test-perf-benchmarks.yml index 69fd3dd256de..4fefc8226acb 100644 --- a/tools/pipelines/test-perf-benchmarks.yml +++ b/tools/pipelines/test-perf-benchmarks.yml @@ -119,10 +119,14 @@ stages: # Checkout the FluidFramework repo (for workspace scripts and source code) - checkout: self path: $(FluidFrameworkDirectory) + fetchDepth: 1 + fetchTags: false # Checkout ff_pipeline_host (provides telemetry-generator and trips-setup/cleanup) - checkout: ff_pipeline_host path: $(FFPipelineHostDirectory) + fetchDepth: 1 + fetchTags: false - task: Bash@3 displayName: Print parameter/variable values for troubleshooting