Publish Nightly Builds #46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |