Skip to content

Commit

Permalink
Jms/metadata sheet upload (#76)
Browse files Browse the repository at this point in the history
* 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
jms301 authored Mar 19, 2024
1 parent 54ed9a8 commit a52527b
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/update-googlesheet-metadata.yaml
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

0 comments on commit a52527b

Please sign in to comment.