forked from coinbase/agentkit
-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (228 loc) · 9.42 KB
/
publish_nightly.yml
File metadata and controls
259 lines (228 loc) · 9.42 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: Publish Nightly Builds
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Run daily at midnight UTC
jobs:
prepare-nightly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Configure Git
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
- name: Update nightly branch
run: |
git checkout -B nightly
git push origin nightly --force
publish-npm-nightly:
needs: prepare-nightly
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: nightly
- uses: actions/setup-node@v4
with:
node-version: "18"
registry-url: "https://registry.npmjs.org"
cache: "npm"
cache-dependency-path: ./typescript
- name: Install jq
run: sudo apt-get install jq
- name: Install dependencies and build packages
run: |
cd typescript
npm ci
npm run build
- name: Find NPM packages
id: find-npm-packages
run: |
cd typescript
PACKAGES=$(find . -name "package.json" \
-not -path "*/node_modules/*" \
-not -path "./package.json" \
-not -path "*/examples/*" \
-not -path "*/create-onchain-agent/templates/*" \
-not -path "*/dist/*" \
-exec dirname {} \; | tr '\n' ' ')
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
- name: Update NPM package versions
run: |
cd typescript
for pkg in ${{ steps.find-npm-packages.outputs.packages }}; do
if [ -f "$pkg/package.json" ]; then
cd $pkg
if ! grep -q '"private": true' package.json; then
PKG_NAME=$(node -p "require('./package.json').name")
ALL_VERSIONS=$(npm view "$PKG_NAME" versions --all --json 2>/dev/null || echo "[]")
LATEST_NIGHTLY=$(echo "$ALL_VERSIONS" | jq -r '.[]' 2>/dev/null | grep -E "nightly\.[0-9]{8}\.[0-9]+$" | sort -V | tail -n1 || echo "")
TODAY=$(date +%Y%m%d)
if [ -z "$LATEST_NIGHTLY" ]; then
npm version prerelease --preid=nightly.$TODAY --no-git-tag-version
else
BUILD_NUM=$(echo $LATEST_NIGHTLY | grep -Eo '[0-9]+$')
NEXT_BUILD=$((BUILD_NUM + 1))
npm version "$(echo $LATEST_NIGHTLY | cut -d'-' -f1)-nightly.$TODAY.$NEXT_BUILD" --no-git-tag-version
fi
fi
cd - > /dev/null
fi
done
- name: Publish packages
run: |
cd typescript
for pkg in ${{ steps.find-npm-packages.outputs.packages }}; do
if [ -f "$pkg/package.json" ] && ! grep -q '"private": true' "$pkg/package.json"; then
cd $pkg && npm publish --tag nightly --provenance --access public
cd - > /dev/null
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-pypi-nightly:
needs: prepare-nightly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: nightly
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install jq
run: sudo apt-get install jq
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Find Python packages
id: find-python-packages
run: |
cd python
PACKAGES=$(find . -name "pyproject.toml" \
-not -path "*/examples/*" \
-exec dirname {} \; | tr '\n' ' ')
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
- name: Update Python package versions
run: |
cd python
for pkg in ${{ steps.find-python-packages.outputs.packages }}; do
if [ -f "$pkg/pyproject.toml" ]; then
cd $pkg
if ! grep -q "private = true" pyproject.toml; then
PKG_NAME=$(poetry version | cut -d' ' -f1)
CURRENT_VERSION=$(poetry version -s)
if [[ $CURRENT_VERSION == *".dev"* ]]; then
NEXT_VERSION=$(echo $CURRENT_VERSION | sed -E 's/\.dev[0-9]+$//')
else
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3 | cut -d- -f1 | cut -d+ -f1)
NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
fi
TODAY=$(date +%Y%m%d)
ALL_VERSIONS=$(curl -s "https://pypi.org/pypi/$PKG_NAME/json" | jq -r '.releases | keys[]')
LATEST_NIGHTLY=$(echo "$ALL_VERSIONS" | grep -E "^${NEXT_VERSION}\.dev${TODAY}[0-9]$" | sort -V | tail -n1 || echo "")
if [ -z "$LATEST_NIGHTLY" ]; then
poetry version "${NEXT_VERSION}.dev${TODAY}0"
else
BUILD_NUM=$(echo $LATEST_NIGHTLY | sed -E "s/.*\.dev${TODAY}([0-9])$/\1/")
NEXT_BUILD=$((BUILD_NUM + 1))
poetry version "${NEXT_VERSION}.dev${TODAY}${NEXT_BUILD}"
fi
fi
cd - > /dev/null
fi
done
- name: Build and publish
run: |
cd python
for pkg in ${{ steps.find-python-packages.outputs.packages }}; do
if [ -f "$pkg/pyproject.toml" ] && ! grep -q "private = true" "$pkg/pyproject.toml"; then
cd $pkg
poetry install --only main
poetry build
poetry publish --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
cd - > /dev/null
fi
done
# create-github-release:
# needs: [prepare-nightly, publish-npm-nightly, publish-pypi-nightly]
# runs-on: ubuntu-latest
# permissions:
# contents: write
# outputs:
# release_id: ${{ steps.create_release.outputs.id }}
# steps:
# - uses: actions/checkout@v4
# with:
# ref: nightly
# - name: Install Poetry
# uses: snok/install-poetry@v1
# - name: Generate Release Notes
# id: release_notes
# run: |
# TODAY=$(date +%Y%m%d)
# TODAY_FORMATTED=$(date +%Y-%m-%d)
# echo "TODAY=$TODAY" >> $GITHUB_OUTPUT
# echo "TODAY_FORMATTED=$TODAY_FORMATTED" >> $GITHUB_OUTPUT
# {
# extract_unreleased() {
# local file=$1 package=$2 version=$3
# if [ -f "$file" ]; then
# if [[ $package == @* ]]; then
# local url="https://www.npmjs.com/package/$package"
# [[ $version != "latest" ]] && url="$url/v/$version"
# else
# local url="https://pypi.org/project/$package"
# [[ $version != "latest" ]] && url="$url/$version"
# fi
# echo "## [📦 $package]($url)"
# echo ""
# awk '/^## Unreleased$/{p=1;next}/^## /{p=0}p' "$file" | grep -v '^$' || echo "No unreleased changes"
# echo ""
# fi
# }
# cd typescript
# for pkg in $(find . -name "package.json" -not -path "*/node_modules/*" -not -path "./typescript/package.json" -not -path "*/examples/*" -not -path "*/create-onchain-agent/templates/*" -not -path "*/dist/*" -exec dirname {} \;); do
# if [ -f "$pkg/package.json" ] && ! grep -q '"private": true' "$pkg/package.json"; then
# PKG_NAME=$(node -p "require('$pkg/package.json').name")
# CHANGELOG="$pkg/CHANGELOG.md"
# extract_unreleased "$CHANGELOG" "$PKG_NAME" \
# $(npm view "$PKG_NAME" versions --json | jq -r '.[]' | grep -E "nightly\.${TODAY}\.[0-9]$" | sort -V | tail -n1 || echo "latest")
# fi
# done
# cd - > /dev/null
# cd python
# for pkg in $(find . -name "pyproject.toml" -not -path "*/examples/*" -exec dirname {} \;); do
# if [ -f "$pkg/pyproject.toml" ] && ! grep -q "private = true" "$pkg/pyproject.toml"; then
# cd $pkg
# PKG_NAME=$(poetry version | cut -d' ' -f1)
# cd - > /dev/null
# CHANGELOG="$pkg/CHANGELOG.md"
# extract_unreleased "$CHANGELOG" "$PKG_NAME" \
# $(curl -s "https://pypi.org/pypi/$PKG_NAME/json" | jq -r '.releases | keys[]' | grep -E "\.dev${TODAY}[0-9]$" | sort -V | tail -n1 || echo "latest")
# fi
# done
# cd - > /dev/null
# } > release_notes.md
# echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
# cat release_notes.md >> $GITHUB_OUTPUT
# echo "EOF" >> $GITHUB_OUTPUT
# - name: Create Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# TODAY: ${{ steps.release_notes.outputs.TODAY }}
# with:
# tag_name: nightly-${{ env.TODAY }}
# release_name: "🌙 Nightly Build ${{ steps.release_notes.outputs.TODAY_FORMATTED }}"
# body: ${{ steps.release_notes.outputs.RELEASE_NOTES }}
# draft: false
# prerelease: true