Merge pull request #388 from ebattat/try2 #496
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [ "main" ] | |
workflow_dispatch: | |
jobs: | |
grafonnet_generator: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Update product versions in main.libsonnet | |
env: | |
PERF_MAIN_LIBSONNET_PATH: grafonnet_generator/grafana/perf/jsonnet/main.libsonnet | |
ELASTICSEARCH: ${{ secrets.ELASTICSEARCH }} | |
ELASTICSEARCH_PORT: ${{ secrets.ELASTICSEARCH_PORT }} | |
ELASTICSEARCH_USER: ${{ secrets.ELASTICSEARCH_USER }} | |
ELASTICSEARCH_PASSWORD: ${{ secrets.ELASTICSEARCH_PASSWORD }} | |
run: | | |
pip install elasticsearch==7.17.6 | |
cd "$GITHUB_WORKSPACE" && PYTHONPATH=. python grafonnet_generator/common/grafana/update_versions_main_libsonnet.py | |
- name: Generate grafana dashboard.json using grafonnet container | |
run: | | |
sudo podman run --rm --name run_grafonnet -v "$GITHUB_WORKSPACE"/grafonnet_generator/grafana/perf:/app --privileged quay.io/ebattat/run_grafonnet:latest | |
- name: Check for changes in dashboard.json | |
id: check_changes | |
run: | | |
git diff --quiet $GITHUB_WORKSPACE/grafonnet_generator/grafana/perf/dashboard.json || echo "changes=true" >> "$GITHUB_OUTPUT" | |
- name: Update the Grafana dashboard if any changes are detected in dashboard.json | |
if: steps.check_changes.outputs.changes == 'true' | |
env: | |
PERF_GRAFANA_URL: ${{ secrets.PERF_GRAFANA_URL }} | |
PERF_GRAFANA_API_KEY: ${{ secrets.PERF_GRAFANA_API_KEY }} | |
PERF_GRAFANA_JSON: grafonnet_generator/grafana/perf/dashboard.json | |
PERF_MAIN_LIBSONNET_PATH: grafonnet_generator/grafana/perf/jsonnet/main.libsonnet | |
ELASTICSEARCH: ${{ secrets.ELASTICSEARCH }} | |
ELASTICSEARCH_PORT: ${{ secrets.ELASTICSEARCH_PORT }} | |
ELASTICSEARCH_USER: ${{ secrets.ELASTICSEARCH_USER }} | |
ELASTICSEARCH_PASSWORD: ${{ secrets.ELASTICSEARCH_PASSWORD }} | |
run: | | |
pip install elasticsearch==7.17.6 | |
# backup dashboard.json before adding dashboard version by python code | |
cp $GITHUB_WORKSPACE/grafonnet_generator/grafana/perf/dashboard.json $GITHUB_WORKSPACE/grafonnet_generator/grafana/perf/dashboard_backup.json | |
cd "$GITHUB_WORKSPACE" && PYTHONPATH=. python grafonnet_generator/grafana/update_grafana_dashboard.py | |
# revert dashboard.json w/o grafana dashboard version | |
cp -p $GITHUB_WORKSPACE/grafonnet_generator/grafana/perf/dashboard_backup.json $GITHUB_WORKSPACE/grafonnet_generator/grafana/perf/dashboard.json | |
- name: Commit dashboard.json if any changes are detected | |
if: steps.check_changes.outputs.changes == 'true' | |
run: | | |
git checkout main | |
git config --global user.email "${{ secrets.EMAIL }}" | |
git config --global user.name "${{ secrets.USER_NAME }}" | |
git config pull.rebase false # merge | |
git commit grafonnet_generator/grafana/perf/dashboard.json -m "Update grafana json file" | |
git pull https://${{ secrets.GIT_TOKEN }}@${{ secrets.GIT_REPOSITORY}} main | |
git push https://${{ secrets.GIT_TOKEN }}@${{ secrets.GIT_REPOSITORY}} main | |
- name: Check if adding new products versions in main.libsonnet | |
id: libsonnet_check_changes | |
run: | | |
git diff --quiet "$GITHUB_WORKSPACE"/grafonnet_generator/grafana/perf/jsonnet/main.libsonnet || echo "changes=true" >> "$GITHUB_OUTPUT" | |
- name: Commit main.libsonnet if any changes are detected | |
if: steps.libsonnet_check_changes.outputs.changes == 'true' | |
run: | | |
git checkout main | |
git config --global user.email "${{ secrets.EMAIL }}" | |
git config --global user.name "${{ secrets.USER_NAME }}" | |
git config pull.rebase false # merge | |
git commit grafonnet_generator/grafana/perf/jsonnet/main.libsonnet -m "Update main.libsonnet file" | |
git pull https://${{ secrets.GIT_TOKEN }}@${{ secrets.GIT_REPOSITORY}} main | |
git push https://${{ secrets.GIT_TOKEN }}@${{ secrets.GIT_REPOSITORY}} main |