Skip to content

GAM Trigger - Dashboard-12619645985 #8

GAM Trigger - Dashboard-12619645985

GAM Trigger - Dashboard-12619645985 #8

name: Gated Auto Merger
run-name: GAM Trigger - ${{ inputs.component }}-${{ inputs.gam_trigger_run_id }}
on:
workflow_dispatch:
inputs:
component:
type: choice
description: select component
required: true
options:
- Dashboard
gam_trigger_repository:
description: 'Github Repository of the GAM Trigger Workflow. (Leave this field empty when triggered via the UI)'
required: false
gam_trigger_run_id:
description: 'Workflow Run ID of the GAM Trigger Workflow. (Leave this field empty when triggered via the UI)'
required: false
gam_execution_id:
description: 'A Unique ID for The GAM Execution. (Leave this field empty when triggered via the UI)'
required: false
env:
METADATA: "data/metadata.yaml"
GAM_TRIGGER_REPOSITORY: ${{ inputs.gam_trigger_repository }}
GAM_EXECUTION_ID: ${{ inputs.gam_execution_id }}
GAM_TRIGGER_RUN_ID: ${{ inputs.gam_trigger_run_id }}
jobs:
gated-auto-merger:
runs-on: ubuntu-latest
steps:
- name: Generate input variables if empty
run: |
if [ -z "${{ env.GAM_TRIGGER_REPOSITORY }}" ]; then
echo "GAM_TRIGGER_REPOSITORY=$GITHUB_REPOSITORY" | tee -a $GITHUB_ENV
fi
if [ -z "${{ env.GAM_TRIGGER_RUN_ID }}" ]; then
echo "GAM_TRIGGER_RUN_ID=$GITHUB_RUN_ID" | tee -a $GITHUB_ENV
fi
if [ -z "${{ env.GAM_EXECUTION_ID }}" ]; then
echo "GAM_EXECUTION_ID=$(date +"%d%m%y%H%M%S%6N")" | tee -a $GITHUB_ENV
fi
echo "THIS_WORKFLOW_RUN_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | tee -a $GITHUB_ENV
- name: Print Trigger Workflow Details
run: |
echo "This workflow was triggered by https://github.com/${{ env.GAM_TRIGGER_REPOSITORY }}/actions/runs/${{ env.GAM_TRIGGER_RUN_ID }}"
- uses: actions/checkout@v3
with:
repository: red-hat-data-services/Gated-Auto-Merger
ref: main
path: main
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: '3.10.15' # Specify the Python version you need
- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv
- name: Install dependencies from Pipfile.lock
run: cd main && pipenv install --ignore-pipfile
- name: Trigger GAM
env:
HYDRA_TOKEN: ${{ secrets.HYDRA_TOKEN }}
shell: bash
id: trigger_gam
run: |
cd main
pipenv run python src/main.py --component ${{ inputs.component }} --execution_id ${{ env.GAM_EXECUTION_ID }} --gam_run_url ${{ env.THIS_WORKFLOW_RUN_URL }}
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
owner: red-hat-data-services
repositories: Gated-Auto-Merger
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: configure git committer string
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
- uses: actions/checkout@v3
with:
repository: red-hat-data-services/Gated-Auto-Merger
token: ${{ steps.app-token.outputs.token }}
ref: metadata
path: metadata
- name: Copy metadata Json
id: copy_meta
run: |
meta=$(yq -o json main/$METADATA)
metadata_folder="metadata/executions/${{ inputs.component }}/${{ env.GAM_EXECUTION_ID }}"
mkdir -p ${metadata_folder}
cp main/$METADATA ${metadata_folder}
cat ${metadata_folder}/metadata.yaml
echo "----------------------------------------------------"
echo "METADATA_FILE=${metadata_folder}/metadata.yaml" | tee -a $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
with:
name: metadata_file
path: ${{ steps.copy_meta.outputs.METADATA_FILE }}
if-no-files-found: error
- name: Commit and push changes to metadata branch
run: |
cd metadata
git status
git add .
git commit -m "Adding metadata.yaml - Component: '${{ inputs.component }}', Execution ID: '${{ env.GAM_EXECUTION_ID }}'"
git push origin metadata