Skip to content

Commit

Permalink
Add node IDs to insert spreadsheet (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Dec 4, 2024
1 parent a2d40f0 commit d14078b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
create_credentials_file: true
service_account: ${{ secrets.WORKBENCH_GSA }}
token_format: 'access_token'
access_token_scopes: "https://www.googleapis.com/auth/spreadsheets.readonly"
access_token_scopes: "https://www.googleapis.com/auth/spreadsheets"

- name: Get Job ID from GH API
id: get-job-id
Expand Down Expand Up @@ -95,11 +95,11 @@ jobs:
env:
ISLANDORA_WORKBENCH_PASSWORD: ${{ secrets.ISLANDORA_WORKBENCH_PASSWORD }}

- name: Attach rollback
uses: actions/upload-artifact@v4
with:
name: rollback.csv
path: islandora_workbench/input_data/rollback.csv
- name: add node IDs to sheet
run: ./scripts/insert-nids.sh
env:
URL: ${{ github.event.inputs.url }}
ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}

- name: Notify Slack on Success
if: ${{ success() }}
Expand Down
35 changes: 35 additions & 0 deletions scripts/insert-nids.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -eou pipefail

if [ ! -f islandora_workbench/input_data/rollback.csv ]; then
echo "rollback.csv does not exist"
exit 0
fi

regex='^(https:\/\/docs\.google\.com\/spreadsheets\/d\/[a-zA-Z0-9_-]+)'
if [[ "$URL" =~ $regex ]]; then
URL="${BASH_REMATCH[1]}"
else
echo "Invalid URL"
exit 1
fi

# extract sheet ID from https://docs.google.com/spreadsheets/d/foo/edit?gid=0#gid=0
SHEET_ID=$(echo "$URL" | sed -n 's|.*/d/\(.*\)|\1|p')
API_URL="https://sheets.googleapis.com/v4/spreadsheets/$SHEET_ID/values/Sheet1!D2:append"
PAYLOAD=$(tail +4 islandora_workbench/input_data/rollback.csv | jq -R 'tonumber? | [if . == null then empty else . end]' | jq -s '{"values": [.[] | . ]}')

STATUS=$(curl -s -X POST \
-o /tmp/gsup.log \
-w '%{http_code}' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data @<(echo "$PAYLOAD") \
"$API_URL?valueInputOption=RAW")

if [ "${STATUS}" != 200 ]; then
echo "Failed to update spreadsheet with node IDs"
cat /tmp/gsup.log
exit 1
fi

0 comments on commit d14078b

Please sign in to comment.