Skip to content

updated command behavior #55

updated command behavior

updated command behavior #55

name: 'StackQL Exec Test'
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/checkout@v4.1.3
#
# 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: |
# Test `stackql-command`
output="${{ steps.stackql-command.outputs.stackql-command-output }}"
all_passed=true
echo "$output" | while IFS= read -r line; do
# Skip empty lines
if [[ -z "$line" ]]; then
continue
fi
# Validate against a simple keyword presence
if ! echo "$line" | grep -qi "provider" || ! echo "$line" | grep -qi "version" || ! echo "$line" | grep -qi "successfully installed"; then
echo "Failed line: $line"
all_passed=false
fi
done
if [[ "$all_passed" == "false" ]]; then
echo "One or more lines in the output failed to match the expected format."
exit 1
else
echo "All lines in the output match the expected format."
fi
# # validate github query example using the query input (stackql-query)
# if [ -z '${{ steps.stackql-query.outputs.exec-result }}' ]; then
# echo "exec-stackql output does not contain expected result"
# exit 1
# fi
# # validate google query example with query file (stackql-query-file)
# if [ -z '${{ steps.stackql-query-file.outputs.exec-result }}' ]; then
# echo "exec-stackql output does not contain expected result"
# exit 1
# fi
# # validate google query example with query file using vars (stackql-query-file-with-vars)
# if [ -z '${{ steps.stackql-query-file-with-vars.outputs.exec-result }}' ]; then
# echo "exec-stackql output does not contain expected result"
# exit 1
# fi
# # validate google query example with query file and data file using vars (stackql-query-file-with-data-file-and-vars)
# if [ -z '${{ steps.stackql-query-file-with-data-file-and-vars.outputs.exec-result }}' ]; then
# echo "exec-stackql output does not contain expected result"
# exit 1
# fi