diff --git a/.github/workflows/manual-freeze-requirements.yml b/.github/workflows/manual-freeze-requirements.yml new file mode 100644 index 0000000000..ff958bbb28 --- /dev/null +++ b/.github/workflows/manual-freeze-requirements.yml @@ -0,0 +1,38 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +name: Freeze-requirements + +on: + workflow_dispatch: + +jobs: + freeze-requirements: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Set up Git + run: | + git config --global user.name "NeuralChatBot" + git config --global user.email "grp_neural_chat_bot@intel.com" + git remote set-url origin https://NeuralChatBot:"${{ secrets.ACTION_TOKEN }}"@github.com/opea-project/GenAIComps.git + + - name: Run script + run: | + bash .github/workflows/scripts/freeze_requirements.sh + + - name: Commit changes + run: | + git add . + git commit -m "Freeze requirements" + git push diff --git a/.github/workflows/scripts/freeze_requirements.sh b/.github/workflows/scripts/freeze_requirements.sh new file mode 100644 index 0000000000..7c3b1d18ae --- /dev/null +++ b/.github/workflows/scripts/freeze_requirements.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +function freeze() { + local file=$1 + local folder=$(dirname "$file") + local keep_origin_packages="true" + echo "::group::Check $file ..." + pip-compile \ + --no-upgrade \ + --no-annotate \ + --no-header \ + --output-file "$folder/freeze.txt" \ + "$file" + echo "::endgroup::" + if [[ -e "$folder/freeze.txt" ]]; then + if [[ "$keep_origin_packages" == "true" ]]; then + sed -i '/^\s*#/d; s/#.*//; /^\s*$/d' "$file" + sed -i '/^\s*#/d; s/#.*//; /^\s*$/d' "$folder/freeze.txt" + + packages1=$(cut -d'=' -f1 "$file" | tr '[:upper:]' '[:lower:]' | sed 's/[-_]/-/g') + packages2=$(cut -d'=' -f1 "$folder/freeze.txt" | tr '[:upper:]' '[:lower:]' | sed 's/[-_]/-/g') + common_packages=$(comm -12 <(echo "$packages2" | sort) <(echo "$packages1" | sort)) + + rm "$file" + while IFS= read -r line; do + package=$(echo "$line" | cut -d'=' -f1) + package_transformed=$(echo "$package" | tr '[:upper:]' '[:lower:]' | sed 's/[_-]/-/g') + pattern=$(echo "$package_transformed" | sed 's/\[/\\\[/g; s/\]/\\\]/g') + if echo "$common_packages" | grep -q "^$pattern$"; then + echo "$line" >>"$file" + fi + done <"$folder/freeze.txt" + rm "$folder/freeze.txt" + else + mv "$folder/freeze.txt" "$file" + fi + fi +} + +function check_branch_name() { + if [[ "$GITHUB_REF_NAME" == "main" ]]; then + echo "$GITHUB_REF_NAME is protected branch" + exit 0 + else + echo "branch name is $GITHUB_REF_NAME" + fi +} + +function main() { + check_branch_name + echo "::group::pip install pip-tools" && pip install pip-tools --upgrade && echo "::endgroup::" + export -f freeze + find . -name "requirements.txt" | xargs -n 1 -I {} bash -c 'freeze "$@"' _ {} +} + +main diff --git a/.gitignore b/.gitignore index bee8a64b79..567994ceb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +*.egg-info/