-
Notifications
You must be signed in to change notification settings - Fork 5
125 lines (106 loc) · 4.05 KB
/
Copy pathimport.yml
File metadata and controls
125 lines (106 loc) · 4.05 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Import and Commit Content
on:
workflow_dispatch:
workflow_call:
permissions:
contents: write
actions: write
jobs:
import-and-commit:
name: Import content and commit
runs-on: ubuntu-latest
environment:
name: github-pages
steps:
- name: Checkout
uses: actions/checkout@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: "22"
cache: "npm"
# Cache node_modules to avoid reinstalling
- name: Restore node_modules cache
id: node-modules-cache
uses: actions/cache@v6.1.0
with:
path: |
node_modules
~/.cache/puppeteer
~/.cache/ms-playwright
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Import content
run: npm run import
env:
STADIA_MAPS_API_KEY: ${{ secrets.STADIA_MAPS_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Save node_modules cache if it wasn't cached
- name: Save node_modules cache
if: steps.node-modules-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6.1.0
with:
path: |
node_modules
~/.cache/puppeteer
~/.cache/ms-playwright
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Commit content updates
id: commit
run: |
# Configure git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Get meta.json values for commit message
git show HEAD:meta.json > /tmp/old_meta.json 2>/dev/null || echo '{}' > /tmp/old_meta.json
OLD_EVENT_SLUG=$(jq -r '.nextEventSlug // ""' /tmp/old_meta.json)
NEW_COMMIT=$(jq -r '.commitHash' meta.json)
NEW_EVENT_SLUG=$(jq -r '.nextEventSlug // ""' meta.json)
echo "Old event slug: $OLD_EVENT_SLUG"
echo "New event slug: $NEW_EVENT_SLUG"
echo "New commit: $NEW_COMMIT"
# Check for content changes
CONTENT_CHANGES=$(git status --porcelain content/)
# Check if event slug changed (event ended)
EVENT_ENDED=false
if [ -n "$OLD_EVENT_SLUG" ] && [ "$OLD_EVENT_SLUG" != "$NEW_EVENT_SLUG" ]; then
EVENT_ENDED=true
fi
echo "Content changes: ${CONTENT_CHANGES:-none}"
echo "Event ended: $EVENT_ENDED"
# Only commit if actual content changed OR event ended
if [ -n "$CONTENT_CHANGES" ] || [ "$EVENT_ENDED" = true ]; then
# Stage changes
git add content/ meta.json astro.config.ts
# Determine commit message
if [ -n "$CONTENT_CHANGES" ]; then
git commit -m "Auto import content from https://github.com/oktechjp/public/commit/$NEW_COMMIT"
else
git commit -m "Auto event end rebuild: $OLD_EVENT_SLUG"
fi
git push
echo "Content updates committed and pushed"
echo "changes_committed=true" >> $GITHUB_OUTPUT
else
echo "No content changes and no event end. Skipping commit."
echo "changes_committed=false" >> $GITHUB_OUTPUT
fi
- name: Trigger build workflow
if: steps.commit.outputs.changes_committed == 'true'
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'astro.yml',
ref: 'main'
})
console.log('Build workflow triggered successfully')