Skip to content

Commit

Permalink
feat: add ci (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mano-lis authored Oct 30, 2023
1 parent 6039d8c commit f86396e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 39 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#################################
#################################
## Super Linter GitHub Actions ##
#################################
#################################
name: Lint Code Base

#############################
# Start the job on all push #
#############################
on:
push:
branches-ignore: [master, main]
# Remove the line above to run when pushing to master or main
pull_request:
branches: [master, main]

###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

############################################
# Grant status permission for MULTI_STATUS #
############################################
permissions:
contents: read
packages: read
statuses: write

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper
# list of changed files within `super-linter`
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: super-linter/super-linter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
A script to easily update a template based project

## Presentation
This script identifies a commit in the template history which is the closest one to your project.
This script identifies a commit in the template history which is the closest one to your project.
Then it squashes all the updates into a commit which will be cherry-picked on the top of your working branch.
Therefore you just have to resolve conflicts and work is done!

## Basic Usage
1. Go to your project repository (we recommend to create a new branch)
Copy template-sync.sh at the root of your project

2. The only mandatory argument is the github or gitlab url of your template.
2. The only mandatory argument is the GitHub or gitlab URL of your template.
E.g. `./template-sync.sh https://github.com/dunglas/symfony-docker`

3. In case some files are renamed or moved in the template history, you can modify the threshold where
Expand Down
58 changes: 21 additions & 37 deletions template-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,8 @@ git_template_sync() {
fi
}

git_template_sync clone "$url" template/

git_template_sync clone "$project_dir" project/

cd template/ || return

if [ -n "$commit" ]; then
git_template_sync reset --hard "$commit"
fi

api_shas=$(git log --pretty=format:"%H")

index=0
for sha in $api_shas;
do
git_template_sync checkout "$sha"
estimate_similarity_index() {
git_template_sync checkout "$sha"
cp -r . ../template_modified
find ../template_modified -type f -name "*.lock" -exec rm -f {} +
find ../template_modified -type f -name "*-lock*" -exec rm -f {} +
Expand All @@ -86,6 +72,24 @@ do

ratio=$(echo "scale=4; $common_files / $total_template_modified_files" | bc)
ratio_percent=$(printf "%.0f" "$(echo "$ratio * 100" | bc)")
}

git_template_sync clone "$url" template/

git_template_sync clone "$project_dir" project/

cd template/ || return

if [ -n "$commit" ]; then
git_template_sync reset --hard "$commit"
fi

api_shas=$(git log --pretty=format:"%H")

index=0
for sha in $api_shas;
do
estimate_similarity_index

if [ "$index" -eq 0 ]; then
ratioMax=$ratio_percent
Expand All @@ -107,27 +111,7 @@ rm -rf ../template_modified/*
index=0
for sha in $api_shas;
do
git_template_sync checkout "$sha"
cp -r . ../template_modified
find ../template_modified -type f -name "*.lock" -exec rm -f {} +
find ../template_modified -type f -name "*-lock*" -exec rm -f {} +
find ../template_modified -type d -name ".git" -exec rm -rf {} +
find ../template_modified -type f -name "*.json" -exec rm -f {} +
find ../template_modified -type f -name "*README*" -exec rm -f {} +
total_template_modified_files=$(find ../template_modified -type f | wc -l )
cd ..
tmpfile1=$(mktemp)
tmpfile2=$(mktemp)

(find template_modified/ -type f | sort | sed 's|template_modified/||') > "$tmpfile1"

(find project/ -type f | sort | sed 's|project/||') > "$tmpfile2"

common_files=$(comm -12 "$tmpfile1" "$tmpfile2" | wc -l)
rm "$tmpfile1" "$tmpfile2"

ratio=$(echo "scale=4; $common_files / $total_template_modified_files" | bc)
ratio_percent=$(printf "%.0f" "$(echo "$ratio * 100" | bc)")
estimate_similarity_index

if [ "$ratio_percent" -gt "$ratioThreshold" ] || [ "$ratio_percent" -eq "$ratioThreshold" ]; then
diff=$(git diff --shortstat --no-index --diff-filter=d -- project template_modified)
Expand Down

0 comments on commit f86396e

Please sign in to comment.