Skip to content

Commit b29e0cb

Browse files
authored
Merge pull request #16 from stackql/feature/updates
updated command behavior
2 parents f425427 + 63d7bf9 commit b29e0cb

File tree

8 files changed

+758
-542
lines changed

8 files changed

+758
-542
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Build and Test'
1+
name: 'npm test'
22
on:
33
pull_request:
44

@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4.1.3
1111
- name: Use Node.js 16
12-
uses: actions/setup-node@v3
12+
uses: actions/setup-node@v4.0.2
1313
with:
1414
node-version: 16.x
1515
- run: npm ci
1616
- run: npm test
17-
17+
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: 'stackql query tests'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
jobs:
9+
stackql-exec-google-example:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, windows-latest, macos-latest]
13+
runs-on: ${{matrix.os}}
14+
name: 'StackQL exec Google '
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/[email protected]
19+
20+
#
21+
# run a query that does not return data (using the `is_command` input)
22+
#
23+
- name: pull providers
24+
id: stackql-command
25+
uses: ./
26+
with:
27+
is_command: true
28+
query: "REGISTRY PULL github;
29+
REGISTRY PULL google;"
30+
31+
#
32+
# run a query using the `query` input
33+
#
34+
- name: github query example using the query input
35+
id: stackql-query
36+
uses: ./
37+
with:
38+
query: |
39+
select visibility, count(*) as number_of_repos
40+
from github.repos.repos
41+
where org = 'stackql'
42+
group by visibility
43+
env:
44+
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
45+
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
46+
47+
# `csv` output
48+
- name: github query example using the query input (csv output)
49+
id: stackql-query-csv-output
50+
uses: ./
51+
with:
52+
query_output: csv
53+
query: |
54+
select visibility, count(*) as number_of_repos
55+
from github.repos.repos
56+
where org = 'stackql'
57+
group by visibility
58+
env:
59+
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
60+
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
61+
62+
# `table` output
63+
- name: github query example using the query input (table output)
64+
id: stackql-query-table-output
65+
uses: ./
66+
with:
67+
query_output: table
68+
query: |
69+
select visibility, count(*) as number_of_repos
70+
from github.repos.repos
71+
where org = 'stackql'
72+
group by visibility
73+
env:
74+
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
75+
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
76+
77+
# `text` output
78+
- name: github query example using the query input (text output)
79+
id: stackql-query-text-output
80+
uses: ./
81+
with:
82+
query_output: text
83+
query: |
84+
select visibility, count(*) as number_of_repos
85+
from github.repos.repos
86+
where org = 'stackql'
87+
group by visibility
88+
env:
89+
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
90+
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
91+
92+
#
93+
# run a query using the `query_file_path` input
94+
#
95+
- name: google query example with query file
96+
id: stackql-query-file
97+
uses: ./
98+
with:
99+
query_file_path: './stackql_scripts/google-instances-by-status.iql'
100+
env:
101+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
102+
103+
#
104+
# run a query using the `query_file_path` and `vars` inputs
105+
#
106+
- name: google query example with query file using vars
107+
id: stackql-query-file-with-vars
108+
uses: ./
109+
with:
110+
query_file_path: './stackql_scripts/google-instances-by-status-with-inline-jsonnet-block.iql'
111+
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
112+
env:
113+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
114+
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
115+
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
116+
117+
#
118+
# run a query using the `query_file_path`, `data_file_path` and `vars` inputs
119+
#
120+
- name: google query example with query file and data file using vars
121+
id: stackql-query-file-with-data-file-and-vars
122+
uses: ./
123+
with:
124+
query_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.iql'
125+
data_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.jsonnet'
126+
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
127+
env:
128+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
129+
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
130+
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
131+
132+
- name: validate stackql outputs
133+
shell: bash
134+
run: |
135+
echo "stackql-command:"
136+
echo "${{ steps.stackql-command.outputs.stackql-command-output }}"
137+
138+
echo "stackql-query:"
139+
echo "${{ steps.stackql-query.outputs.stackql-query-results }}"
140+
141+
echo "stackql-query-csv-output:"
142+
echo "${{ steps.stackql-query-csv-output.outputs.stackql-query-results }}"
143+
144+
echo "stackql-query-table-output:"
145+
echo "${{ steps.stackql-query-table-output.outputs.stackql-query-results }}"
146+
147+
echo "stackql-query-text-output:"
148+
echo "${{ steps.stackql-query-text-output.outputs.stackql-query-results }}"
149+
150+
echo "stackql-query-file:"
151+
echo "${{ steps.stackql-query-file.outputs.stackql-query-results }}"
152+
153+
echo "stackql-query-file-with-vars:"
154+
echo "${{ steps.stackql-query-file-with-vars.outputs.stackql-query-results }}"
155+
156+
echo "stackql-query-file-with-data-file-and-vars:"
157+
echo "${{ steps.stackql-query-file-with-data-file-and-vars.outputs.stackql-query-results }}"

.github/workflows/stackql-exec.yml

Lines changed: 0 additions & 106 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Authentication to StackQL providers is done via environment variables source fro
1111
- `query_file_path` - stackql query file to execute **(need to supply either `query` or `query_file_path`)**
1212
- `data_file_path` - (optional) path to data file to pass to the stackql query preprocessor (`json` or `jsonnet`)
1313
- `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
14-
- `query_output` - (optional) output format of the stackql exec result, accepts `table`, `csv`, `json`, defaults to `json`
14+
- `query_output` - (optional) output format of the stackql exec result, accepts `table`, `csv`, `json` and `text`, defaults to `json`
1515
- `auth_obj_path` - (optional) the path of json file that stores stackql AUTH string **(only required when using non-standard environment variable names)**
1616
- `auth_str` - (optional) stackql AUTH string **(only required when using non-standard environment variable names)**
17-
17+
- `is_command` - (optional defaults to 'false') set to true if the stackql execution is a command that does not return data
1818

1919
## Outputs
2020
This action uses [setup-stackql](https://github.com/marketplace/actions/stackql-studio-setup-stackql), with use_wrapper set
@@ -27,15 +27,29 @@ to `true`, `stdout` and `stderr` are set to `exec-result` and `exec-error`
2727

2828
### Inline `stackql` query example
2929

30+
this is an example of a command (that does not return data):
31+
3032
```yaml
3133
- name: exec github example
3234
uses: ./
3335
with:
36+
is_command: 'true'
3437
query: "REGISTRY PULL github;
35-
SHOW PROVIDERS;
36-
select total_private_repos
37-
from github.orgs.orgs
38-
where org = 'stackql';"
38+
env:
39+
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
40+
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
41+
```
42+
43+
this is an example of a query that returns data:
44+
45+
```yaml
46+
- name: exec github example
47+
uses: ./
48+
with:
49+
query: |
50+
select total_private_repos
51+
from github.orgs.orgs
52+
where org = 'stackql'"
3953
env:
4054
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
4155
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}

0 commit comments

Comments
 (0)