Skip to content

Commit

Permalink
Freeze requirements workflow for release tag (opea-project#485)
Browse files Browse the repository at this point in the history
Signed-off-by: Sun, Xuehao <[email protected]>
Signed-off-by: NeuralChatBot <[email protected]>
Signed-off-by: BaoHuiling <[email protected]>
  • Loading branch information
XuehaoSun authored and BaoHuiling committed Aug 15, 2024
1 parent 91278e0 commit 0574132
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/manual-freeze-requirements.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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
59 changes: 59 additions & 0 deletions .github/workflows/scripts/freeze_requirements.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
*.egg-info/

0 comments on commit 0574132

Please sign in to comment.