Skip to content

Commit

Permalink
chore(ci): fix and update file_license_check and workflow (#192)
Browse files Browse the repository at this point in the history
Description
Fix and update file_license_check and workflow

Motivation and Context
Better CI workflow

How Has This Been Tested?
Runs at expected in local fork
  • Loading branch information
leet4tari authored Dec 2, 2024
1 parent 3857925 commit 76eb2db
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name: CI

'on':
push:
branches:
- "ci-*"
workflow_dispatch:
pull_request:
types:
Expand Down Expand Up @@ -151,19 +154,22 @@ jobs:
run: rustup show
- name: cargo check
run: cargo check --release --all-targets --workspace --exclude tari_integration_tests --locked

licenses:
name: file licenses
runs-on: [ ubuntu-20.04 ]
runs-on: [ ubuntu-22.04 ]
steps:
- name: checkout
uses: actions/checkout@v4
- name: install ripgrep
run: |
wget https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb
sudo dpkg -i ripgrep_13.0.0_amd64.deb
#wget https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep_14.1.1-1_amd64.deb.sha256
wget https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep_14.1.1-1_amd64.deb
sudo dpkg -i ripgrep_14.1.1-1_amd64.deb
rg --version || exit 1
- name: run the license check
run: ./scripts/file_license_check.sh

test:
name: test
runs-on: [ self-hosted, ubuntu-high-cpu ]
Expand Down
56 changes: 49 additions & 7 deletions scripts/file_license_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,80 @@
# Must be run from the repo root
#

#set -xo pipefail
set -e

check_for() {
if prog_location=$(which ${1}) ; then
if result=$(${1} --version 2>/dev/null); then
result="${1}: ${result} INSTALLED ✓"
else
result="${1}: INSTALLED ✓"
fi
else
result="${1}: MISSING ⨯"
fi
}

check_requirements() {
echo "List of requirements and possible test:"
req_progs=(
mktemp
rg
diff
)
for RProg in "${req_progs[@]}"; do
check_for ${RProg}
echo "${result}"
if [[ "${result}" == "${RProg}: MISSING ⨯" ]]; then
echo "!! Install ${RProg} and try again !!"
exit -1
fi
done

if [ ! -f .license.ignore ]; then
echo "!! No .license.ignore file !!"
exit -1
fi
}

check_requirements

diffparms=${diffparms:-"-u --suppress-blank-empty --strip-trailing-cr --color=never"}
rgTemp=${rgTemp:-$(mktemp)}

# rg -i "Copyright.*The Tari Project" --files-without-match \
# -g '!*.{Dockerfile,asc,bat,config,config.js,css,csv,drawio,env,gitkeep,hbs,html,ini,iss,json,lock,md,min.js,ps1,py,rc,scss,sh,sql,svg,toml,txt,yml,vue}' . \
# | sort > /tmp/rgtemp

# Exclude files without extensions as well as those with extensions that are not in the list
#
rgTemp=$(mktemp)
rg -i "Copyright.*The Tari Project" --files-without-match \
-g '!*.{Dockerfile,asc,bat,config,config.js,css,csv,drawio,env,gitkeep,hbs,html,ini,iss,json,lock,md,min.js,ps1,py,rc,scss,sh,sql,svg,toml,txt,yml,vue}' . \
-g '!*.{Dockerfile,asc,bat,config,config.js,css,csv,drawio,env,gitkeep,hbs,html,ini,iss,json,lock,md,min.js,ps1,py,rc,scss,sh,sql,svg,toml,txt,yml,vue,liquid,otf,d.ts,mjs}' . \
| while IFS= read -r file; do
if [[ -n $(basename "$file" | grep -E '\.') ]]; then
echo "$file"
fi
done | sort > ${rgTemp}

# Sort the .license.ignore file as sorting seems to behave differently on different platforms
licenseIgnoreTemp=$(mktemp)
licenseIgnoreTemp=${licenseIgnoreTemp:-$(mktemp)}
cat .license.ignore | sort > ${licenseIgnoreTemp}

DIFFS=$(diff -u --strip-trailing-cr ${licenseIgnoreTemp} ${rgTemp})
DIFFS=$( diff ${diffparms} ${licenseIgnoreTemp} ${rgTemp} || true )

# clean up
rm -vf ${rgTemp}
rm -vf ${licenseIgnoreTemp}

if [ -n "$DIFFS" ]; then
echo "New files detected that either need copyright/license identifiers added, or they need to be added to .license.ignore"
if [ -n "${DIFFS}" ]; then
echo "New files detected that either need copyright/license identifiers added, "
echo "or they need to be added to .license.ignore"
echo "NB: The ignore file must be sorted alphabetically!"

echo "Diff:"
echo "$DIFFS"
echo "${DIFFS}"
exit 1
else
exit 0
fi
3 changes: 3 additions & 0 deletions src/server/http/stats_collector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use std::time::Duration;

use human_format::Formatter;
Expand Down

0 comments on commit 76eb2db

Please sign in to comment.