From f86396efcdcafa0220c2fb717ca15748471336c9 Mon Sep 17 00:00:00 2001 From: Emmanuel Barat Date: Mon, 30 Oct 2023 16:36:19 +0100 Subject: [PATCH] feat: add ci (#3) --- .github/workflows/linter.yml | 57 +++++++++++++++++++++++++++++++++++ README.md | 4 +-- template-sync.sh | 58 +++++++++++++----------------------- 3 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..87fbb8f --- /dev/null +++ b/.github/workflows/linter.yml @@ -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 }} + \ No newline at end of file diff --git a/README.md b/README.md index 2eaaadc..44075d4 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 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! @@ -10,7 +10,7 @@ Therefore you just have to resolve conflicts and work is done! 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 diff --git a/template-sync.sh b/template-sync.sh index 32e7d79..d8a41c7 100755 --- a/template-sync.sh +++ b/template-sync.sh @@ -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 {} + @@ -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 @@ -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)