Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof FromTagCommand.run>>;
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<string, Date> = {
[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);
}
Comment on lines +75 to +83
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended and documented.


expect(JSON.stringify(output)).to.equal(JSON.stringify(expected));
});
const output: jsonOutput = JSON.parse(stdout) as jsonOutput;
expect(output).to.deep.equal(expected);
});
}
});
10 changes: 10 additions & 0 deletions tools/pipelines/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/build-performance-observability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tools/pipelines/deploy-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions tools/pipelines/publish-api-model-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -257,6 +259,8 @@ stages:
- checkout: self
submodules: false
clean: true
fetchDepth: 1
fetchTags: false
- task: TriggerBuild@4
condition: eq(variables['shouldDeploy'], 'true')
inputs:
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/repo-policy-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/templates/build-docker-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ extends:
clean: true
lfs: false
submodules: false
fetchDepth: 1
fetchTags: false

- task: Bash@3
displayName: Parameters
Expand Down
6 changes: 6 additions & 0 deletions tools/pipelines/templates/build-npm-client-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ extends:
clean: true
lfs: '${{ parameters.checkoutSubmodules }}'
submodules: '${{ parameters.checkoutSubmodules }}'
fetchDepth: 1
fetchTags: false

- script: |
echo "commit sha: $(Build.SourceVersion)"
Expand Down Expand Up @@ -589,6 +591,8 @@ extends:
clean: true
lfs: '${{ parameters.checkoutSubmodules }}'
submodules: '${{ parameters.checkoutSubmodules }}'
fetchDepth: 1
fetchTags: false

- script: |
echo "commit: $(COMMIT_SHA)"
Expand Down Expand Up @@ -753,6 +757,8 @@ extends:
clean: true
lfs: '${{ parameters.checkoutSubmodules }}'
submodules: '${{ parameters.checkoutSubmodules }}'
fetchDepth: 1
fetchTags: false

- script: |
echo "commit: $(COMMIT_SHA)"
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/templates/build-npm-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ extends:
clean: true
lfs: '${{ parameters.checkoutSubmodules }}'
submodules: '${{ parameters.checkoutSubmodules }}'
fetchDepth: 1
fetchTags: false

- task: Bash@3
displayName: Parameters
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/templates/include-policy-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ jobs:
steps:
- checkout: self
clean: true
fetchDepth: 1
fetchTags: false
Comment on lines +164 to +165
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one would be my main concern, together with the corresponding one in include-publish-docker-service-steps.yml‎. As I mentioned in Teams, I think flub does need the tags to be available at some point during the release/publish process, but I can't recall where exactly. @tylerbutler might remember.

- template: /tools/pipelines/templates/include-git-tag-steps.yml@self
parameters:
tagName: ${{ parameters.tagName }}
4 changes: 4 additions & 0 deletions tools/pipelines/templates/include-test-real-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -185,6 +187,8 @@ stages:
- checkout: self
path: $(FluidFrameworkDirectory)
clean: true
fetchDepth: 1
fetchTags: false

- bash: |
git fetch --depth=1 origin $FF_SOURCE_VERSION
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/templates/upload-dev-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tools/pipelines/templates/upload-server-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions tools/pipelines/test-perf-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading