Skip to content

Github Action as a wrapper for executing a single command in stackql, maps all stackql exec args to actions args

License

Notifications You must be signed in to change notification settings

stackql/stackql-exec

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

stackql-exec

Github Action as a wrapper for executing a single command in stackql, maps all stackql exec args to actions args

Usage

Provider Authentication

Authentication to StackQL providers is done via environment variables source from GitHub Actions Secrets. To learn more about authentication, see the setup instructions for your provider or providers at the StackQL Provider Registry Docs.

Inputs

  • query - stackql query to execute (need to supply either query or query_file_path)
  • query_file_path - stackql query file to execute (need to supply either query or query_file_path)
  • data_file_path - (optional) path to data file to pass to the stackql query preprocessor (json or jsonnet)
  • vars - (optional) comma delimited list of variables to pass to the stackql query preprocessor (supported with jsonnet config blocks or jsonnet data files only), accepts var1=val1,var2=val2, can be used to source environment variables into stackql queries
  • query_output - (optional) output format of the stackql exec result, accepts table, csv, json and text, defaults to json
  • auth_obj_path - (optional) the path of json file that stores stackql AUTH string (only required when using non-standard environment variable names)
  • auth_str - (optional) stackql AUTH string (only required when using non-standard environment variable names)
  • is_command - (optional defaults to 'false') set to true if the stackql execution is a command that does not return data

Outputs

This action uses setup-stackql, with use_wrapper set to true, stdout and stderr are set to exec-result and exec-error

  • exec-result - The STDOUT stream of the call to the stackql binary.
  • exec-error - The STDERR stream of the call to the stackql binary.

Examples

Inline stackql query example

this is an example of a command (that does not return data):

    - name: exec github example
      uses: ./
      with:
        is_command: 'true'
        query: "REGISTRY PULL github;
      env: 
        STACKQL_GITHUB_USERNAME: ${{  secrets.STACKQL_GITHUB_USERNAME }}
        STACKQL_GITHUB_PASSWORD: ${{  secrets.STACKQL_GITHUB_PASSWORD }}

this is an example of a query that returns data:

    - name: exec github example
      uses: ./
      with:
        query: |
          select total_private_repos
          from github.orgs.orgs
          where org = 'stackql'"
      env: 
        STACKQL_GITHUB_USERNAME: ${{  secrets.STACKQL_GITHUB_USERNAME }}
        STACKQL_GITHUB_PASSWORD: ${{  secrets.STACKQL_GITHUB_PASSWORD }}

Query file example using an inline jsonnet variable block and external variables

google-example.iql

<<<jsonnet
local project = std.extVar("GOOGLE_PROJECT");
local zone = std.extVar("GOOGLE_ZONE");
{
   project: project,
   zone: zone,
}
>>>
SELECT status, count(*) as num_instances
FROM google.compute.instances
WHERE project = '{{ .project }}' and zone = '{{ .zone }}'
GROUP BY status;

workflow excerpt:

    - name: exec google example with query file using vars
      id: stackql-exec-file-with-vars
      uses: ./
      with:
        query_file_path: './stackql_scripts/google-example.iql'
        vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
      env: 
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
        GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
        GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}

Query file example using an external jsonnet data file and external variables

google-example.iql

SELECT status, count(*) as num_instances
FROM google.compute.instances
WHERE project = '{{ .project }}' and zone = '{{ .zone }}'
GROUP BY status;

google-example.jsonnet

local project = std.extVar("GOOGLE_PROJECT");
local zone = std.extVar("GOOGLE_ZONE");
{
   project: project,
   zone: zone,
}

workflow excerpt:

    - name: exec google example with query file and data file using vars
      id: stackql-exec-file-with-data-file-and-vars
      uses: ./
      with:
        query_file_path: './stackql_scripts/google-example.iql'
        data_file_path: './stackql_scripts/google-example.jsonnet'
        vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
      env: 
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
        GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
        GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}        

Test action locally

To run unit tests locally against this action, use the following:

npm i
npm run test lib/tests/utils.test.js

About

Github Action as a wrapper for executing a single command in stackql, maps all stackql exec args to actions args

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •