Skip to content

Remove/Update Devices in the Database #26

Remove/Update Devices in the Database

Remove/Update Devices in the Database #26

name: Remove/Update Devices in the Database
on:
workflow_dispatch:
inputs:
select_index:
type: choice
description: Index as test or live
options:
- Test
- Live
default: "Test"
select_action:
type: choice
description: Select what you want to do
options:
- Set sdk_support
- Remove Devices
default: "Set SDKToDevice"
regex:
type: string
description: Regex of Device uids to use
default: "PIC32MZ2048EFH144|MCU_CARD_10_FOR_KINETIS_MK60DN512VLQ10"
delete_device:
type: boolean
description: Remove Device completely? (only used for "Remove Devices" option, clears only sdk_support if not checked)
default: false
xc8_specific:
type: boolean
description: Set XC8 support? (only used for "Set sdk_support" option)
default: false
AI_generated_sdk:
type: boolean
description: AI generated SDK? (only used for "Set sdk_support" option)
default: false
jobs:
Update_Devices_in_Dev_Database:
if: ${{ github.event.inputs.select_index == 'Test' }}
runs-on: ubuntu-latest
steps:
- name: Authorize Mikroe Actions App
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.MIKROE_ACTIONS }}
private-key: ${{ secrets.MIKROE_ACTIONS_KEY_AUTHORIZE }}
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r scripts/requirements/shared.txt
pip install -r scripts/requirements/databases.txt
sudo apt-get install p7zip-full
- name: Upload new database asset
run: |
python -u scripts/update_devices_db.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} "Test" "${{ github.event.inputs.select_action }}" "${{ github.event.inputs.regex }}" ${{ github.event.inputs.delete_device }} ${{ github.event.inputs.xc8_specific }} "--ai_sdk" ${{ github.event.inputs.AI_generated_sdk }}
- name: Add GitHub Actions credentials
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Commit and Push Changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Updating with new dev database";
git add necto_db_dev.db
git commit -m "Updated necto dev database with latest merged release."
git push
curl --location --request POST '${{ secrets.ERP_DB_IMPORT_API }}' \
--header 'Authorization: Basic ${{ secrets.ERP_DB_IMPORT_KEY }}'
else
echo "No changes made to necto_db_dev.db";
fi
- name: Run Index Script
env:
ES_HOST: ${{ secrets.ES_HOST }}
ES_USER: ${{ secrets.ES_USER }}
ES_PASSWORD: ${{ secrets.ES_PASSWORD }}
run: |
echo "Indexing database to TEST."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_TEST }} ${{ secrets.PROG_DEBUG_CODEGRIP }} "True" "latest" "True" "False"
Update_Devices_in_Live_Database:
if: ${{ github.event.inputs.select_index == 'Live' }}
runs-on: ubuntu-latest
steps:
- name: Authorize Mikroe Actions App
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.MIKROE_ACTIONS }}
private-key: ${{ secrets.MIKROE_ACTIONS_KEY_AUTHORIZE }}
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r scripts/requirements/shared.txt
pip install -r scripts/requirements/databases.txt
sudo apt-get install p7zip-full
- name: Upload new database asset
run: |
python -u scripts/update_devices_db.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} "Live" "${{ github.event.inputs.select_action }}" "${{ github.event.inputs.regex }}" ${{ github.event.inputs.delete_device }} ${{ github.event.inputs.xc8_specific }} "--ai_sdk" ${{ github.event.inputs.AI_generated_sdk }}
- name: Add GitHub Actions credentials
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Commit and Push Changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Updating with new live database";
git add necto_db.db
git commit -m "Updated necto live database with latest merged release."
git push
curl --location --request POST '${{ secrets.ERP_DB_IMPORT_API }}' \
--header 'Authorization: Basic ${{ secrets.ERP_DB_IMPORT_KEY }}'
else
echo "No changes made to necto_db.db";
fi
- name: Run Index Script
env:
ES_HOST: ${{ secrets.ES_HOST }}
ES_USER: ${{ secrets.ES_USER }}
ES_PASSWORD: ${{ secrets.ES_PASSWORD }}
run: |
echo "Indexing database to LIVE."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_LIVE }} ${{ secrets.PROG_DEBUG_CODEGRIP }} "True" "latest" "True" "False"