Skip to content

Commit

Permalink
Use a self hosted runner to executre the job
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Nov 11, 2024
1 parent db5edb7 commit 5f6dc85
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 12 deletions.
68 changes: 62 additions & 6 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ on:
type: string
default: "Sheet1"
jobs:
check:
run:
env:
SHARED_SECRET: abc123
runs-on: ubuntu-latest
runs-on: self-hosted
permissions:
contents: read
id-token: write
Expand All @@ -37,7 +37,9 @@ jobs:
run: go build -o fabricator

- name: run
run: nohup ./fabricator -server=1 &
run: |
nohup ./fabricator -server=1 &
echo $! > fabricator_pid.txt
- id: 'auth'
name: 'Authenticate to Google Cloud'
Expand All @@ -51,9 +53,63 @@ jobs:

- name: download sheet
run: |-
./scripts/download.sh "${{ github.event.inputs.url }}" "${{ github.event.inputs.range }}" "${{ steps.auth.outputs.access_token }}"
curl -v \
./scripts/download.sh
STATUS=$(curl -v \
-w '%{http_code}' \
-H "X-Secret: $SHARED_SECRET" \
-XPOST \
--upload-file csv.json \
http://localhost:8080/workbench/check
http://localhost:8080/workbench/check)
if [ ${STATUS} -gt 299 ]; then
echo "Check my work failed"
exit 1
fi
env:
URL: ${{ github.event.inputs.url }}
RANGE: ${{ github.event.inputs.range }}
ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}

- name: run
run: ./fabricator --source source.csv --target target.csv

- name: Checkout workbench
uses: actions/checkout@v4
with:
repository: lehigh-university-libraries/islandora_workbench
ref: simple-field-json
path: islandora_workbench

- name: execute
working-directory: islandora_workbench
env:
ISLANDORA_WORKBENCH_PASSWORD: ${{ secrets.ISLANDORA_WORKBENCH_PASSWORD }}
run: |-
mkdir logs
mv ../workbench-configs configs
mv ../*.csv input_data/
if [ -f source.agents.csv ]; then
python3 workbench --config configs/terms.yml
fi
python3 workbench --config configs/create.yml
- name: Get Job ID from GH API
id: get-job-id
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
jobs=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs)
job_id=$(echo $jobs | jq -r '.jobs[] | select(.runner_name=="${{ runner.name }}") | .id')
echo "job_id=$job_id" >> $GITHUB_OUTPUT
- name: Notify Slack after job runs
run: |-
curl -s -o /dev/null -XPOST $SLACK_WEBHOOK_URL -d '{
"text": ":islandora: :hammer_and_wrench: Workbench job complete ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.get-job-id.outputs.job_id }}#step:11:1",
}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Terminate Fabricator process
if: always()
run: |
kill $(cat fabricator_pid.txt)
18 changes: 12 additions & 6 deletions scripts/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
set -eou pipefail

# extract sheet ID from https://docs.google.com/spreadsheets/d/foo/edit?gid=0#gid=0
SHEET_ID=$(echo "$1" | sed -n 's|.*/d/\(.*\)/.*|\1|p')
RANGE=$2
ACCESS_TOKEN=$3
SHEET_ID=$(echo "$URL" | sed -n 's|.*/d/\(.*\)/.*|\1|p')

# Fetch data from the Google Sheet
response=$(curl -s \
"https://sheets.googleapis.com/v4/spreadsheets/$SHEET_ID/values/$RANGE" \
-H "Authorization: Bearer $ACCESS_TOKEN")

json_data=$(echo "$response" | jq -r '.values | map(map(tostring))')
echo "$json_data" > csv.json
echo $response > ok.txt

if echo "$response" | jq -e .values >/dev/null; then
# save as a CSV
echo "$response" | jq .values | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' | tail -n +2 > source.csv
# and also as JSON in a format check my work expects
echo "$response" | jq -r '.values | map(map(tostring))' > csv.json
else
echo "Failed to fetch data: $(echo "$response" | jq -r '.error.message')"
exit 1
fi
6 changes: 6 additions & 0 deletions workbench-configs/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
task: create
host: https://preserve.lehigh.edu
username: workbench
allow_adding_terms: true
input_csv: target.csv
log_file_path: logs/items.log
6 changes: 6 additions & 0 deletions workbench-configs/terms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
task: create_terms
host: https://preserve.lehigh.edu
username: workbench
vocab_id: person
input_csv: source.agents.csv
log_file_path: logs/agents.log

0 comments on commit 5f6dc85

Please sign in to comment.