128 lines
4.0 KiB
YAML
128 lines
4.0 KiB
YAML
name: Publish Market Index
|
|
|
|
on:
|
|
push:
|
|
branches: ['main']
|
|
paths:
|
|
- 'registry.json'
|
|
- 'withdrawn.json'
|
|
- 'scripts/**'
|
|
schedule:
|
|
- cron: '17 4 * * *'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
concurrency:
|
|
group: publish-dist
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
steps:
|
|
- name: Checkout plugins repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
|
|
- name: Check if registry has active plugins
|
|
id: reg
|
|
run: |
|
|
count=$(node -e "const r = JSON.parse(require('fs').readFileSync('registry.json','utf8')); console.log((r.plugins||[]).length)")
|
|
echo "count=$count" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Checkout Reims-Go CLI source
|
|
if: steps.reg.outputs.count != '0'
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: Nwflower/Reims-Go
|
|
ref: main
|
|
path: reims-go
|
|
|
|
- name: Setup Go from Reims-Go go.mod
|
|
if: steps.reg.outputs.count != '0'
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: reims-go/go.mod
|
|
|
|
- name: Build headless reims-go CLI
|
|
if: steps.reg.outputs.count != '0'
|
|
run: |
|
|
cd reims-go
|
|
mkdir -p cmd/reims-doctor
|
|
cat <<'EOF' > cmd/reims-doctor/main.go
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"github.com/Nwflower/reims-go/internal/cli"
|
|
)
|
|
|
|
func main() {
|
|
os.Exit(cli.Main(os.Args[1:]))
|
|
}
|
|
EOF
|
|
CGO_ENABLED=0 go build -o "$GITHUB_WORKSPACE/reims-go-cli" ./cmd/reims-doctor
|
|
|
|
- name: Build dist/index.json
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
REIMS_GO_PLATFORM: windows-x64
|
|
run: |
|
|
extra=""
|
|
if [ -x "./reims-go-cli" ]; then
|
|
extra="--reims-bin ./reims-go-cli"
|
|
fi
|
|
node scripts/build-index.mjs $extra --out-dir dist
|
|
|
|
- name: Check if dist content changed
|
|
id: diff
|
|
run: |
|
|
if git fetch --depth 1 origin dist 2>/dev/null; then
|
|
mkdir -p prev-dist
|
|
git show origin/dist:index.json > prev-dist/index.json 2>/dev/null || true
|
|
git show origin/dist:changes.json > prev-dist/changes.json 2>/dev/null || true
|
|
changed=$(node -e "
|
|
const fs = require('fs');
|
|
const norm = (p) => {
|
|
if (!fs.existsSync(p)) return '';
|
|
const obj = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
delete obj.updated_at;
|
|
return JSON.stringify(obj);
|
|
};
|
|
const same = norm('prev-dist/index.json') === norm('dist/index.json')
|
|
&& norm('prev-dist/changes.json') === norm('dist/changes.json');
|
|
console.log(same ? 'false' : 'true');
|
|
")
|
|
else
|
|
changed="true"
|
|
fi
|
|
echo "changed=$changed" >> "$GITHUB_OUTPUT"
|
|
echo "Dist content changed: $changed"
|
|
|
|
- name: Publish dist orphan branch
|
|
if: steps.diff.outputs.changed == 'true'
|
|
run: |
|
|
cd dist
|
|
git init -b dist
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git add index.json changes.json
|
|
git commit -m "chore(dist): publish market index $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
|
|
git push --force origin dist
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Purge jsDelivr CDN cache
|
|
if: steps.diff.outputs.changed == 'true'
|
|
run: |
|
|
curl -fsS "https://purge.jsdelivr.net/gh/${GITHUB_REPOSITORY}@dist/index.json" || true
|
|
curl -fsS "https://purge.jsdelivr.net/gh/${GITHUB_REPOSITORY}@dist/changes.json" || true
|