info
stackql
is a dev tool that allows you to query and manage cloud and SaaS resources using SQL, which developers and analysts can use for CSPM, assurance, user access management reporting, IaC, XOps and more.
For more background on using StackQL with GitHub Actions see StackQL GitHub Actions Tutorial
- name: setup StackQL
uses: stackql/setup-stackql@v1.1.0
with:
use_wrapper: true
- name: get changed files
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
shell: bash
run: |
ORG=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f1)
REPO=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f2)
QUERY="select filename FROM github.repos.commit_files where owner = '${ORG}' and ref = '${GITHUB_SHA}' and repo = '${REPO}'"
echo "pulling github provider"
stackql exec "REGISTRY PULL github"
echo "running query: ${QUERY}"
stackql --output json -f changed_files.txt exec "${QUERY}"
changed_files.txt
looks like this...
[{"filename":"src/app.ts"},{"filename":"src/mod.ts"},...]
You could then do something with the changed files in a further step like:
- name: Do something with changed files
run: |
while IFS="" read -r filename || [ -n "$filename" ]
do
echo "processing ${filename}..."
#
# do something interesting here...
#
done < <(jq -r '.[] | .filename' changed_files.txt)
The github.repos.commit_files
StackQL resource has other interesting fields which could be projected and used for actioning or reporting, these can be seen using:
DESCRIBE EXTENDED github.repos.commit_files;
Fields available in this resource include:
status
- one ofadded
,removed
,modified
,renamed
,copied
,changed
orunchanged
filename
- filename which has changedprevious_filename
- previous filename if the filename had changed in the commitadditions
- the number of additions in each filechanges
- the number of changes to each filedeletions
- the number of deletions in each filepatch
-git diff
output for each fileblob_url
- the blob url for the fileraw_url
- the raw url for the filecontents_url
- the contents url for the filesha
- The sha for each individual file