-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Try adding metadata read github action * temporary run on pull request to create 1st run * create empty metadata.json file, cat the spreadsheet output * switch back to the same branch as normal csv upload * jq to process metadata spreadsheet output * remove pull request workflow activation
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Update GoogleSheet MetaData | ||
on: | ||
# Allows workflow to be manually run in Github UI | ||
workflow_dispatch: | ||
# Allows workflow to be called via HTTP calls to GitHub (with correct auth, etc) | ||
repository_dispatch: | ||
types: [update-googlesheet-data] | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
create-or-update-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout latest code from main branch | ||
uses: actions/checkout@v4 | ||
# Currently using a fork of https://github.com/jroehl/gsheet.action/ which adds | ||
# the ability to output to file rather than using the standard GitHub Action | ||
# output to an ENV. Outputting to ENV doesn't work when downloading large volumes | ||
# of data. If/when this PR is merged we can go back to using the original repo: | ||
# https://github.com/jroehl/gsheet.action/pull/615 | ||
- uses: asibs/gsheet.action.asibs@release | ||
name: Download latest data from Google Sheets | ||
id: download_gsheets_data | ||
env: | ||
GSHEET_CLIENT_EMAIL: ${{ secrets.GSHEET_CLIENT_EMAIL }} | ||
GSHEET_PRIVATE_KEY: ${{ secrets.GSHEET_PRIVATE_KEY }} | ||
with: | ||
spreadsheetId: ${{ vars.GSHEET_SPREADSHEET_ID }} | ||
commands: | | ||
[ | ||
{ | ||
"command": "getData", | ||
"args": { | ||
"range": "'Metadata - EXPORT'!A:C", | ||
"hasHeaderRow": true | ||
} | ||
} | ||
] | ||
outputFile: /tmp/gsheet_action_results.json | ||
- name: Output full results | ||
run: | | ||
cat /tmp/gsheet_action_results.json | ||
- name: Write internal json metadata json | ||
run: | | ||
jq '.results[0].result.formatted | group_by( .source_type)[] | {(.[0].source_type): [.[] | { "description" : .description, "url" : .url } ]}' /tmp/gsheet_action_results.json > /tmp/jq_interim.json | ||
jq -s 'reduce .[] as $item (null; . + $item)' /tmp/jq_interim.json > data/metadata.json | ||
# Add the updates to git | ||
git add data/metadata.json | ||
- name: Commit Changes and Create Pull Request | ||
uses: peter-evans/[email protected] | ||
with: | ||
# Note: Need to use a Personal Access Token here, NOT the standard | ||
# secrets.GITHUB_TOKEN - if we use the standard Github Actions GITHUB_TOKEN | ||
# then the commit/push/etc won't trigger subsequent Github Actions (such as | ||
# the lint-pr action, which is required to merge PRs). The Personal Access | ||
# Token must be setup as an Action Secret on the GitHub repo. Use the same | ||
# Personal Access Token as the GHA_TOKEN env variable in your deployed app. | ||
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | ||
base: main | ||
branch: auto/constituency-data-changes | ||
commit-message: Latest metadata data from Google Sheets | ||
committer: GitHub Action Bot - Constituency Data <[email protected]> | ||
author: GitHub Action Bot - Constituency Data <[email protected]> | ||
title: "[MetaData] Latest Google Sheets Data" | ||
body: | | ||
Automatically created by Update-Googlesheet-Data Github action | ||
labels: | | ||
automated-pr | ||
metadata-pr |