From 64b2f4155623516346a49e112dd4c5c74ed48bdc Mon Sep 17 00:00:00 2001 From: danholdaway Date: Wed, 23 Oct 2024 10:29:15 -0400 Subject: [PATCH 1/4] Add GitHub testing --- .github/workflows/run_jcb_basic_testing.yaml | 77 ++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/run_jcb_basic_testing.yaml diff --git a/.github/workflows/run_jcb_basic_testing.yaml b/.github/workflows/run_jcb_basic_testing.yaml new file mode 100644 index 0000000..7305d7e --- /dev/null +++ b/.github/workflows/run_jcb_basic_testing.yaml @@ -0,0 +1,77 @@ +name: Run JCB client testing with client changes + +on: + push: + branches: + - develop + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + + jcb_integration_tests: + + runs-on: ubuntu-latest + name: JCB Client Integration Tests + + env: + JCB_REPO: https://github.com/NOAA-EMC/jcb.git + + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Add repo url to the environment + run: | + JCB_ALGO_REPO="${{ github.repository }}" + echo "JCB_ALGO_REPO=${JCB_ALGO_REPO}" >> $GITHUB_ENV + + - name: Determine the name of the client branch + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + JCB_ALGO_BRANCH=${{ github.head_ref }} + else + BRANCH_REF=${{ github.ref }} + JCB_ALGO_BRANCH=${BRANCH_REF#refs/heads/} + fi + echo "JCB_ALGO_BRANCH=$JCB_ALGO_BRANCH" >> $GITHUB_ENV + + - name: Determine branch to use for main jcb repo + run: | + BRANCH_NAME=${{ env.JCB_ALGO_BRANCH }} + if git ls-remote --heads $JCB_REPO $BRANCH_NAME | grep -q "refs/heads/$BRANCH_NAME"; then + echo "Branch $BRANCH_NAME exists in jcb repo." + echo "JCB_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV + else + echo "Branch $BRANCH_NAME does not exist in jcb repo. Using develop branch." + echo "JCB_BRANCH=develop" >> $GITHUB_ENV + fi + + - name: Clone jcb repository + run: | + mkdir -p empty_hooks + git config --global core.hooksPath empty_hooks + git clone --branch ${{ env.JCB_BRANCH }} --recursive $JCB_REPO jcb_repo + + - name: Clone the clients + run: | + cd jcb_repo + pip install pyyaml + ./jcb_client_init.py + # Note that the above step will take care of checking out the correct branch of the + # algorithm repo and any clients being simultaneously modified. + + - name: Install dependencies + run: | + cd jcb_repo + pip install .[testing] + + - name: Run the JCB client integration tests + run: | + cd jcb_repo/test/client_integration + pytest -v From bfe05b56b3f1eb907e7b7ac8dbe05114efd0cb63 Mon Sep 17 00:00:00 2001 From: danholdaway Date: Wed, 23 Oct 2024 11:03:34 -0400 Subject: [PATCH 2/4] safety feature --- .github/workflows/run_jcb_basic_testing.yaml | 38 +++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/run_jcb_basic_testing.yaml b/.github/workflows/run_jcb_basic_testing.yaml index 7305d7e..c175650 100644 --- a/.github/workflows/run_jcb_basic_testing.yaml +++ b/.github/workflows/run_jcb_basic_testing.yaml @@ -19,6 +19,7 @@ jobs: env: JCB_REPO: https://github.com/NOAA-EMC/jcb.git + JCB_ALGO_REPO: https://github.com/NOAA-EMC/jcb-algorithms.git steps: - name: Set up Python @@ -28,28 +29,43 @@ jobs: - name: Add repo url to the environment run: | - JCB_ALGO_REPO="${{ github.repository }}" - echo "JCB_ALGO_REPO=${JCB_ALGO_REPO}" >> $GITHUB_ENV + JCB_APP_REPO="${{ github.repository }}" + echo "JCB_APP_REPO=${JCB_APP_REPO}" >> $GITHUB_ENV - name: Determine the name of the client branch run: | if [ "${{ github.event_name }}" == "pull_request" ]; then - JCB_ALGO_BRANCH=${{ github.head_ref }} + JCB_APP_BRANCH=${{ github.head_ref }} else BRANCH_REF=${{ github.ref }} - JCB_ALGO_BRANCH=${BRANCH_REF#refs/heads/} + JCB_APP_BRANCH=${BRANCH_REF#refs/heads/} fi - echo "JCB_ALGO_BRANCH=$JCB_ALGO_BRANCH" >> $GITHUB_ENV + echo "JCB_APP_BRANCH=$JCB_APP_BRANCH" >> $GITHUB_ENV - - name: Determine branch to use for main jcb repo + - name: Check for existence of the branch name in the main jcb repo run: | - BRANCH_NAME=${{ env.JCB_ALGO_BRANCH }} + BRANCH_NAME=${{ env.JCB_APP_BRANCH }} if git ls-remote --heads $JCB_REPO $BRANCH_NAME | grep -q "refs/heads/$BRANCH_NAME"; then + echo "Branch $BRANCH_NAME exists in jcb repo." - echo "JCB_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV + else - echo "Branch $BRANCH_NAME does not exist in jcb repo. Using develop branch." - echo "JCB_BRANCH=develop" >> $GITHUB_ENV + + # If the tested jcb-algorithms branch does not exist in the main jcb repo then we need to + # throw an error. This is not a safe situation. The developer should create a branch in + # the main jcb repo with the same name as the branch in the jcb-application repo. + # If there were branches in other apps to account for the changes in the algorithm repo + # they could not be tested here since the scipt is not clever enough to check for + # the existence of the branch being tested here in all the clients. The safest thing to do + # is simply create a branch with the same name (even if empty) in the main jcb repo. This + # will ensure the branches of the other applications are checked out by the init script. + + echo "The $BRANCH_NAME being tested for jcb-algorithms does not exist in the main jcb " + echo "repo. Please create a branch with the same name in the jcb repo (even if empty). " + echo "This ensures that where you have made branches with the same name in the clients " + echo "they will be checked out by the cleint intialization script." + exit 1 + fi - name: Clone jcb repository @@ -63,8 +79,6 @@ jobs: cd jcb_repo pip install pyyaml ./jcb_client_init.py - # Note that the above step will take care of checking out the correct branch of the - # algorithm repo and any clients being simultaneously modified. - name: Install dependencies run: | From 129438a06c16591f70b15242d6d4e1114fe376fa Mon Sep 17 00:00:00 2001 From: danholdaway Date: Wed, 23 Oct 2024 11:06:30 -0400 Subject: [PATCH 3/4] update comment --- .github/workflows/run_jcb_basic_testing.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_jcb_basic_testing.yaml b/.github/workflows/run_jcb_basic_testing.yaml index c175650..28a1dd7 100644 --- a/.github/workflows/run_jcb_basic_testing.yaml +++ b/.github/workflows/run_jcb_basic_testing.yaml @@ -60,10 +60,11 @@ jobs: # is simply create a branch with the same name (even if empty) in the main jcb repo. This # will ensure the branches of the other applications are checked out by the init script. - echo "The $BRANCH_NAME being tested for jcb-algorithms does not exist in the main jcb " - echo "repo. Please create a branch with the same name in the jcb repo (even if empty). " - echo "This ensures that where you have made branches with the same name in the clients " - echo "they will be checked out by the cleint intialization script." + echo "The $BRANCH_NAME branch begin tested for jcb-algorithms does not exist in the main " + echo "jcb repo. Please create a branch with the same name in the jcb repo (even if " + echo "empty and without PR). This ensures that where you have made branches with the " + echo "same name in any clients they will be checked out by the cleint intialization " + echo "script." exit 1 fi From 3d028ebe2a6bb9ea2423231dcfd7440a1950a74f Mon Sep 17 00:00:00 2001 From: danholdaway Date: Wed, 23 Oct 2024 11:09:45 -0400 Subject: [PATCH 4/4] correct the branch name --- .github/workflows/run_jcb_basic_testing.yaml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/run_jcb_basic_testing.yaml b/.github/workflows/run_jcb_basic_testing.yaml index 28a1dd7..843b304 100644 --- a/.github/workflows/run_jcb_basic_testing.yaml +++ b/.github/workflows/run_jcb_basic_testing.yaml @@ -27,24 +27,19 @@ jobs: with: python-version: '3.x' - - name: Add repo url to the environment - run: | - JCB_APP_REPO="${{ github.repository }}" - echo "JCB_APP_REPO=${JCB_APP_REPO}" >> $GITHUB_ENV - - - name: Determine the name of the client branch + - name: Determine the name of the algorithm branch run: | if [ "${{ github.event_name }}" == "pull_request" ]; then - JCB_APP_BRANCH=${{ github.head_ref }} + JCB_ALGO_BRANCH=${{ github.head_ref }} else BRANCH_REF=${{ github.ref }} - JCB_APP_BRANCH=${BRANCH_REF#refs/heads/} + JCB_ALGO_BRANCH=${BRANCH_REF#refs/heads/} fi - echo "JCB_APP_BRANCH=$JCB_APP_BRANCH" >> $GITHUB_ENV + echo "JCB_ALGO_BRANCH=$JCB_ALGO_BRANCH" >> $GITHUB_ENV - name: Check for existence of the branch name in the main jcb repo run: | - BRANCH_NAME=${{ env.JCB_APP_BRANCH }} + BRANCH_NAME=${{ env.JCB_ALGO_BRANCH }} if git ls-remote --heads $JCB_REPO $BRANCH_NAME | grep -q "refs/heads/$BRANCH_NAME"; then echo "Branch $BRANCH_NAME exists in jcb repo." @@ -73,7 +68,7 @@ jobs: run: | mkdir -p empty_hooks git config --global core.hooksPath empty_hooks - git clone --branch ${{ env.JCB_BRANCH }} --recursive $JCB_REPO jcb_repo + git clone --branch ${{ env.JCB_ALGO_BRANCH }} $JCB_REPO jcb_repo - name: Clone the clients run: |