From 61fc983602230a74c035ce829bdc861cae6343d0 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 12:46:08 +0330 Subject: [PATCH 01/14] scripts/detectNotUsingGitPush1by1: add --- scripts/detectNotUsingGitPush1by1.fsx | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/detectNotUsingGitPush1by1.fsx diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx new file mode 100644 index 000000000..77fdc2bf2 --- /dev/null +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -0,0 +1,58 @@ +#!/usr/bin/env -S dotnet fsi + +open System.Net.Http +open System.Net.Http.Headers + +let currentBranch = + Fsdk + .Process + .Execute( + { + Command = "git" + Arguments = "rev-parse --abbrev-ref HEAD" + }, + Fsdk.Process.Echo.All + ) + .UnwrapDefault() + .Trim() + +let prCommits = + Fsdk + .Process + .Execute( + { + Command = "git" + Arguments = sprintf "rev-list master..%s" currentBranch + }, + Fsdk.Process.Echo.All + ) + .UnwrapDefault() + .Trim() + .Split "\n" + +let notUsingGitPush1by1 = + prCommits + |> Seq.map(fun commit -> + let client: HttpClient = new HttpClient() + client.DefaultRequestHeaders.Accept.Clear() + + client.DefaultRequestHeaders.Accept.Add( + new MediaTypeWithQualityHeaderValue("application/vnd.github+json") + ) + + client.DefaultRequestHeaders.Add("User-Agent", ".NET App") + client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28") + + let url = + sprintf + "https://api.github.com/repos/realmarv/conventions/commits/%s/check-suites" + commit + + let json = client.GetStringAsync(url).Result + + json.Contains "\"check_suites\":[]" + ) + |> Seq.contains true + +if notUsingGitPush1by1 then + failwith "Please push the commits one by one." From 7b1014ff7c6c7d265768ccc2578464cfb7f6b17f Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 13:01:47 +0330 Subject: [PATCH 02/14] scripts/detectNotUsingGitPush1by1: fix --- scripts/detectNotUsingGitPush1by1.fsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index 77fdc2bf2..ba8369310 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -1,8 +1,11 @@ #!/usr/bin/env -S dotnet fsi +open System open System.Net.Http open System.Net.Http.Headers +#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" + let currentBranch = Fsdk .Process @@ -45,8 +48,9 @@ let notUsingGitPush1by1 = let url = sprintf - "https://api.github.com/repos/realmarv/conventions/commits/%s/check-suites" + "https://api.github.com/repos/%s/commits/%s/check-suites" commit + (Environment.GetEnvironmentVariable("GITHUB_REPOSITORY")) let json = client.GetStringAsync(url).Result From ae0c062ca376a49906a491b1f7cd8174a727561c Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 13:10:13 +0330 Subject: [PATCH 03/14] scripts/detectNotUsingGitPush1by1: fix message --- scripts/detectNotUsingGitPush1by1.fsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index ba8369310..0ecbffdd7 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -59,4 +59,4 @@ let notUsingGitPush1by1 = |> Seq.contains true if notUsingGitPush1by1 then - failwith "Please push the commits one by one." + failwith "Please push the commits one by one.\nYou may use the scripts/gitPush1by1.fsx script." From f7510febb056aa6e3f8fe068d3da6576ad34d6de Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 13:19:36 +0330 Subject: [PATCH 04/14] scripts/detectNotUsingGitPush1by1: fix --- scripts/detectNotUsingGitPush1by1.fsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index 0ecbffdd7..03ddc9104 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -46,11 +46,18 @@ let notUsingGitPush1by1 = client.DefaultRequestHeaders.Add("User-Agent", ".NET App") client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28") + let command = sprintf + "https://api.github.com/repos/%s/commits/%s/check-suites" + (Environment.GetEnvironmentVariable("GITHUB_REPOSITORY")) + commit + + printfn "Command: %A" command + let url = sprintf "https://api.github.com/repos/%s/commits/%s/check-suites" - commit (Environment.GetEnvironmentVariable("GITHUB_REPOSITORY")) + commit let json = client.GetStringAsync(url).Result From 47d57e63cee5f2a70dc734958b778b6b4d14e5bb Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 13:20:06 +0330 Subject: [PATCH 05/14] GitHubCI: run detectNotUsingGitPush1by1.fsx --- .github/workflows/CI.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7cc835d7d..547552516 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -141,6 +141,8 @@ jobs: run: dotnet fsi scripts/unpinnedDotnetPackageVersions.fsx - name: Check there are no unpinned nuget package reference versions in F# scripts run: dotnet fsi scripts/unpinnedNugetPackageReferenceVersions.fsx + - name: Check if gitPush1by1 was used + run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx - name: Install prettier run: npm install prettier@2.8.3 - name: Change file permissions From 8345a31ee21785f9d76ce59bc023838c7ddb00ab Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 13:53:56 +0330 Subject: [PATCH 06/14] WIP1 --- .github/workflows/CI.yml | 142 +-------------------------------------- 1 file changed, 2 insertions(+), 140 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 547552516..7788aab76 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,99 +3,8 @@ name: CI on: [push, pull_request] jobs: - build: - name: Build - runs-on: ubuntu-22.04 - container: - image: "ubuntu:22.04" - steps: - - uses: actions/checkout@v2 - - name: Install required dependencies - run: | - apt update - apt install -y sudo - sudo apt install -y git - # workaround for https://github.com/actions/runner/issues/2033 - - name: ownership workaround - run: git config --global --add safe.directory '*' - - name: Install dotnet sdk - run: sudo apt install -y dotnet6 - - name: Compile the conventions solution - run: dotnet build --configuration Release conventions.sln - - name: Compile F# scripts - run: dotnet fsi scripts/compileFSharpScripts.fsx - - file-conventions-tests: - name: Run FileConventions-lib unit tests - needs: build - runs-on: ubuntu-22.04 - container: - image: "ubuntu:22.04" - steps: - - uses: actions/checkout@v2 - - name: Install required dependencies - run: | - apt update - apt install --yes sudo - - # We need to install curl otherwise we get these errors in the CI: - # Unable to load the service index for source https://api.nuget.org/v3/index.json. - # The SSL connection could not be established, see inner exception. - # The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot - sudo apt install --yes curl - - - name: Setup .NET - run: apt install -y dotnet6 - - name: Run tests to validate F# scripts - run: dotnet test src/FileConventions.Test/FileConventions.Test.fsproj - - commitlint-plugins-tests: - name: Run commitlint-related tests - needs: build - runs-on: ubuntu-22.04 - container: - image: "ubuntu:22.04" - steps: - - uses: actions/checkout@v2 - - name: Install required dependencies - run: | - apt update - apt install --yes sudo - sudo apt install --yes git - - sudo apt install --yes curl - # can't install ubuntu's default nodejs version because we would get this error: - # error @jest/core@29.4.1: The engine "node" is incompatible with this module. Expected version "^14.15.0 || ^16.10.0 || >=18.0.0". Got "12.22.9" - curl --show-error --location https://deb.nodesource.com/setup_14.x | sudo --preserve-env bash - - sudo DEBIAN_FRONTEND=noninteractive apt install --yes nodejs - - name: Print versions - run: | - git --version - node --version - npm --version - npx commitlint --version - - name: Install yarn - run: | - npm install --global yarn - yarn add --dev jest typescript ts-jest @types/jest - - name: Install commitlint - run: | - npm install conventional-changelog-conventionalcommits - npm install commitlint@latest - - name: Print versions - run: | - git --version - node --version - npm --version - npx commitlint --version - - name: Run tests to validate our plugins - run: yarn jest - sanity-check: name: Sanity check - needs: - - file-conventions-tests - - commitlint-plugins-tests runs-on: ubuntu-22.04 container: image: "ubuntu:22.04" @@ -113,56 +22,9 @@ jobs: # workaround for https://github.com/actions/runner/issues/2033 - name: ownership workaround run: git config --global --add safe.directory '*' - - name: Print versions - run: | - git --version - node --version - npm --version - - name: Validate current commit (last commit) with commitlint - if: github.event_name == 'push' - run: ./commitlint.sh --from HEAD~1 --to HEAD --verbose - - name: Validate PR commits with commitlint + - name: Print if: github.event_name == 'pull_request' run: | - ./commitlint.sh --verbose \ - --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} \ - --to ${{ github.event.pull_request.head.sha }} - - name: Install dotnet sdk - run: sudo apt install --yes dotnet6 - - name: Check all files end with EOL - run: dotnet fsi scripts/eofConvention.fsx - - name: Check all .fsx scripts have shebang - run: dotnet fsi scripts/shebangConvention.fsx - - name: Check there are no mixed line-endings in any files - run: dotnet fsi scripts/mixedLineEndings.fsx - - name: Check there are no unpinned GitHubActions image versions - run: dotnet fsi scripts/unpinnedGitHubActionsImageVersions.fsx - - name: Check there are no unpinned dotnet package versions - run: dotnet fsi scripts/unpinnedDotnetPackageVersions.fsx - - name: Check there are no unpinned nuget package reference versions in F# scripts - run: dotnet fsi scripts/unpinnedNugetPackageReferenceVersions.fsx + echo ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} \ - name: Check if gitPush1by1 was used run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx - - name: Install prettier - run: npm install prettier@2.8.3 - - name: Change file permissions - # We need this step so we can change the files using `npx prettier --write` in the next step. - # Otherwise we get permission denied error in the CI. - run: sudo chmod 777 -R . - - name: Run "prettier" to check the style of our TypeScript code - run: | - sudo npx prettier --quote-props=consistent --write './**/*.ts' - # Since we changed file modes in the previous step we need the following command to - # make git ignore mode changes in files and doesn't include them in the git diff command. - git config core.fileMode false - # Since after installing commitlint dependencies package.json file changes, we need to - # run the following command to ignore package.json file - git restore package.json - git diff --exit-code - - name: fantomless - run: | - dotnet new tool-manifest - dotnet tool install fantomless-tool --version 4.7.997-prerelease - dotnet fantomless --recurse . - git diff --exit-code - From af905763d6ee3b97666a7a4dcf7813f6f73ff856 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 14:06:29 +0330 Subject: [PATCH 07/14] WIP2 --- .github/workflows/CI.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7788aab76..36345a0e0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -26,5 +26,8 @@ jobs: if: github.event_name == 'pull_request' run: | echo ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} \ + - name: Git branches + run: | + git branch - name: Check if gitPush1by1 was used run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx From b873f1b83b853efd60520ae19bb65411a6db1e08 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 14:12:10 +0330 Subject: [PATCH 08/14] WIP3 --- .github/workflows/CI.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 36345a0e0..71dcf42d8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,5 +29,8 @@ jobs: - name: Git branches run: | git branch + - name: Git remotes + run: | + git remote -v - name: Check if gitPush1by1 was used run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx From 42b3767600a94d0520a8bcc55fbaac16bd72ed43 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 14:14:54 +0330 Subject: [PATCH 09/14] WIP4 --- .github/workflows/CI.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 71dcf42d8..06ad609fd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -32,5 +32,11 @@ jobs: - name: Git remotes run: | git remote -v + - name: fetch + run: | + git fetch origin + - name: Git branches + run: | + git branch - name: Check if gitPush1by1 was used run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx From ae30322cf1a060728e1749f8140c489673adb475 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 14:32:40 +0330 Subject: [PATCH 10/14] WIP5 --- .github/workflows/CI.yml | 2 ++ scripts/detectNotUsingGitPush1by1.fsx | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 06ad609fd..a417cc0fa 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -22,6 +22,8 @@ jobs: # workaround for https://github.com/actions/runner/issues/2033 - name: ownership workaround run: git config --global --add safe.directory '*' + - name: Install dotnet sdk + run: sudo apt install -y dotnet6 - name: Print if: github.event_name == 'pull_request' run: | diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index 03ddc9104..170caf638 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -19,13 +19,16 @@ let currentBranch = .UnwrapDefault() .Trim() +let numPrCommits = Environment.GetEnvironmentVariable("github.event.pull_request.commits") +printfn "numPrCommits: %A" numPrCommits + let prCommits = Fsdk .Process .Execute( { Command = "git" - Arguments = sprintf "rev-list master..%s" currentBranch + Arguments = sprintf "rev-list %s~%s..%s" currentBranch numPrCommits currentBranch }, Fsdk.Process.Echo.All ) From deac038e794ffc6326241fdb747a4197267a5cd6 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 15:29:05 +0330 Subject: [PATCH 11/14] WIP6 --- scripts/detectNotUsingGitPush1by1.fsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index 170caf638..72bd21aa0 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -36,6 +36,8 @@ let prCommits = .Trim() .Split "\n" +printfn "prCommits: %A" prCommits + let notUsingGitPush1by1 = prCommits |> Seq.map(fun commit -> From e5c9bad511bcbdf0a20725783f064b4cbd66bf0b Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 15:33:48 +0330 Subject: [PATCH 12/14] WIP7 --- .github/workflows/CI.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a417cc0fa..ff8bb8c38 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,5 +40,8 @@ jobs: - name: Git branches run: | git branch + - name: Git log + run: | + git log - name: Check if gitPush1by1 was used run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx From 57a21ca1228caf2c866d89f70589d6d371e09d1d Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 15:38:56 +0330 Subject: [PATCH 13/14] WIP8 --- scripts/detectNotUsingGitPush1by1.fsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index 72bd21aa0..e027b99be 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -21,6 +21,7 @@ let currentBranch = let numPrCommits = Environment.GetEnvironmentVariable("github.event.pull_request.commits") printfn "numPrCommits: %A" numPrCommits +printfn "currentBranch: %A" currentBranch let prCommits = Fsdk @@ -28,7 +29,7 @@ let prCommits = .Execute( { Command = "git" - Arguments = sprintf "rev-list %s~%s..%s" currentBranch numPrCommits currentBranch + Arguments = sprintf "rev-list %s~..%s" currentBranch currentBranch }, Fsdk.Process.Echo.All ) From 3314b0e1bd7db1bc5158dfc567b5fc3e235c6a75 Mon Sep 17 00:00:00 2001 From: realmarv Date: Tue, 14 Mar 2023 15:48:34 +0330 Subject: [PATCH 14/14] WIP9 --- scripts/detectNotUsingGitPush1by1.fsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/detectNotUsingGitPush1by1.fsx b/scripts/detectNotUsingGitPush1by1.fsx index e027b99be..6923396df 100644 --- a/scripts/detectNotUsingGitPush1by1.fsx +++ b/scripts/detectNotUsingGitPush1by1.fsx @@ -19,10 +19,6 @@ let currentBranch = .UnwrapDefault() .Trim() -let numPrCommits = Environment.GetEnvironmentVariable("github.event.pull_request.commits") -printfn "numPrCommits: %A" numPrCommits -printfn "currentBranch: %A" currentBranch - let prCommits = Fsdk .Process @@ -37,8 +33,6 @@ let prCommits = .Trim() .Split "\n" -printfn "prCommits: %A" prCommits - let notUsingGitPush1by1 = prCommits |> Seq.map(fun commit ->