From 4f2d48ce3ddd59e5b48e389d40e2303d9e3206c7 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Thu, 9 Mar 2023 17:55:06 +0800 Subject: [PATCH] FileConventions: add failing test For inconsistent versions in GitHubCI yml files. --- .../DummyCIWithSamePulumiVersion.yml | 25 +++++++++++++++ .../DummyCIWithoutSamePulumiVersion.yml | 25 +++++++++++++++ .../FileConventions.Test.fs | 31 +++++++++++++++++++ .../FileConventions.Test.fsproj | 2 ++ src/FileConventions/Library.fs | 4 +++ 5 files changed, 87 insertions(+) create mode 100644 src/FileConventions.Test/DummyFiles/DummyCIWithSamePulumiVersion.yml create mode 100644 src/FileConventions.Test/DummyFiles/DummyCIWithoutSamePulumiVersion.yml diff --git a/src/FileConventions.Test/DummyFiles/DummyCIWithSamePulumiVersion.yml b/src/FileConventions.Test/DummyFiles/DummyCIWithSamePulumiVersion.yml new file mode 100644 index 000000000..79920232b --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyCIWithSamePulumiVersion.yml @@ -0,0 +1,25 @@ +name: CI + +on: [push, pull_request] + +jobs: + jobA: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Setup Pulumi CLI + uses: pulumi/setup-pulumi@v2.0.0 + with: + pulumi-version: 3.40.0 + - name: Print "Hello World!" + run: echo "Hello World!" + jobB: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Setup Pulumi CLI + uses: pulumi/setup-pulumi@v2.0.0 + with: + pulumi-version: 3.40.0 + - name: Print "Hello World!" + run: echo "Hello World!" diff --git a/src/FileConventions.Test/DummyFiles/DummyCIWithoutSamePulumiVersion.yml b/src/FileConventions.Test/DummyFiles/DummyCIWithoutSamePulumiVersion.yml new file mode 100644 index 000000000..071d93e2a --- /dev/null +++ b/src/FileConventions.Test/DummyFiles/DummyCIWithoutSamePulumiVersion.yml @@ -0,0 +1,25 @@ +name: CI + +on: [push, pull_request] + +jobs: + jobA: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Setup Pulumi CLI + uses: pulumi/setup-pulumi@v2.0.0 + with: + pulumi-version: 3.40.0 + - name: Print "Hello World!" + run: echo "Hello World!" + jobB: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: Setup Pulumi CLI + uses: pulumi/setup-pulumi@v2.0.0 + with: + pulumi-version: 3.41.0 + - name: Print "Hello World!" + run: echo "Hello World!" diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 96cb03969..2ff0c66c5 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -348,3 +348,34 @@ let WrapTextTest4() = + "characters." Assert.That(WrapText text characterCount, Is.EqualTo expectedResult) +[] + +let DetectInconsistentVersionsInGitHubCIWorkflow1() = + let fileInfo = + (FileInfo( + Path.Combine( + dummyFilesDirectory.FullName, + "DummyCIWithSamePulumiVersion.yml" + ) + )) + + Assert.That( + DetectInconsistentVersionsInGitHubCIWorkflow fileInfo, + Is.EqualTo false + ) + + +[] +let DetectInconsistentVersionsInGitHubCIWorkflow2() = + let fileInfo = + (FileInfo( + Path.Combine( + dummyFilesDirectory.FullName, + "DummyCIWithoutSamePulumiVersion.yml" + ) + )) + + Assert.That( + DetectInconsistentVersionsInGitHubCIWorkflow fileInfo, + Is.EqualTo true + ) diff --git a/src/FileConventions.Test/FileConventions.Test.fsproj b/src/FileConventions.Test/FileConventions.Test.fsproj index 530e2adfa..1be1b3f28 100644 --- a/src/FileConventions.Test/FileConventions.Test.fsproj +++ b/src/FileConventions.Test/FileConventions.Test.fsproj @@ -40,5 +40,7 @@ + + diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 899c9bc75..5ba7ceb9b 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -245,3 +245,7 @@ let WrapText (text: string) (maxCharsPerLine: int) : string = $"{Environment.NewLine}{Environment.NewLine}", wrappedParagraphs ) + +let DetectInconsistentVersionsInGitHubCIWorkflow(fileInfo: FileInfo) = + assert (fileInfo.FullName.EndsWith ".yml") + false