Skip to content

Commit 92ead03

Browse files
authored
Add license check action (#36)
* Add license check action * Add charset to editorconfig * Update permissions * Add F# file checking * Code cleanup and BOM removal * Fix accidental line duplicate
1 parent 573c2e9 commit 92ead03

File tree

106 files changed

+1367
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1367
-1019
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ trim_trailing_whitespace=true
55
insert_final_newline=true
66

77
[*]
8+
charset = utf-8
89
indent_style = tab
910
indent_size = 4
1011

.github/add-license-headers.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
script_path=$(dirname $(realpath -s $0))/../
3+
4+
function add_license () {
5+
(find "$script_path" -name $1 | grep -v "/bin/" | grep -v "/obj/" )|while read fname; do
6+
line=$(sed -n '2p;3q' "$fname")
7+
if ! [[ "$line" == " * Licensed to Elasticsearch B.V. under one or more contributor" ]] ; then
8+
# awk joins the header with the existing file, inserting a newline between them
9+
awk '(NR>1 && FNR==1){print ""}1' "${script_path}.github/license-header.txt" "$fname" > "${fname}.new"
10+
mv "${fname}.new" "$fname"
11+
fi
12+
done
13+
}
14+
15+
add_license "*.cs"

.github/check-license-headers.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
# Check that source code files in this repo have the appropriate license
4+
# header.
5+
6+
if [ "$TRACE" != "" ]; then
7+
export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
8+
set -o xtrace
9+
fi
10+
set -o errexit
11+
set -o pipefail
12+
13+
TOP=$(cd "$(dirname "$0")/.." >/dev/null && pwd)
14+
NLINES=$(wc -l .github/license-header.txt | awk '{print $1}')
15+
16+
function check_license_header {
17+
local f
18+
f=$1
19+
if ! diff -a --strip-trailing-cr .github/license-header.txt <(head -$NLINES "$f") >/dev/null; then
20+
echo "check-license-headers: error: '$f' does not have required license header, see 'diff -u .github/license-header.txt <(head -$NLINES $f)'"
21+
return 1
22+
else
23+
return 0
24+
fi
25+
}
26+
27+
cd "$TOP"
28+
nErrors=0
29+
for f in $(git ls-files | grep '\.cs$'); do
30+
if ! check_license_header $f; then
31+
nErrors=$((nErrors+1))
32+
fi
33+
done
34+
35+
for f in $(git ls-files | grep '\.fs$'); do
36+
if ! check_license_header $f; then
37+
nErrors=$((nErrors+1))
38+
fi
39+
done
40+
41+
if [[ $nErrors -eq 0 ]]; then
42+
exit 0
43+
else
44+
exit 1
45+
fi

.github/license-header.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information

.github/workflows/license.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: License headers
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Check license headers
14+
run: |
15+
./.github/check-license-headers.sh

build/scripts/CommandLine.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
15
module CommandLine
26

37
open Argu

build/scripts/Paths.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
15
module Paths
26

37
open System

build/scripts/Program.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
module Program
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
module Program
26

37
open Argu
48
open Bullseye

build/scripts/Targets.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
15
module Targets
26

37
open Argu

examples/Elastic.Managed.Example/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to Elasticsearch B.V under one or more agreements.
1+
// Licensed to Elasticsearch B.V under one or more agreements.
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

@@ -14,13 +14,13 @@ public static class Program
1414
public static void Main(string[] args)
1515
{
1616
var version = "6.3.0";
17-
var esHome = Environment.ExpandEnvironmentVariables($@"%LOCALAPPDATA%\ElasticManaged\{version}\elasticsearch-{version}");
17+
var esHome =
18+
Environment.ExpandEnvironmentVariables(
19+
$@"%LOCALAPPDATA%\ElasticManaged\{version}\elasticsearch-{version}");
1820

19-
var clusterConfiguration = new ClusterConfiguration(version, esHome, numberOfNodes: 2);
21+
var clusterConfiguration = new ClusterConfiguration(version, esHome, 2);
2022
using (var cluster = new ElasticsearchCluster(clusterConfiguration))
21-
{
2223
cluster.Start(new ConsoleLineWriter(), TimeSpan.FromMinutes(2));
23-
}
2424

2525
Console.WriteLine("Program ended");
2626
}

0 commit comments

Comments
 (0)