Skip to content

Commit

Permalink
Merge pull request #16 from stackql/feature/updates
Browse files Browse the repository at this point in the history
updated command behavior
  • Loading branch information
jeffreyaven authored Apr 26, 2024
2 parents f425427 + 63d7bf9 commit b29e0cb
Show file tree
Hide file tree
Showing 8 changed files with 758 additions and 542 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml → .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Build and Test'
name: 'npm test'
on:
pull_request:

Expand All @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.3
- name: Use Node.js 16
uses: actions/setup-node@v3
uses: actions/setup-node@v4.0.2
with:
node-version: 16.x
- run: npm ci
- run: npm test

157 changes: 157 additions & 0 deletions .github/workflows/stackql-exec-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: 'stackql query tests'

on:
push:
branches:
- main
pull_request:
jobs:
stackql-exec-google-example:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{matrix.os}}
name: 'StackQL exec Google '

steps:
- name: Checkout
uses: actions/[email protected]

#
# run a query that does not return data (using the `is_command` input)
#
- name: pull providers
id: stackql-command
uses: ./
with:
is_command: true
query: "REGISTRY PULL github;
REGISTRY PULL google;"

#
# run a query using the `query` input
#
- name: github query example using the query input
id: stackql-query
uses: ./
with:
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}

# `csv` output
- name: github query example using the query input (csv output)
id: stackql-query-csv-output
uses: ./
with:
query_output: csv
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}

# `table` output
- name: github query example using the query input (table output)
id: stackql-query-table-output
uses: ./
with:
query_output: table
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}

# `text` output
- name: github query example using the query input (text output)
id: stackql-query-text-output
uses: ./
with:
query_output: text
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}

#
# run a query using the `query_file_path` input
#
- name: google query example with query file
id: stackql-query-file
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status.iql'
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

#
# run a query using the `query_file_path` and `vars` inputs
#
- name: google query example with query file using vars
id: stackql-query-file-with-vars
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status-with-inline-jsonnet-block.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 }}

#
# run a query using the `query_file_path`, `data_file_path` and `vars` inputs
#
- name: google query example with query file and data file using vars
id: stackql-query-file-with-data-file-and-vars
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.iql'
data_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.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 }}

- name: validate stackql outputs
shell: bash
run: |
echo "stackql-command:"
echo "${{ steps.stackql-command.outputs.stackql-command-output }}"
echo "stackql-query:"
echo "${{ steps.stackql-query.outputs.stackql-query-results }}"
echo "stackql-query-csv-output:"
echo "${{ steps.stackql-query-csv-output.outputs.stackql-query-results }}"
echo "stackql-query-table-output:"
echo "${{ steps.stackql-query-table-output.outputs.stackql-query-results }}"
echo "stackql-query-text-output:"
echo "${{ steps.stackql-query-text-output.outputs.stackql-query-results }}"
echo "stackql-query-file:"
echo "${{ steps.stackql-query-file.outputs.stackql-query-results }}"
echo "stackql-query-file-with-vars:"
echo "${{ steps.stackql-query-file-with-vars.outputs.stackql-query-results }}"
echo "stackql-query-file-with-data-file-and-vars:"
echo "${{ steps.stackql-query-file-with-data-file-and-vars.outputs.stackql-query-results }}"
106 changes: 0 additions & 106 deletions .github/workflows/stackql-exec.yml

This file was deleted.

26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Authentication to StackQL providers is done via environment variables source fro
- `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`, defaults to `json`
- `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](https://github.com/marketplace/actions/stackql-studio-setup-stackql), with use_wrapper set
Expand All @@ -27,15 +27,29 @@ to `true`, `stdout` and `stderr` are set to `exec-result` and `exec-error`

### Inline `stackql` query example

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

```yaml
- name: exec github example
uses: ./
with:
is_command: 'true'
query: "REGISTRY PULL github;
SHOW PROVIDERS;
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 }}
```
this is an example of a query that returns data:
```yaml
- 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 }}
Expand Down
Loading

0 comments on commit b29e0cb

Please sign in to comment.