Repository navigation
139 lines (117 loc) · 5.07 KB
/
Copy pathsync.yml
File metadata and controls
139 lines (117 loc) · 5.07 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
name: Mirror Sync & Monitor
on:
schedule:
- cron: "0 8 * * *" # Daily at 8am UTC
workflow_dispatch: {}
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Mirror branches and tags from spiceai/snowflake-rs
run: |
git clone --bare https://github.com/spiceai/snowflake-rs.git /tmp/upstream
cd /tmp/upstream
git remote add mirror https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
# Push every branch except our admin branch
for ref in $(git for-each-ref --format='%(refname)' refs/heads/); do
branch="${ref#refs/heads/}"
if [ "$branch" = "hotdata" ]; then
echo "Skipping admin branch: hotdata"
continue
fi
echo "Syncing branch: $branch"
git push mirror "$ref:$ref" --force
done
# Push all tags
git push mirror --tags --force
monitor:
runs-on: ubuntu-latest
needs: sync
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: Iv23liKBX2RYMoZIYuKa
private-key: ${{ secrets.HOTDATA_AUTOMATION_PRIVATE_KEY }}
owner: hotdata-dev
repositories: runtimedb
- name: Check for upstream rev change
id: check
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
# Get the rev spiceai/spiceai currently pins
UPSTREAM_CARGO=$(curl -sfL https://raw.githubusercontent.com/spiceai/spiceai/trunk/Cargo.toml)
UPSTREAM_REV=$(echo "$UPSTREAM_CARGO" | grep 'snowflake-api' | grep -oP 'rev = "\K[a-f0-9]+')
if [ -z "$UPSTREAM_REV" ]; then
echo "Could not extract upstream rev — skipping"
exit 0
fi
echo "upstream_rev=$UPSTREAM_REV" >> "$GITHUB_OUTPUT"
# Get the rev runtimedb currently uses
RUNTIMEDB_CARGO=$(curl -sfL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github.raw+json" \
"https://api.github.com/repos/hotdata-dev/runtimedb/contents/Cargo.toml?ref=main")
CURRENT_REV=$(echo "$RUNTIMEDB_CARGO" | grep 'snowflake-api' | grep -oP 'rev = "\K[a-f0-9]+')
if [ -z "$CURRENT_REV" ]; then
echo "Could not extract runtimedb rev — skipping"
exit 0
fi
echo "current_rev=$CURRENT_REV" >> "$GITHUB_OUTPUT"
if [ "$UPSTREAM_REV" != "$CURRENT_REV" ]; then
echo "Rev changed: $CURRENT_REV -> $UPSTREAM_REV"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "Revs match ($CURRENT_REV) — nothing to do"
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Verify commit exists in mirror
if: steps.check.outputs.changed == 'true'
env:
UPSTREAM_REV: ${{ steps.check.outputs.upstream_rev }}
run: |
HTTP_CODE=$(curl -so /dev/null -w '%{http_code}' \
"https://api.github.com/repos/${{ github.repository }}/git/commits/$UPSTREAM_REV")
if [ "$HTTP_CODE" != "200" ]; then
echo "::error::Commit $UPSTREAM_REV not found in mirror (HTTP $HTTP_CODE)"
exit 1
fi
- name: File PR against runtimedb
if: steps.check.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
UPSTREAM_REV: ${{ steps.check.outputs.upstream_rev }}
CURRENT_REV: ${{ steps.check.outputs.current_rev }}
run: |
SHORT_REV="${UPSTREAM_REV:0:7}"
# Check for existing open PR
EXISTING=$(gh pr list --repo hotdata-dev/runtimedb \
--search "update snowflake-rs rev" --state open \
--json number --jq '.[0].number')
if [ -n "$EXISTING" ]; then
echo "PR #$EXISTING already open — skipping"
exit 0
fi
# Clone runtimedb and create update branch
gh repo clone hotdata-dev/runtimedb /tmp/runtimedb
cd /tmp/runtimedb
BRANCH="chore/update-snowflake-rs-rev-${SHORT_REV}"
git checkout -b "$BRANCH"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# Update the rev in Cargo.toml
sed -i "s|rev = \"$CURRENT_REV\"|rev = \"$UPSTREAM_REV\"|" Cargo.toml
git add Cargo.toml
git commit -m "chore(deps): update snowflake-rs rev to ${SHORT_REV}"
git push -u origin "$BRANCH"
gh pr create --repo hotdata-dev/runtimedb \
--title "chore(deps): update snowflake-rs rev to ${SHORT_REV}" \
--body "$(cat <<EOF
Spice.ai updated their snowflake-rs pin from \`${CURRENT_REV:0:12}\` to \`${UPSTREAM_REV:0:12}\`.
Detected automatically by the [mirror sync workflow](https://github.com/${{ github.repository }}/actions).
EOF
)"