Skip to content

Commit

Permalink
chore: fix publish_nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRAG committed Feb 21, 2025
1 parent 593f362 commit d812e16
Showing 1 changed file with 88 additions and 20 deletions.
108 changes: 88 additions & 20 deletions .github/workflows/publish_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,67 @@ jobs:
with:
node-version: "18"
registry-url: "https://registry.npmjs.org"

- name: Install jq
run: sudo apt-get install jq

- name: Install dependencies and build packages
run: |
npm ci
npm run build
- name: Find NPM packages
id: find-npm-packages
run: |
PACKAGES=$(find . -name "package.json" -not -path "*/node_modules/*" -not -path "./package.json" -exec dirname {} \;)
PACKAGES=$(find . -name "package.json" \
-not -path "*/node_modules/*" \
-not -path "./package.json" \
-not -path "*/examples/*" \
-exec dirname {} \; | tr '\n' ' ')
echo "Found NPM packages in directories:"
echo "$PACKAGES"
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
- name: Update package versions
run: |
while IFS= read -r pkg; do
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
echo "Updating version for $pkg"
npm version prerelease --preid=nightly.$(date +%Y%m%d) --no-git-tag-version
# Get package name from package.json
PKG_NAME=$(node -p "require('./package.json').name")
echo "Package name: $PKG_NAME"
# Debug: show all versions, handle case where package doesn't exist yet
echo "All versions from npm:"
ALL_VERSIONS=$(npm view "$PKG_NAME" versions --all --json 2>/dev/null || echo "[]")
echo "$ALL_VERSIONS" | jq -r '.[]' 2>/dev/null || echo "No versions found"
# Get all versions and find latest nightly if it exists
LATEST_NIGHTLY=$(echo "$ALL_VERSIONS" | jq -r '.[]' 2>/dev/null | grep -E "nightly\.[0-9]{8}\.[0-9]+$" | sort -V | tail -n1 || echo "")
echo "Latest nightly found: ${LATEST_NIGHTLY:-none}"
TODAY=$(date +%Y%m%d)
if [ -z "$LATEST_NIGHTLY" ]; then
echo "Creating first nightly version"
npm version prerelease --preid=nightly.$TODAY --no-git-tag-version
else
# Extract the build number and increment it
BUILD_NUM=$(echo $LATEST_NIGHTLY | grep -Eo '[0-9]+$')
NEXT_BUILD=$((BUILD_NUM + 1))
echo "Incrementing build number from $BUILD_NUM to $NEXT_BUILD"
npm version "$(echo $LATEST_NIGHTLY | cut -d'-' -f1)-nightly.$TODAY.$NEXT_BUILD" --no-git-tag-version
fi
fi
cd - > /dev/null
fi
done <<< "${{ steps.find-npm-packages.outputs.packages }}"
- run: npm ci

done
- name: Publish packages
run: |
while IFS= read -r pkg; do
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
Expand All @@ -73,7 +107,7 @@ jobs:
fi
cd - > /dev/null
fi
done <<< "${{ steps.find-npm-packages.outputs.packages }}"
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Expand All @@ -89,44 +123,79 @@ jobs:
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: |
PACKAGES=$(find . -name "pyproject.toml" -exec dirname {} \;)
# Convert newlines to spaces for GitHub Actions output
PACKAGES=$(find . -name "pyproject.toml" \
-not -path "*/examples/*" \
-exec dirname {} \; | tr '\n' ' ')
echo "Found Python packages in directories:"
echo "$PACKAGES"
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
- name: Update package versions
run: |
while IFS= read -r pkg; do
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
echo "Updating version for $pkg"
poetry version $(poetry version -s).dev$(date +%Y%m%d)
# Get package name from pyproject.toml
PKG_NAME=$(poetry version | cut -d' ' -f1)
echo "Package name: $PKG_NAME"
# Get current version
CURRENT_VERSION=$(poetry version -s)
echo "Current version: $CURRENT_VERSION"
# Debug: show all versions from PyPI
echo "All versions from PyPI:"
ALL_VERSIONS=$(curl -s "https://pypi.org/pypi/$PKG_NAME/json" 2>/dev/null | jq -r '.releases | keys[]' 2>/dev/null || echo "[]")
echo "$ALL_VERSIONS"
# Get latest nightly version if it exists
LATEST_NIGHTLY=$(echo "$ALL_VERSIONS" | grep -E "dev[0-9]{8}\.[0-9]+$" | sort -V | tail -n1 || echo "")
echo "Latest nightly found: ${LATEST_NIGHTLY:-none}"
TODAY=$(date +%Y%m%d)
if [ -z "$LATEST_NIGHTLY" ]; then
echo "Creating first nightly version"
poetry version $(poetry version -s).dev$(date +%Y%m%d).0
else
# Extract the build number and increment it
BUILD_NUM=$(echo $LATEST_NIGHTLY | grep -Eo '[0-9]+$')
NEXT_BUILD=$((BUILD_NUM + 1))
echo "Incrementing build number from $BUILD_NUM to $NEXT_BUILD"
poetry version $(poetry version -s).dev$(date +%Y%m%d).$NEXT_BUILD
fi
fi
cd - > /dev/null
fi
done <<< "${{ steps.find-python-packages.outputs.packages }}"
done
- name: Build and publish
run: |
while IFS= read -r pkg; do
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
echo "Publishing $pkg"
poetry install --only main
poetry build
poetry publish --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
fi
cd - > /dev/null
fi
done <<< "${{ steps.find-python-packages.outputs.packages }}"
done
create-github-release:
needs: [prepare-nightly, publish-npm-nightly, publish-pypi-nightly]
Expand All @@ -144,13 +213,11 @@ jobs:
id: release_notes
run: |
TODAY=$(date +%Y-%m-%d)
echo "TODAY=$TODAY" >> $GITHUB_OUTPUT
echo "Generating release notes for nightly build $TODAY"
{
echo "# 🌙 Nightly Build $TODAY"
echo ""
extract_unreleased() {
local file=$1
local package=$2
Expand Down Expand Up @@ -179,9 +246,10 @@ jobs:
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TODAY: ${{ steps.release_notes.outputs.TODAY }}
with:
tag_name: nightly-${{ github.sha }}
release_name: 🌙 Nightly Build $(date +%Y-%m-%d)
tag_name: nightly-${{ env.TODAY }}
release_name: "🌙 Nightly Build ${{ env.TODAY }}"
body: ${{ steps.release_notes.outputs.RELEASE_NOTES }}
draft: false
prerelease: true

0 comments on commit d812e16

Please sign in to comment.