-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (79 loc) · 4.12 KB
/
Copy pathupstream-watch.yml
File metadata and controls
90 lines (79 loc) · 4.12 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
name: Upstream SDK watch
# Detects when the upstream TypeScript SDK (@avodotso/market-sdk) publishes a new
# version and opens a tracking issue so the Rust port can be updated. Baseline is
# this crate's own Cargo.toml version (we mirror upstream); an issue fires only
# when npm's latest differs, and bumping Cargo.toml on port clears the condition.
#
# NOTE: scheduled runs only fire for workflows on the DEFAULT branch — this must
# be merged to `main` to run on cron. Use workflow_dispatch to test.
on:
schedule:
- cron: '0 7 * * *' # daily 07:00 UTC
workflow_dispatch:
permissions:
contents: read # checkout + read Cargo.toml
issues: write # create the issue + ensure the label exists
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Resolve versions
id: v
run: |
set -euo pipefail
# [package] is the first table, so the first `version = "..."` line is the crate version.
PORTED=$(grep -m1 '^version' Cargo.toml | sed -E 's/.*"(.*)".*/\1/')
NPM=$(curl -fsSL https://registry.npmjs.org/@avodotso/market-sdk)
LATEST=$(printf '%s' "$NPM" | jq -r '."dist-tags".latest')
PUBLISHED=$(printf '%s' "$NPM" | jq -r --arg v "$LATEST" '.time[$v] // ""')
echo "ported=$PORTED" >> "$GITHUB_OUTPUT"
echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
echo "published=$PUBLISHED" >> "$GITHUB_OUTPUT"
echo "Rust port: v$PORTED — upstream npm latest: v$LATEST"
- name: Open sync issue when upstream is ahead
if: >-
steps.v.outputs.latest != '' &&
steps.v.outputs.latest != 'null' &&
steps.v.outputs.latest != steps.v.outputs.ported
env:
GH_TOKEN: ${{ github.token }}
LATEST: ${{ steps.v.outputs.latest }}
PORTED: ${{ steps.v.outputs.ported }}
PUBLISHED: ${{ steps.v.outputs.published }}
run: |
set -euo pipefail
TITLE="Upstream @avodotso/market-sdk v${LATEST} released — sync Rust SDK"
# Dedup: one issue per upstream version, across all states (open + closed),
# so it isn't re-filed daily while the port is in progress.
EXISTING=$(gh issue list --state all --search "in:title \"v${LATEST}\"" \
--json title --jq '.[].title')
if printf '%s\n' "$EXISTING" | grep -Fxq "$TITLE"; then
echo "Issue for v${LATEST} already exists — nothing to do."
exit 0
fi
# Ensure the label exists (idempotent — no-op if already present).
gh label create upstream-sync \
--color 1D76DB \
--description "Sync the Rust port with the upstream TS SDK" 2>/dev/null || true
# Build the body: dynamic header via printf (safe var expansion), then a
# static checklist via a quoted heredoc (backticks stay literal).
{
printf 'Upstream **@avodotso/market-sdk** published **v%s**' "$LATEST"
[ -n "$PUBLISHED" ] && printf ' (%s)' "$PUBLISHED"
printf '; the Rust port is at **v%s**.\n\n' "$PORTED"
printf -- '- npm: https://www.npmjs.com/package/@avodotso/market-sdk/v/%s\n' "$LATEST"
printf -- '- Upstream diff: https://github.com/avodotso/market-sdk/compare/sdk-v%s...sdk-v%s\n' "$PORTED" "$LATEST"
printf -- '- Source repo: https://github.com/avodotso/market-sdk\n\n'
cat <<'BODY'
## Port checklist
- [ ] Review the upstream diff for API / type / auth changes
- [ ] Update wire types in `src/types/`
- [ ] Update endpoints & auth in `src/client.rs` / `src/auth.rs`
- [ ] Re-check the pinned behaviors in `docs/business-logic.md` §10
- [ ] Refresh golden vectors if the Sig-token / attach message changed
- [ ] Bump `Cargo.toml` `version` (this closes the watcher) + the version note in `docs/business-logic.md`
_Filed automatically by `.github/workflows/upstream-watch.yml`._
BODY
} > issue-body.md
gh issue create --title "$TITLE" --body-file issue-body.md --label upstream-sync