Skip to content

Commit

Permalink
Test #1
Browse files Browse the repository at this point in the history
  • Loading branch information
StrahinjaJacimovic committed Aug 15, 2024
1 parent a915f17 commit 941f45c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Index Latest Release
on:
workflow_dispatch:
inputs:
release_version:
type: string
description: Which release version to index (type v1.0.6 for example)
default: "latest"
select_index:
type: choice
description: Index as test or live
Expand All @@ -29,11 +33,7 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install aiohttp
pip install aiofiles
pip install requests
pip install py7zr
pip install elasticsearch==7.13.4
pip install -r scripts/requirements/shared.txt
sudo apt-get install p7zip-full
- name: Run Index Script
Expand All @@ -44,8 +44,8 @@ jobs:
run: |
if [[ ${{ github.event.inputs.select_index }} == "Live" ]]; then
echo "Indexing to Live."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_LIVE }} ${{ github.event.inputs.force_index }}
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_LIVE }} ${{ github.event.inputs.force_index }} ${{ github.event.inputs.release_version }}
else
echo "Indexing to Test."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_TEST }} ${{ github.event.inputs.force_index }}
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_TEST }} ${{ github.event.inputs.force_index }} ${{ github.event.inputs.release_version }}
fi
6 changes: 1 addition & 5 deletions .github/workflows/recursiveBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install aiohttp
pip install aiofiles
pip install requests
pip install py7zr
pip install elasticsearch==7.13.4
pip install -r scripts/requirements/shared.txt
sudo apt-get update
sudo apt-get install p7zip-full
sudo apt-get install libopus-dev
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install aiohttp
pip install aiofiles
pip install requests
pip install py7zr
pip install openpyxl
pip install pandas
pip install elasticsearch==7.13.4
pip install -r scripts/requirements/shared.txt
pip install -r scripts/requirements/release.txt
- name: Run Release Script
env:
Expand Down
17 changes: 14 additions & 3 deletions scripts/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ def get_headers(api, token):
}

# Function to fetch release details from GitHub
def fetch_release_details(repo, token):
def fetch_release_details(repo, token, release_version):
api_headers = get_headers(True, token)
url = f'https://api.github.com/repos/{repo}/releases'
response = requests.get(url, headers=api_headers)
response.raise_for_status() # Raise an exception for HTTP errors
return support.get_latest_release(response.json()), support.get_previous_release(response.json(), True)
if "latest" == release_version:
return support.get_latest_release(response.json()), support.get_previous_release(response.json(), True)
else:
release_check = None
release_check = support.get_specified_release(response.json(), release_version)
if release_check:
return release_check, support.get_previous_release(response.json(), True)
else:
## Always fallback to latest release
print("WARNING: Falling back to LATEST release.")
return support.get_latest_release(response.json()), support.get_previous_release(response.json(), True)

# Function to fetch content as JSON from the link
def fetch_json_data(download_link, token):
Expand Down Expand Up @@ -212,6 +222,7 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
parser.add_argument("token", help="GitHub Token")
parser.add_argument("select_index", help="Provided index name")
parser.add_argument("force_index", help="If true will update packages even if hash is the same", type=bool)
parser.add_argument("release_version", help="Selected release version to index to current database", type=str)
args = parser.parse_args()

# Elasticsearch instance used for indexing
Expand All @@ -237,6 +248,6 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
# Now index the new release
index_release_to_elasticsearch(
es, args.select_index,
fetch_release_details(args.repo, args.token),
fetch_release_details(args.repo, args.token, args.release_version),
args.token, args.force_index
)
2 changes: 2 additions & 0 deletions scripts/requirements/release.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openpyxl
pandas
5 changes: 5 additions & 0 deletions scripts/requirements/shared.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
aiohttp
aiofiles
requests
py7zr
elasticsearch==7.13.4
4 changes: 4 additions & 0 deletions scripts/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def get_previous_release(releases, prerelases=None):
return None
return None

def get_specified_release(releases, release_version):
''' Fetch the latest released version '''
return next((release for release in releases if release_version == release['tag_name']), None)

def get_latest_release(releases):
''' Fetch the latest released version '''
return next((release for release in releases if not release['prerelease'] and not release['draft']), None)
Expand Down

0 comments on commit 941f45c

Please sign in to comment.