Google Sheets Quality Control Trigger #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Google Sheets Quality Control Trigger | |
on: | |
schedule: | |
- cron: "0 5 * * *" | |
workflow_dispatch: | |
jobs: | |
fetch-and-process-gsheet: | |
runs-on: ubuntu-latest | |
outputs: | |
qc-entry: ${{ steps.get_input.outputs.result }} | |
steps: | |
- uses: actions/github-script@v7 | |
id: "get_input" | |
env: | |
SPREADSHEET_ID: ${{ secrets.SPREADSHEET_ID }} | |
with: | |
result-encoding: string | |
script: | | |
const { SPREADSHEET_ID } = process.env; | |
const keywords = ['Date', 'Datasets', 'Keywords', 'Facets'] | |
const GID = '0'; | |
const response = await fetch(`https://docs.google.com/spreadsheets/d/${SPREADSHEET_ID}/gviz/tq?tqx=out:json&tq&gid=${GID}`); | |
const txt = await response.text(); | |
const jsonString = txt.match(/(?<="table":).*(?=}\);)/g)[0]; | |
const json = JSON.parse(jsonString); | |
let rawTable = []; | |
let tableData = []; | |
json.rows.forEach((r) => { | |
let row = []; | |
r.c.forEach((cel) => { | |
let value = ''; | |
try { | |
value = cel.f ? cel.f : cel.v; | |
} catch (e) { | |
value = ''; | |
} | |
row.push(value); | |
}); | |
rawTable.push(row); | |
}); | |
rawTable.forEach((row) => { | |
let mappedData = {}; | |
keywords.forEach((keyword, index) => { | |
mappedData[keyword] = row[index] | |
}); | |
tableData.push(mappedData); | |
}); | |
return JSON.stringify(tableData.filter((data) => { | |
return data['Date'] === new Date().toLocaleDateString('en-US') | |
}).slice(-1)[0]); | |
trigger-qc-testing-workflow: | |
runs-on: ubuntu-latest | |
needs: fetch-and-process-gsheet | |
if: fromJson(needs.fetch-and-process-gsheet.outputs.qc-entry).Date | |
env: | |
Keywords: ${{ fromJson(needs.fetch-and-process-gsheet.outputs.qc-entry).Keywords }} | |
Facets: ${{ fromJson(needs.fetch-and-process-gsheet.outputs.qc-entry).Facets }} | |
Datasets: ${{ fromJson(needs.fetch-and-process-gsheet.outputs.qc-entry).Datasets }} | |
steps: | |
- name: Print data entry | |
run: | | |
echo "${{ needs.fetch-and-process-gsheet.outputs.qc-entry }}" | |
- name: Invoke workflow with inputs | |
uses: benc-uk/workflow-dispatch@v1 | |
with: | |
workflow: quality_control_cypress.yml | |
inputs: '{ "SEARCH_KEYWORDS": "${{ env.Keywords }}", "FILTER_FACETS": "${{ env.Facets }}", "DATASET_IDS": "${{ env.Datasets }}" }' |