Skip to content

Commit 47b117d

Browse files
Merge pull request #1 from stackql/init-project
Init project
2 parents a6be705 + 732c9db commit 47b117d

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed

.github/workflows/stackql-exec.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 'Setup StackQL'
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/checkout@v3
19+
20+
- name: Prep Google Creds (Windows)
21+
if: ${{ matrix.os == 'windows-latest'}}
22+
run: | ## use the secret to create json file
23+
$GoogleCreds = [System.Environment]::GetEnvironmentVariable("GOOGLE_CREDS_ENV")
24+
$GoogleCredsDecoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($GoogleCreds))
25+
Write-Output $GoogleCredsDecoded | Set-Content sa-key.json
26+
shell: pwsh
27+
env:
28+
GOOGLE_CREDS_ENV: ${{ secrets.GOOGLE_CREDS }}
29+
30+
- name: Prep Google Creds (bash)
31+
if: ${{ matrix.os != 'windows-latest' }}
32+
shell: bash
33+
run: | ## use the base64 encoded secret to create json file
34+
sudo echo ${{ secrets.GOOGLE_CREDS }} | base64 -d > sa-key.json
35+
36+
- name: exec google example
37+
uses: ./
38+
with:
39+
auth_obj_path: './stackql_scripts/auth.json'
40+
query_file_path: './stackql_scripts/google-example.iql'
41+
42+
stackql-exec-github-example:
43+
strategy:
44+
matrix:
45+
os: [ubuntu-latest, windows-latest, macos-latest]
46+
runs-on: ${{matrix.os}}
47+
name: 'StackQL exec Github '
48+
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
53+
- name: exec github example
54+
uses: ./
55+
with:
56+
auth_str: '{ "github": { "type": "basic", "credentialsenvvar": "STACKQL_GITHUB_CREDS" } }'
57+
query: "REGISTRY PULL github v23.01.00104;
58+
SHOW PROVIDERS;
59+
select total_private_repos
60+
from github.orgs.orgs
61+
where org = 'stackql';"
62+
env:
63+
STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }}
64+

action.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: 'StackQL Studios - stackql-exec'
2+
description: 'A wrapper for executing a single command, maps all stackql exec args to actions args (supplied using with.'
3+
author: 'Yuncheng Yang, StackQL Studios'
4+
inputs:
5+
auth_obj_path:
6+
description: file path to json object of stackql auth
7+
required: false
8+
auth_str:
9+
description: json string of stackql auth
10+
required: false
11+
query:
12+
description: stackql query to be executed
13+
required: false
14+
query_file_path:
15+
description: stackql query file to be executed
16+
required: false
17+
query_output:
18+
description: output format
19+
default: 'json'
20+
required: false
21+
22+
runs:
23+
using: "composite"
24+
steps:
25+
- name: Setup StackQL
26+
uses: stackql/[email protected]
27+
with:
28+
use_wrapper: true
29+
30+
- name: Setup auth
31+
id: setup-auth
32+
shell: bash
33+
run: |
34+
chmod +x ./action_scripts/set_auth_env.sh
35+
./action_scripts/set_auth_env.sh
36+
env:
37+
AUTH_FILE: ${{inputs.auth_obj_path}}
38+
AUTH_STR: ${{inputs.auth_str}}
39+
40+
- name: Execute query
41+
shell: bash
42+
run: |
43+
chmod +x ./action_scripts/execute.sh
44+
./action_scripts/execute.sh
45+
env:
46+
QUERY_FILE_PATH: ${{ inputs.query_file_path }}
47+
QUERY: ${{inputs.query}}
48+
OUTPUT: ${{inputs.query_output}}
49+
50+
51+
branding:
52+
icon: 'terminal'
53+
color: 'green'

action_scripts/execute.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ -z "$AUTH" ]; then
6+
echo "ERROR: AUTH must be set."
7+
exit 1
8+
fi
9+
10+
if [ -z "$QUERY_FILE_PATH" ]; then
11+
stackql exec "$QUERY" --auth="${AUTH}" --output="${OUTPUT}"
12+
else
13+
stackql exec -i "$QUERY_FILE_PATH" --auth="${AUTH}" --output="${OUTPUT}"
14+
fi

action_scripts/set_auth_env.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
FILE_NAME=${AUTH_FILE}
6+
7+
if [ -z "$FILE_NAME" ]; then
8+
AUTH=${AUTH_STR}
9+
10+
if [ -z "$AUTH_STR" ]; then
11+
echo "ERROR: Either AUTH_FILE_NAME or AUTH_STR must be set."
12+
exit 1
13+
fi
14+
else
15+
# Read the JSON file into a string
16+
AUTH=$(cat "$FILE_NAME")
17+
fi
18+
19+
# Set the AUTH environment variable
20+
echo "Setting AUTH environment variable..."
21+
echo "AUTH=$AUTH" >> "$GITHUB_ENV"

stackql_scripts/auth.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" },"github": { "type": "basic", "credentialsenvvar": "STACKQL_GITHUB_CREDS" }}

stackql_scripts/github-example.iql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
REGISTRY PULL github v23.01.00104;
2+
SHOW PROVIDERS;
3+
select total_private_repos
4+
from github.orgs.orgs
5+
where org = 'stackql';

stackql_scripts/google-example.iql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REGISTRY PULL google v23.01.00116;
2+
SELECT name, status
3+
FROM google.compute.instances
4+
WHERE project = 'stackql-demo' AND zone = 'australia-southeast1-a';

0 commit comments

Comments
 (0)