-
Notifications
You must be signed in to change notification settings - Fork 1
183 lines (160 loc) · 5.41 KB
/
update.yml
File metadata and controls
183 lines (160 loc) · 5.41 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Update Plugin Index
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
inputs:
mode:
description: 'Run mode'
required: false
default: 'auto'
type: choice
options:
- auto
- update
- discover
force:
description: 'Force full scan (ignore last_sync)'
required: false
default: false
type: boolean
concurrency:
group: sync-index
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: AllayMC
repositories: AllayHubIndex
- name: Checkout AllayHubIndex
uses: actions/checkout@v6
with:
repository: AllayMC/AllayHubIndex
path: AllayHubIndex
token: ${{ steps.app-token.outputs.token }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Cache Bun dependencies
uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Download indexer
run: |
curl -sL https://github.com/${{ github.repository }}/releases/download/indexer-latest/allayindexer -o allayindexer
chmod +x allayindexer
- name: Install dependencies
run: bun install
- name: Get current date
id: date
run: echo "today=$(date -u +%Y-%m-%d)" >> $GITHUB_OUTPUT
- name: Restore update progress
uses: actions/cache/restore@v4
with:
path: .update_progress
key: update-progress-${{ steps.date.outputs.today }}-${{ github.run_id }}
restore-keys: |
update-progress-${{ steps.date.outputs.today }}-
- name: Restore last sync
uses: actions/cache/restore@v4
with:
path: .last_sync
key: last-sync-${{ github.run_id }}
restore-keys: |
last-sync-
- name: Restore data cache
uses: actions/cache/restore@v4
with:
path: .data_cache.bin.gz
key: data-cache-${{ github.run_id }}
restore-keys: |
data-cache-
- name: Determine run mode
id: mode
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.mode }}" != "auto" ]; then
echo "mode=${{ inputs.mode }}" >> $GITHUB_OUTPUT
else
TODAY=$(date -u +%Y-%m-%d)
if [ -f .last_sync ] && grep -q "$TODAY" .last_sync; then
echo "mode=update" >> $GITHUB_OUTPUT
else
echo "mode=discover" >> $GITHUB_OUTPUT
fi
fi
echo "Running in mode: $(cat $GITHUB_OUTPUT | grep mode | cut -d= -f2)"
- name: Write GitHub App private key
env:
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
run: echo "$APP_PRIVATE_KEY" > /tmp/app-private-key.pem
- name: Run update
if: steps.mode.outputs.mode == 'update'
run: |
./allayindexer update \
--app-id ${{ vars.APP_ID }} \
--installation-id ${{ vars.APP_INSTALLATION_ID }} \
--private-key-file /tmp/app-private-key.pem \
--debug
- name: Run discover
if: steps.mode.outputs.mode == 'discover'
run: |
FORCE_FLAG=""
if [ "${{ inputs.force }}" = "true" ]; then
FORCE_FLAG="--force"
fi
./allayindexer discover $FORCE_FLAG \
--app-id ${{ vars.APP_ID }} \
--installation-id ${{ vars.APP_INSTALLATION_ID }} \
--private-key-file /tmp/app-private-key.pem \
--debug
- name: Cleanup private key
if: always()
run: rm -f /tmp/app-private-key.pem
- name: Save update progress
if: always() && hashFiles('.update_progress') != ''
uses: actions/cache/save@v4
with:
path: .update_progress
key: update-progress-${{ steps.date.outputs.today }}-${{ github.run_id }}
- name: Save last sync
if: always() && hashFiles('.last_sync') != ''
uses: actions/cache/save@v4
with:
path: .last_sync
key: last-sync-${{ github.run_id }}
- name: Save data cache
if: always() && hashFiles('.data_cache.bin.gz') != ''
uses: actions/cache/save@v4
with:
path: .data_cache.bin.gz
key: data-cache-${{ github.run_id }}
- name: Check for changes
id: changes
run: |
cd AllayHubIndex
git add -A
if git diff --staged --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected, skipping commit and push"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected"
fi
- name: Commit and push changes
if: steps.changes.outputs.has_changes == 'true'
run: |
cd AllayHubIndex
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: sync plugin index"
git push