Skip to content

Commit

Permalink
update github action workflow to at least one test pass and some skip…
Browse files Browse the repository at this point in the history
…ped, update bearer token function (#3353)
  • Loading branch information
sliu008 authored Nov 14, 2024
1 parent eacd893 commit d237ba3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 72 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,22 @@ jobs:
echo "any_test_failed=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_fail > 0 }}" >> $GITHUB_OUTPUT
echo "any_test_skipped=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_skip > 0 }}" >> $GITHUB_OUTPUT
echo "any_test_error=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_error > 0 }}" >> $GITHUB_OUTPUT
echo "all_tests_passed=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_succ == fromJSON( steps.publish-test.outputs.json ).stats.tests }}" >> $GITHUB_OUTPUT
echo "all_tests_passed=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_succ == fromJSON( steps.publish-test.outputs.json ).stats.tests }}" >> $GITHUB_ENV
# echo "any_test_failed=false" >> $GITHUB_OUTPUT
# echo "any_test_skipped=false" >> $GITHUB_OUTPUT
# echo "any_test_error=false" >> $GITHUB_OUTPUT
# echo "all_test_passed=true" >> $GITHUB_OUTPUT
echo "any_test_passed=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_succ > 0 }}" >> $GITHUB_OUTPUT
echo "all_tests_succeeded_or_skipped=${{ fromJSON( steps.publish-test.outputs.json ).stats.tests_succ > 0 && fromJSON( steps.publish-test.outputs.json ).stats.tests_fail == 0 && fromJSON( steps.publish-test.outputs.json ).stats.tests_error == 0 }}" >> $GITHUB_ENV
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: test-results/**
- name: Succeeded in Completing All Tests
uses: LouisBrunner/[email protected]
if: env.all_tests_passed == 'true'
if: env.all_tests_succeeded_or_skipped == 'true'
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: All Tests Run And Passed
name: All Tests Run and Completed (Passed and/or Skipped)
conclusion: success
output: |
{"summary":"No errors, skipped tests, or failed tests detected"}
{"summary":"No failed or errored tests; at least one test passed, with some skipped tests."}
tests_pass:
needs: verify_collection
name: Merge Pull Request
Expand Down
46 changes: 15 additions & 31 deletions tests/create_or_update_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,24 @@
from groq import Groq
import time


def bearer_token(env):
tokens = []
headers: dict = {'Accept': 'application/json'}
url: str = f"https://{'uat.' if env == 'uat' else ''}urs.earthdata.nasa.gov/api/users"
url = f"https://{'uat.' if env == 'uat' else ''}urs.earthdata.nasa.gov/api/users/find_or_create_token"

# First just try to get a token that already exists
try:
resp = requests.get(url + "/tokens", headers=headers,
auth=requests.auth.HTTPBasicAuth(os.environ['CMR_USER'], os.environ['CMR_PASS']))
response_content = json.loads(resp.content)

for x in response_content:
tokens.append(x['access_token'])

except Exception as ex: # noqa E722
print(ex)
print("Error getting the token - check user name and password")

# No tokens exist, try to create one
if not tokens:
try:
resp = requests.post(url + "/token", headers=headers,
auth=requests.auth.HTTPBasicAuth(os.environ['CMR_USER'], os.environ['CMR_PASS']))
response_content: dict = json.loads(resp.content)
tokens.append(response_content['access_token'])
except Exception as ex: # noqa E722
print(ex)
print("Error getting the token - check user name and password")

# If still no token, then we can't do anything
if not tokens:
return None

return next(iter(tokens))
# Make the request with the Base64-encoded Authorization header
resp = request_session.post(
url,
auth=HTTPBasicAuth(os.environ['CMR_USER'], os.environ['CMR_PASS'])
)

# Check for successful response
if resp.status_code == 200:
response_content = resp.json()
return response_content.get('access_token')

except Exception as e:
logging.warning(f"Error getting the token (status code {resp.status_code}): {e}", exc_info=True)


def get_collection_names(providers, env, collections_list):
Expand Down
54 changes: 23 additions & 31 deletions tests/verify_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,48 +64,40 @@ def read_skip_list(csv_file):
# Fixture for the first skip list (skip_collections1.csv)
@pytest.fixture(scope="session")
def skip_temporal(env):
return read_skip_list(f"skip/skip_temporal_{env}.csv")
current_dir = os.path.dirname(__file__)
path = os.path.join(current_dir, f"skip/skip_temporal_{env}.csv")
return read_skip_list(path)


# Fixture for the second skip list (skip_collections2.csv)
@pytest.fixture(scope="session")
def skip_spatial(env):
return read_skip_list(f"skip/skip_spatial_{env}.csv")
current_dir = os.path.dirname(__file__)
path = os.path.join(current_dir, f"skip/skip_spatial_{env}.csv")
return read_skip_list(path)


@pytest.fixture(scope="session")
def bearer_token(env: str, request_session: requests.Session) -> str:
tokens = []
headers: dict = {'Accept': 'application/json'}
url: str = f"https://{'uat.' if env == 'uat' else ''}urs.earthdata.nasa.gov/api/users"
url = f"https://{'uat.' if env == 'uat' else ''}urs.earthdata.nasa.gov/api/users/find_or_create_token"

# First just try to get a token that already exists
try:
resp = request_session.get(url + "/tokens", headers=headers,
auth=HTTPBasicAuth(os.environ['CMR_USER'], os.environ['CMR_PASS']))
response_content = json.loads(resp.content)

for x in response_content:
tokens.append(x['access_token'])

except: # noqa E722
logging.warning("Error getting the token - check user name and password", exc_info=True)

# No tokens exist, try to create one
if not tokens:
try:
resp = request_session.post(url + "/token", headers=headers,
auth=HTTPBasicAuth(os.environ['CMR_USER'], os.environ['CMR_PASS']))
response_content: dict = json.loads(resp.content)
tokens.append(response_content['access_token'])
except: # noqa E722
logging.warning("Error getting the token - check user name and password", exc_info=True)

# If still no token, then we can't do anything
if not tokens:
pytest.skip("Unable to get bearer token from EDL")

return next(iter(tokens))
# Make the request with the Base64-encoded Authorization header
resp = request_session.post(
url,
auth=HTTPBasicAuth(os.environ['CMR_USER'], os.environ['CMR_PASS'])
)

# Check for successful response
if resp.status_code == 200:
response_content = resp.json()
return response_content.get('access_token')

except Exception as e:
logging.warning(f"Error getting the token (status code {resp.status_code}): {e}", exc_info=True)

# Skip the test if no token is found
pytest.skip("Unable to get bearer token from EDL")


@pytest.fixture(scope="function")
Expand Down

0 comments on commit d237ba3

Please sign in to comment.