Skip to content

trigger-workflow

trigger-workflow #206

name: Update Latest Database From mikroSDK
on:
repository_dispatch:
types: [trigger-workflow]
jobs:
Update-Database-From-mikroSDK:
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:
ref: ${{ github.event.client_payload.sha }}
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: Extract payload version
id: mikrosdk_payload
run: |
echo "tag_version=${{ github.event.client_payload.version }}" >> $GITHUB_OUTPUT
echo "index=${{ github.event.client_payload.index }}" >> $GITHUB_OUTPUT
- name: Upload new database asset
run: |
python -u scripts/reupload_databases.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ secrets.PROG_DEBUG_CODEGRIP }} ${{ secrets.PROG_DEBUG_MIKROPROG }} "latest" ${{ steps.mikrosdk_payload.outputs.tag_version }} ${{ steps.mikrosdk_payload.outputs.index }}
- 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 [[ ${{ steps.mikrosdk_payload.outputs.index }} == "Live" ]]; then
DB_NAME="necto_db.db"
else
DB_NAME="necto_db_dev.db"
fi
STATUS=$(git status --short "$DB_NAME")
if [ -z "$STATUS" ]; then
echo "No changes made to $DB_NAME";
else
echo "Updating with new $DB_NAME";
echo "test"
git pull
git add $DB_NAME
git commit -m "Updated $DB_NAME with latest merged release."
git push
if [[ ${{ steps.mikrosdk_payload.outputs.index }} == "Live" ]]; then
curl --location --request POST '${{ secrets.ERP_DB_IMPORT_API }}' \
--header 'Authorization: Basic ${{ secrets.ERP_DB_IMPORT_KEY }}'
fi
fi
- name: Run Index Script
env:
ES_HOST: ${{ secrets.ES_HOST }}
ES_USER: ${{ secrets.ES_USER }}
ES_PASSWORD: ${{ secrets.ES_PASSWORD }}
run: |
if [[ ${{ steps.mikrosdk_payload.outputs.index }} == "Test" ]]; then
echo "Indexing database to TEST."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_TEST }} "True" "latest" "True" "False"
fi
if [[ ${{ steps.mikrosdk_payload.outputs.index }} == "Live" ]]; then
echo "Indexing database to LIVE."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_LIVE }} "True" "latest" "True" "False"
fi