Sample workflow scripts for GitHub Actions


The sample workflows are located in SQL Assurance Sample Folder in the GitHub Actions directory, which is the directory to which the BMC-AMI-SQL-Assurance-Version-13.1.00-for-Db2-UC.zip file is downloaded and extracted. For example: C:\Users\userName\Downloads\BMC-AMI-SQL-Assurance-Version-13.1.00-for-Db2-UC\BMC AMI SQL Assurance Version 13.1.00 for Db2 - UC\GitHub Actions\SQL Assurance Sample Folder

Sample workflow script for SQL Assurance Dynamic SQL

The following figure represents a sample workflow script for SQL Assurance Dynamic SQL:

###
### Workflow_SQL_Assurance_Dynamic_SQL_Sample.yml (for GitHub Actions)
###
# The sample workflow performs Authentication + Dynamic SQL steps using application defined command step.
# The sample workflow script is defined to use various items like below:
#  a) References to variables added through GitHub Actions secrets and variables.
#  b) Use of Linux based sed command to replace input as variable name by variable definition from GitHub Actions secrets and variables.
#  c) Use of configuration file (Config_SQL_Assurance_Dynamic_SQL.yml), that resides in directory (non-root folder).
#     Example of properties of authentication step is taken from config file "Config_SQL_Assurance_Dynamic_SQL.yml", that is
#       maintained inside folders "GitHub/SAMPLE/MAA/configFiles":
#            step authentication GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
#  d) GitHub Actions based "if:" condition command is used.
###
name: Workflow_SQL_Assurance_Dynamic_SQL_Sample   #name of the workflow

on:
  workflow_dispatch               #manual trigger of the workflow

jobs:
  SA_Dynamic_SQL:                  #name of the job
    runs-on: <name of the runner> #specify runner name
    container:
      image:attach:xwiki:Mainframe.Data-for-Db2.BMC-AMI-SQL-Assurance-for-Db2.COB13100.Command-and-syntax-reference.Universal-Connector-samples-in-BMC-AMI-SQL-Assurance.Sample-workflow-scripts-for-GitHub-Actions.WebHome@filename <Image location>/sqlassuranceuc:13.01.00.0001-GA
      options: -u <uid>           #specify uid of the user running the runner
     
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Check out repository
        uses: actions/checkout@v4
     
      # For certBased Authentication, uncomment the following task to unzip the specified client certificate
      # from repository into path specified with -d parameter (ex. /opt/secret)  
      # - name: unzip client certificate
      #   run: |
      #    unzip -P "${{secrets.zip_cert_pass}}" <clientCertificateName>.p12 -d /opt/secret
     
      # Perform various initialization functions using Linux based command sed
      - name: Initialization
        run: |
          echo "Replace variables defined in GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml file"
          # Linux command sed is used to replace the config file variables with GitHub Actions secrets and variables
          sed -i "s/USER_ID_AUTH/${{vars.user_id}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          sed -i "s/USER_PASS_AUTH/${{secrets.user_pass}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          # For certBased Authentication, uncomment the following 2 sed commands
          # sed -i "s|CERT_PATH_AUTH|/opt/secret/<clientCertificateName>.p12|" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          # sed -i "s/CERT_PASS_AUTH/${{secrets.cert_pass}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          # Use GitHub Actions environment variables to fetch workflow name, run number, run by and run mode of the executing workflow
          sed -i "s/PIPELINENAME_VALUE/${{github.workflow}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          sed -i "s/RUNNUMBER_VALUE/${{github.run_id}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          sed -i "s/RUNBY_VALUE/${{github.actor}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
          sed -i "s/RUNMODE_VALUE/${{github.event_name}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml         
          echo "-----   GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml file is updated -----"
     
      # Execute application step - authentication
      - name: Authentication
        run:
          step authentication GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml
         
      # Execute application step - analyzeDynamicSql (dynamic_sql)
      - name: SQL Assurance - Analyze Dynamic SQL
        run:
          step dynamic_sql GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml

      # Fetch the return code from output file output_analyze_dynamic_sql.properties
      # and set in output variable as environment variable to use in subsequent steps
      - name: Return Code-Dynamic SQL
        if: ${{ success() || failure() }}
        run: |
          . $GITHUB_WORKSPACE/output_analyze_dynamic_sql.properties  #read and fetch the return code from output file
          echo "retCode=$dynamicSqlRC" >> "$GITHUB_ENV"               #set the return code as environment variable

      ###
      # Execute dummy step - It could be any customized subsequent step based on the requirement
      # Using GitHub Actions based if condition - Run step only if condition is satisfied.
      ###
      - name: Run Dummy step
        if: ${{ (success() || failure()) && env.retCode <= '0004' }}
        run:
          step <dummy step name> GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml{{/secrets.zip_cert_pass}}

Sample workflow script for SQL Assurance Static and Dynamic SQL

The following figure represents a sample workflow script for SQL Assurance Static and Dynamic SQL:

###
### Workflow_SQL_Assurance_Static_Dynamic_SQL_Sample.yml (for GitHub Actions)
###
# The sample workflow performs Authentication + Static SQL (Package) + Dynamic SQL steps using application defined command step.
# The purpose of the workflow is to extract the return code from the respective output file. Once extracted, it can be used in the
# workflow to decide the execution of the subsequent steps.
# The sample workflow script is defined to use various items like below:
#  a) References to variables added through GitHub Actions secrets and variables.
#  b) Use of Linux based sed command to replace input as variable name by variable definition from GitHub Actions secrets and variables.
#  c) Use of configuration files (Config_SQL_Assurance_Static_SQL.yml & Config_SQL_Assurance_Dynamic_SQL.yml), that reside in directory (non-root folder).
#     Example of properties of authentication step is taken from config file "Config_SQL_Assurance_Static_SQL.yml", that is
#       maintained inside folders "GitHub/SAMPLE/MAA/configFiles":
#            step authentication GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
###
name: Workflow_SA_Static_Dynamic_SQL_Sample   #name of the workflow

on:
  workflow_dispatch               #manual trigger of the workflow

jobs:
  SA_Static_Dynamic_SQL:                  #name of the job
    runs-on: <name of the runner> #specify runner name
    container:
      image:attach:xwiki:Mainframe.Data-for-Db2.BMC-AMI-SQL-Assurance-for-Db2.COB13100.Command-and-syntax-reference.Universal-Connector-samples-in-BMC-AMI-SQL-Assurance.Sample-workflow-scripts-for-GitHub-Actions.WebHome@filename <Image location>/sqlassuranceuc:13.01.00.0001-GA
      options: -u <uid>           #specify uid of the user running the runner
     
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Check out repository
        uses: actions/checkout@v4
     
      # For certBased Authentication, uncomment the following task to unzip the specified client certificate
      # from repository into path specified with -d parameter (ex. /opt/secret)  
      # - name: unzip client certificate
      #   run: |
      #    unzip -P "${{secrets.zip_cert_pass}}" <clientCertificateName>.p12 -d /opt/secret
     
      # Perform various initialization functions using Linux based command sed
      - name: Initialization
        run: |
          echo "Replace variables defined in GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml file"
          # Linux command sed is used to replace the config file variables with GitHub Actions secrets and variables
          sed -i "s/USER_ID_AUTH/${{vars.user_id}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/USER_PASS_AUTH/${{secrets.user_pass}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          # For certBased Authentication, uncomment the following 2 sed commands
          # sed -i "s|CERT_PATH_AUTH|/opt/secret/<clientCertificateName>.p12|" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          # sed -i "s/CERT_PASS_AUTH/${{secrets.cert_pass}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          # Use GitHub Actions environment variables to fetch workflow name, run number, run by and run mode of the executing workflow
          sed -i "s/PIPELINENAME_VALUE/${{github.workflow}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/RUNNUMBER_VALUE/${{github.run_id}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/RUNBY_VALUE/${{github.actor}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/RUNMODE_VALUE/${{github.event_name}}/" GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml         
          echo "-----   GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml file is updated -----"
     
      # Execute application step - authentication
      - name: Authentication
        run:
          step authentication GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml

      # Execute application step - analyzeStaticSql (static_sql_package)
      - name: SQL Assurance - Analyze Static SQL
        run:
          step static_sql_package GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Static_SQL.yml

      # Fetch the return code from output file output_analyze_static_sql.properties
      # and set in output variable as environment variable to use in subsequent steps
      - name: Return Code-Static SQL
        if: ${{ success() || failure() }}
        run: |
          . $GITHUB_WORKSPACE/output_analyze_static_sql.properties    #read and fetch the return code from output file
          echo "staticRetCode=$staticSqlRC" >> "$GITHUB_ENV"          #set the return code as environment variable

      # Execute application step - analyzeDynamicSql (dynamic_sql)
      - name: SQL Assurance - Analyze Dynamic SQL
        if: ${{ success() || failure() }}
        run:
          step dynamic_sql GitHub/SAMPLE/MAA/configFiles/Config_SQL_Assurance_Dynamic_SQL.yml

      # Fetch the return code from output file output_analyze_dynamic_sql.properties
      # and set in output variable as environment variable to use in subsequent steps
      - name: Return Code-Dynamic SQL
        if: ${{ success() || failure() }}
        run: |
          . $GITHUB_WORKSPACE/output_analyze_dynamic_sql.properties     #read and fetch the return code from output file
          echo "dynamicRetCode=$dynamicSqlRC" >> "$GITHUB_ENV"          #set the return code as environment variable{{/secrets.zip_cert_pass}}

Sample workflow script for SQL Assurance Static SQL

The following figure represents a sample workflow script for SQL Assurance Static SQL:

###
### Workflow_SQL_Assurance_Static_SQL_Sample.yml (for GitHub Actions)
###
# The sample workflow performs Authentication + Static SQL steps using application defined command step.
# The sample workflow script is defined to use various items like below:
#  a) References to variables added through GitHub Actions secrets and variables.
#  b) Use of Linux based sed command to replace input as variable name by variable definition from GitHub Actions secrets and variables.
#  c) Use of configuration file (Config_SQL_Assurance_Static_SQL.yml), that is maintained in default root folder.
#     Example of properties of authentication step is taken from Config_SQL_Assurance_Static_SQL.yml file:
#            step authentication Config_SQL_Assurance_Static_SQL.yml
#     Note: If workflow executes with default configuration file name config.yml, that is maintained in root folder, then file name is not required in step command.
#     Example of properties of authentication step is taken from default file name config.yml maintained in root folder:
#            step authentication
###
name: Workflow_SQL_Assurance_Static_SQL_Sample   #name of the workflow

on:
  workflow_dispatch               #manual trigger of the workflow

jobs:
  SA_Static_SQL:                  #name of the job
    runs-on: <name of the runner> #specify runner name
    container:
      image:attach:xwiki:Mainframe.Data-for-Db2.BMC-AMI-SQL-Assurance-for-Db2.COB13100.Command-and-syntax-reference.Universal-Connector-samples-in-BMC-AMI-SQL-Assurance.Sample-workflow-scripts-for-GitHub-Actions.WebHome@filename <Image location>/sqlassuranceuc:13.01.00.0001-GA
      options: -u <uid>           #specify uid of the user running the runner
     
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Check out repository
        uses: actions/checkout@v4
     
      # For certBased Authentication, uncomment the following task to unzip the specified client certificate
      # from repository into path specified with -d parameter (ex. /opt/secret)  
      # - name: unzip client certificate
      #   run: |
      #    unzip -P "${{secrets.zip_cert_pass}}" <clientCertificateName>.p12 -d /opt/secret
     
      # Perform various initialization functions using Linux based command sed
      - name: Initialization
        run: |
          echo "Replace variables defined in Config_SQL_Assurance_Static_SQL.yml file"
          # Linux command sed is used to replace the config file variables with GitHub Actions secrets and variables
          sed -i "s/USER_ID_AUTH/${{vars.user_id}}/" Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/USER_PASS_AUTH/${{secrets.user_pass}}/" Config_SQL_Assurance_Static_SQL.yml
          # For certBased Authentication, uncomment the following 2 sed commands
          # sed -i "s|CERT_PATH_AUTH|/opt/secret/<clientCertificateName>.p12|" Config_SQL_Assurance_Static_SQL.yml
          # sed -i "s/CERT_PASS_AUTH/${{secrets.cert_pass}}/" Config_SQL_Assurance_Static_SQL.yml
          # Use GitHub Actions environment variables to fetch workflow name, run number, run by and run mode of the executing workflow
          sed -i "s/PIPELINENAME_VALUE/${{github.workflow}}/" Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/RUNNUMBER_VALUE/${{github.run_id}}/" Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/RUNBY_VALUE/${{github.actor}}/" Config_SQL_Assurance_Static_SQL.yml
          sed -i "s/RUNMODE_VALUE/${{github.event_name}}/" Config_SQL_Assurance_Static_SQL.yml         
          echo "-----   Config_SQL_Assurance_Static_SQL.yml file is updated -----"
     
      # Execute application step - authentication
      - name: Authentication
        run:
          step authentication Config_SQL_Assurance_Static_SQL.yml
         
      # Execute application step - analyzeStaticSql (static_sql_package)
      - name: SQL Assurance - Analyze Static SQL
        run:
          step static_sql_package Config_SQL_Assurance_Static_SQL.yml{{/secrets.zip_cert_pass}}

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*