Ingest: Task Runner #5625
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: 'Ingest: Task Runner' | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
types: [opened, synchronize] | |
schedule: | |
# - cron: '0 * * * *' # Runs every hour, adjust to your needs | |
- cron: '*/15 * * * *' # Run every 15 minutes | |
# - cron: '30 * * * *' # Run every hour on the half-hour | |
# - cron: '0 */6 * * *' # Runs every 6 hours | |
workflow_dispatch: # Allows manual trigger from the GitHub UI | |
env: | |
INGEST_TOKEN: ${{ secrets.INGEST_TOKEN }} | |
jobs: | |
define_tasks: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set_matrix.outputs.matrix }} | |
steps: | |
- name: Set Dynamic Matrix | |
id: set_matrix | |
run: | | |
tasks=("update_posts" "update_popular_posts") | |
json_array=$(printf ',{"task":"%s"}' "${tasks[@]}") | |
matrix_stringified="{\"include\":[${json_array:1}]}" | |
echo "matrix=$matrix_stringified" >> $GITHUB_OUTPUT | |
run_tasks: | |
needs: define_tasks | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{ fromJson(needs.define_tasks.outputs.matrix) }} | |
steps: | |
- name: Run task | |
run: | | |
task="${{ matrix.task }}" | |
response=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" --request POST \ | |
--header "Content-Type: application/json" \ | |
--data "{\"task\":\"$task\",\"token\":\"${{ env.INGEST_TOKEN }}\"}" \ | |
https://scottspence.com/api/ingest) | |
body=$(echo $response | sed -e 's/HTTPSTATUS\:.*//g') | |
status=$(echo $response | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') | |
if [ $status -eq 200 ]; then | |
echo "Response from $task task: $body" | |
echo "$task task was successful" | |
else | |
echo "Response from $task task: $body" | |
echo "$task task failed with status $status" | |
exit 1 | |
fi |