From e5dc6e39b62dd0ae3dfd747fb92542d4f582afea Mon Sep 17 00:00:00 2001 From: abatra2 Date: Fri, 5 Jul 2024 16:06:59 -0700 Subject: [PATCH] inital commit for CI/CD --- .../setup_conda_environment.sh | 31 ++++++++ .../workflows/build-base-docker-images.yml | 38 +++++++++ .../generate-hashed-requirements.yml | 58 ++++++++++++++ .github/workflows/integration-tests.yml | 77 +++++++++++++++++++ .github/workflows/release.yml | 51 ++++++++++++ .github/workflows/unit-test.yml | 32 ++++++++ 6 files changed, 287 insertions(+) create mode 100644 .github/workflow_scripts/setup_conda_environment.sh create mode 100644 .github/workflows/build-base-docker-images.yml create mode 100644 .github/workflows/generate-hashed-requirements.yml create mode 100644 .github/workflows/integration-tests.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/unit-test.yml diff --git a/.github/workflow_scripts/setup_conda_environment.sh b/.github/workflow_scripts/setup_conda_environment.sh new file mode 100644 index 000000000..82c542d7f --- /dev/null +++ b/.github/workflow_scripts/setup_conda_environment.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Ensure the script fails on error +set -e + +# Variables (Consider passing these as arguments to the script instead of hardcoding) +CONDA_ENV_NAME=gnn +PYTHON_VERSION=3.8 + +echo "Initializing environment and installing dependencies" + +if [ ! -d "$HOME/miniconda" ]; then + echo "Miniconda not found, installing..." + wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $HOME/miniconda.sh + bash $HOME/miniconda.sh -b -p $HOME/miniconda +else + echo "Miniconda already installed" +fi + +# Initialize conda in script +source $HOME/miniconda/etc/profile.d/conda.sh +conda init bash + +# Create the conda environment +conda create -y -c conda-forge --name ${CONDA_ENV_NAME} python=${PYTHON_VERSION} pip-tools + +# Reactivate conda.sh to ensure the conda activate command works +source $HOME/miniconda/etc/profile.d/conda.sh +conda activate ${CONDA_ENV_NAME} + +echo "${CONDA_ENV_NAME} environment is ready and activated." \ No newline at end of file diff --git a/.github/workflows/build-base-docker-images.yml b/.github/workflows/build-base-docker-images.yml new file mode 100644 index 000000000..c22be92ee --- /dev/null +++ b/.github/workflows/build-base-docker-images.yml @@ -0,0 +1,38 @@ +name: build-base-docker-images + +on: + issue_comment: + types: [created] + +jobs: + build-docker-images: + permissions: + contents: 'read' + id-token: 'write' + runs-on: ubuntu-latest + env: + TAG: ${{ github.run_number}} + if: contains(github.event.comment.body, '/build_base_docker_images') + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Google Cloud Auth + uses: 'google-github-actions/auth@v2' + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }} + + - name: Set Up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + + - name: Build and Push Docker Images + run: | + gcloud auth configure-docker us-central1-docker.pkg.dev + docker build -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/gigl-base-images/gigl-cpu-base:${TAG} -f containers/Dockerfile.cpu.base . + docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/gigl-base-images/gigl-cpu-base:${TAG} + docker build -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/gigl-base-images/gigl-cuda-base:${TAG} -f containers/Dockerfile.cuda.base . + docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/gigl-base-images/gigl-cuda-base:${TAG} \ No newline at end of file diff --git a/.github/workflows/generate-hashed-requirements.yml b/.github/workflows/generate-hashed-requirements.yml new file mode 100644 index 000000000..57eff25ed --- /dev/null +++ b/.github/workflows/generate-hashed-requirements.yml @@ -0,0 +1,58 @@ +name: generate-hashed-requirements + +on: + issue_comment: + types: [created] + +jobs: + generate-linux-hashed-requirements: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, '/generate_hashed_requirements') + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9.18' + + - name: Install pip-tools + run: pip install pip-tools + + - name: Generate hashed requirements + run: | + pip-compile -v --allow-unsafe --generate-hashes --no-emit-index-url --resolver=backtracking \ + --output-file=requirements/dev_linux_cuda_requirements_unified.txt \ + ./pyproject.toml + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: dev_linux_cuda_requirements_unified + path: requirements/dev_linux_cuda_requirements_unified.txt + + generate-mac-hashed-requirements: + runs-on: macos-14 + if: contains(github.event.comment.body, '/generate_hashed_requirements') + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9.18' + + - name: Install pip-tools + run: pip install pip-tools + + - name: Generate hashed requirements + run: | + pip-compile -v --allow-unsafe --generate-hashes --no-emit-index-url --resolver=backtracking \ + --output-file=requirements/dev_darwin_arm64_requirements_unified.txt \ + ./pyproject.toml + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: dev_darwin_arm64_requirements_unified + path: requirements/dev_darwin_arm64_requirements_unified.txt \ No newline at end of file diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 000000000..2d146be0f --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,77 @@ +name: integration_tests + +on: + issue_comment: + types: [created] + +jobs: + integration_tests: + permissions: + contents: 'read' + id-token: 'write' + pull-requests: write + statuses: write + if: contains(github.event.comment.body, '/integration_tests') + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Conda Environment + run: | + ./.github/workflow_scripts/setup_conda_environment.sh + shell: bash + + - name: Install Dependencies + run: | + source $HOME/miniconda/etc/profile.d/conda.sh + conda activate gnn + make install_dev_deps + shell: bash + + - name: Google Cloud Auth + uses: 'google-github-actions/auth@v2' + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + + - name: Use gcloud CLI + run: gcloud info + + - name: Run Integration Tests + run: | + source $HOME/miniconda/etc/profile.d/conda.sh + conda activate gnn + make integration_test + make integration_e2e_test + shell: bash + + - name: Fetch PR details and update commit status + uses: actions/github-script@v5 + if: always() + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pullRequest = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + const state = '${{ job.status }}'; + + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: pullRequest.data.head.sha, + state: state, + description: 'The integration tests have completed', + context: 'integration-tests' + }) + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..ce25f252b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + + - name: Build Binary Distribution + run: python3 -m build + + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + publish: + name: Publish to TestPyPi 🚀 + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + needs: build + environment: release + permissions: + id-token: write + steps: + - name: Download distribution + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 000000000..ae6cf362c --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,32 @@ +name: unit_test + +on: + pull_request: + types: [synchronize, opened, reopened] + +jobs: + unit-tests: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Conda Environment + run: | + ./.github/workflow_scripts/setup_conda_environment.sh + shell: bash + + - name: Install Dependencies + run: | + source $HOME/miniconda/etc/profile.d/conda.sh + conda activate gnn + make install_dev_deps + shell: bash + + - name: Run Unit Tests + run: | + source $HOME/miniconda/etc/profile.d/conda.sh + conda activate gnn + make unit_test + shell: bash \ No newline at end of file