-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from yasirroni/git_auto_updater
Git auto updater
- Loading branch information
Showing
13 changed files
with
163 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
PYTHON_VERSIONS=("3.7" "3.8" "3.9" "3.10" "3.11" "3.12") | ||
UPDATED_FILES=() | ||
DATE=$(date -u +'%Y-%m-%d') | ||
|
||
# Function to install Python if not already installed | ||
install_python() { | ||
local version="$1" | ||
|
||
if ! command -v python${version} &> /dev/null; then | ||
echo "Python ${version} not found. Installing..." | ||
sudo apt update | ||
sudo apt install software-properties-common | ||
sudo add-apt-repository ppa:deadsnakes/ppa | ||
sudo apt-get update | ||
sudo apt-get install -y python${version} python${version}-venv | ||
else | ||
echo "Python ${version} is already installed." | ||
fi | ||
} | ||
|
||
for version in "${PYTHON_VERSIONS[@]}"; do | ||
echo "Processing Python $version" | ||
|
||
# Install Python if not already installed | ||
install_python "$version" | ||
|
||
# Create virtual environment specific to the current Python version | ||
python${version} -m venv "env_${version}" | ||
source "env_${version}/bin/activate" | ||
|
||
# Install pip using get-pip.py if it's not already installed | ||
if ! command -v pip &> /dev/null; then | ||
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | ||
python get-pip.py | ||
rm get-pip.py | ||
fi | ||
|
||
# Ensure pip is up-to-date within the virtual environment | ||
pip install --upgrade pip | ||
|
||
# Install pru into the virtual environment | ||
pip install pru | ||
|
||
# Calculate checksums before running pru | ||
minor_version=$(python${version} -c "import sys; print(f'{sys.version_info.minor}')") | ||
checksum_before_single=$(md5sum "pytests/requirements/3_${minor_version}/requirements_single_updated.txt" | cut -d ' ' -f 1) | ||
checksum_before_mix=$(md5sum "pytests/requirements/3_${minor_version}/requirements_mix_updated.txt" | cut -d ' ' -f 1) | ||
|
||
# Run pru to update requirements within the virtual environment | ||
pru -r "pytests/requirements/3_${minor_version}/requirements_single_updated.txt" | ||
pru -r "pytests/requirements/3_${minor_version}/requirements_mix_updated.txt" | ||
|
||
# Calculate checksums after running pru | ||
checksum_after_single=$(md5sum "pytests/requirements/3_${minor_version}/requirements_single_updated.txt" | cut -d ' ' -f 1) | ||
checksum_after_mix=$(md5sum "pytests/requirements/3_${minor_version}/requirements_mix_updated.txt" | cut -d ' ' -f 1) | ||
|
||
# Check if any requirements file was updated | ||
if [ "$checksum_before_single" != "$checksum_after_single" ]; then | ||
UPDATED_FILES+=("pytests/requirements/3_${minor_version}/requirements_single_updated.txt") | ||
fi | ||
if [ "$checksum_before_mix" != "$checksum_after_mix" ]; then | ||
UPDATED_FILES+=("pytests/requirements/3_${minor_version}/requirements_mix_updated.txt") | ||
fi | ||
|
||
# Deactivate the virtual environment | ||
deactivate | ||
# Remove the virtual environment directory | ||
rm -rf "env_${version}" | ||
done | ||
|
||
if [ ${#UPDATED_FILES[@]} -ne 0 ]; then | ||
echo "Requirements updated. Creating pull request." | ||
echo "::set-output name=updated::true" | ||
echo "::set-output name=updated_files::${UPDATED_FILES[*]}" | ||
echo "::set-output name=update_date::$DATE" | ||
else | ||
echo "No requirements updated." | ||
echo "::set-output name=updated::false" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: update | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pru | ||
- name: Determine current branch | ||
id: current_branch | ||
run: echo "CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV | ||
|
||
- name: Run requirements updater script | ||
id: run_pru | ||
run: | | ||
bash .github/scripts/update_requirements.sh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Configure git | ||
if: steps.run_pru.outputs.updated == 'true' | ||
run: | | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
- name: Create new branch | ||
if: steps.run_pru.outputs.updated == 'true' | ||
run: | | ||
BRANCH_NAME="update-requirements-${GITHUB_RUN_ID}" | ||
git checkout -b $BRANCH_NAME | ||
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
echo "DATE=${{ steps.run_pru.outputs.update_date }}" >> $GITHUB_ENV | ||
- name: Commit changes | ||
if: steps.run_pru.outputs.updated == 'true' | ||
run: | | ||
git add . | ||
git commit -m "Update requirements based on failed tests at $DATE" | ||
env: | ||
DATE: ${{ steps.run_pru.outputs.update_date }} | ||
|
||
- name: Push changes | ||
if: steps.run_pru.outputs.updated == 'true' | ||
run: | | ||
git push origin $BRANCH_NAME | ||
env: | ||
BRANCH_NAME: ${{ env.BRANCH_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
requests==2.32.2 | ||
numpy==1.26.4 | ||
requests==2.32.3 | ||
numpy==2.0.0 | ||
pandas==2.2.2 | ||
scipy==1.13.1 | ||
scipy==1.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
requests==2.32.2 | ||
requests==2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
requests==2.32.2 | ||
numpy==1.26.4 | ||
requests==2.32.3 | ||
numpy==2.0.0 | ||
pandas==2.2.2 | ||
scipy==1.13.1 | ||
scipy==1.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
requests==2.32.2 | ||
requests==2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
requests==2.32.2 | ||
numpy==1.26.4 | ||
requests==2.32.3 | ||
numpy==2.0.0 | ||
pandas==2.2.2 | ||
scipy==1.13.1 | ||
scipy==1.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
requests==2.32.2 | ||
requests==2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
requests==2.32.2 | ||
requests==2.32.3 | ||
numpy==1.24.4 | ||
pandas==2.0.3 | ||
scipy==1.10.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
requests==2.32.2 | ||
requests==2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
requests==2.32.2 | ||
numpy==1.26.4 | ||
requests==2.32.3 | ||
numpy==2.0.0 | ||
pandas==2.2.2 | ||
scipy==1.13.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
requests==2.32.2 | ||
requests==2.32.3 |