Skip to content
157 changes: 19 additions & 138 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -113,54 +22,26 @@ 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: Install dotnet sdk
run: sudo apt install -y dotnet6
- 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
- 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
echo ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} \
- name: Git branches
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
git branch
- name: Git remotes
run: |
dotnet new tool-manifest
dotnet tool install fantomless-tool --version 4.7.997-prerelease
dotnet fantomless --recurse .
git diff --exit-code

git remote -v
- name: fetch
run: |
git fetch origin
- name: Git branches
run: |
git branch
- name: Git log
run: |
git log
- name: Check if gitPush1by1 was used
run: dotnet fsi scripts/detectNotUsingGitPush1by1.fsx
69 changes: 69 additions & 0 deletions scripts/detectNotUsingGitPush1by1.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/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
.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 %s~..%s" currentBranch 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 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"
(Environment.GetEnvironmentVariable("GITHUB_REPOSITORY"))
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.\nYou may use the scripts/gitPush1by1.fsx script."