superlint/.github/scripts/update-python.sh

81 lines
2.5 KiB
Bash
Raw Normal View History

2022-02-22 10:20:50 -05:00
#!/usr/bin/env bash
################################################################################
########################### Install Python Dependancies ########################
################################################################################
#####################
# Set fail on error #
#####################
set -euo pipefail
############################
# Create staging directory #
############################
2022-02-22 10:24:08 -05:00
# shellcheck disable=SC2154
mkdir -p "${working_directory}/venvs"
2022-02-22 10:20:50 -05:00
########################################
# Install basic libs to run installers #
########################################
pip install virtualenv
#########################################################
# Itterate through requirments.txt to install bainaries #
#########################################################
cd dependencies/python
for DEP_FILE in *.txt; do
# split the package name from its version
PACKAGE_NAME=${DEP_FILE%.txt}
echo "-------------------------------------------"
2022-02-22 10:24:08 -05:00
mkdir -p "${working_directory}/venvs/${PACKAGE_NAME}"
2022-02-22 10:20:50 -05:00
echo "Generating virtualenv for: [${PACKAGE_NAME}]"
2022-02-22 10:24:08 -05:00
pushd "${working_directory}/venvs/${PACKAGE_NAME}"
2022-02-22 10:20:50 -05:00
# Enable virtualenv
virtualenv .
# Activate virtualenv
2022-02-22 11:47:16 -05:00
# shellcheck disable=SC1091
2022-02-22 10:20:50 -05:00
source bin/activate
# Handle the ansibl-lint corner case
2022-02-22 10:34:46 -05:00
if [[ $PACKAGE_NAME == "ansible-lint" ]]; then
2022-02-22 10:20:50 -05:00
pip install "ansible-lint[core]"
else
pip install "${PACKAGE_NAME}"
fi
# Generate an update requirements.txt
2022-02-22 10:34:46 -05:00
pip freeze >requirements.txt
2022-02-22 10:20:50 -05:00
# deactivate the python virtualenv
deactivate
# pop the stack
popd
# Remove old lockfile
rm -rf "$DEP_FILE"
# Create new lockfile
2022-02-22 10:24:08 -05:00
mv "${working_directory}/venvs/${PACKAGE_NAME}/requirements.txt" "${DEP_FILE}"
2022-02-22 10:20:50 -05:00
done
git status
# Setup Git Config
echo "Configuring Git..."
git config --global user.email "noreply@github.com"
git config --global user.name "Super-Linter Automation"
if [[ $(git status --porcelain) ]]; then
# Push changes to remote
echo "Pushing changes to remote..."
git add .
2022-02-22 10:26:50 -05:00
git commit -a -m "Update Python dependencies"
2022-02-22 10:20:50 -05:00
# shellcheck disable=SC2154
git checkout -b "python_deps_${id}"
# shellcheck disable=SC2154
git push origin "python_deps_${id}"
# Open pull request
echo "Opening pull request..."
2022-02-22 10:34:16 -05:00
# shellcheck disable=SC2154
2022-02-22 10:33:03 -05:00
echo "${token}" | gh auth login --with-token
2022-02-22 10:36:08 -05:00
gh pr create --title "Weekly Python Updates" --body "Updates Python dependencies" --base main --head "python_deps_${id}"
2022-02-22 10:20:50 -05:00
else
echo "No changes to commit"
fi