-
Notifications
You must be signed in to change notification settings - Fork 3
98 lines (79 loc) · 3.64 KB
/
scheduler.yml
File metadata and controls
98 lines (79 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Rebuild Check
on:
schedule:
# Run daily at midnight JST (3pm UTC)
- cron: "0 15 * * *"
workflow_dispatch:
jobs:
check-and-trigger:
name: Check for updates and trigger build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for content updates or event end
id: check-updates
run: |
UPSTREAM_REPO="oktechjp/public"
# Read current values from meta.json
CURRENT_COMMIT=$(jq -r '.commitHash' meta.json)
CURRENT_CONTENT_HASH=$(jq -r '.contentHash // ""' meta.json)
NEXT_EVENT_ENDS=$(jq -r '.nextEventEnds' meta.json)
echo "Current commit: $CURRENT_COMMIT"
echo "Current content hash: $CURRENT_CONTENT_HASH"
echo "Next event ends: $NEXT_EVENT_ENDS"
# Get latest commit from upstream main branch
LATEST_COMMIT=$(curl -s "https://api.github.com/repos/$UPSTREAM_REPO/commits/main" | jq -r '.sha')
echo "Latest upstream commit: $LATEST_COMMIT"
# Initialize NEEDS_BUILD flag
NEEDS_BUILD=false
# First check if an event has ended (this always needs checking)
if [ "$NEXT_EVENT_ENDS" != "null" ] && [ "$NEXT_EVENT_ENDS" != "" ]; then
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
if [[ "$CURRENT_TIME" > "$NEXT_EVENT_ENDS" ]]; then
echo "Event has ended, triggering rebuild to update event status"
NEEDS_BUILD=true
fi
fi
# Early exit if commits are the same and no event ended
if [ "$CURRENT_COMMIT" = "$LATEST_COMMIT" ] && [ "$NEEDS_BUILD" = false ]; then
echo "Commits are identical and no event has ended. No updates needed."
echo "NEEDS_BUILD=false" >> $GITHUB_ENV
exit 0
fi
# Only fetch content if commits are different
if [ "$CURRENT_COMMIT" != "$LATEST_COMMIT" ]; then
echo "Commit has changed, fetching content to check for actual changes..."
# Fetch and hash the content from latest commit
EVENTS_URL="https://raw.githubusercontent.com/$UPSTREAM_REPO/$LATEST_COMMIT/events.json"
PHOTOS_URL="https://raw.githubusercontent.com/$UPSTREAM_REPO/$LATEST_COMMIT/photos.json"
echo "Fetching events.json and photos.json from latest commit..."
# Download both files and compute combined hash
EVENTS_CONTENT=$(curl -sL "$EVENTS_URL")
PHOTOS_CONTENT=$(curl -sL "$PHOTOS_URL")
# Compute hash of combined content
COMBINED_CONTENT="${EVENTS_CONTENT}${PHOTOS_CONTENT}"
NEW_CONTENT_HASH=$(echo -n "$COMBINED_CONTENT" | sha256sum | cut -d' ' -f1)
echo "New content hash: $NEW_CONTENT_HASH"
# Check for content changes (via hash)
if [ "$CURRENT_CONTENT_HASH" != "$NEW_CONTENT_HASH" ]; then
echo "Content has changed (hash mismatch)!"
NEEDS_BUILD=true
else
echo "Commit changed but content is identical (hash match)"
fi
fi
echo "NEEDS_BUILD=$NEEDS_BUILD" >> $GITHUB_ENV
- name: Trigger import workflow
if: env.NEEDS_BUILD == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'import.yml',
ref: 'main'
})
console.log('Import workflow triggered successfully')