nightly #142
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: nightly | |
| on: | |
| schedule: | |
| # Run at 2 AM UTC every day | |
| - cron: "0 2 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: "Force publish even if no changes" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| check-and-publish: | |
| runs-on: ubuntu-latest | |
| env: | |
| NPM_PACKAGE_NAME: "@adolago/zee" | |
| ZEE_CHANNEL: nightly | |
| ZEE_NPM_PACKAGE: "@adolago/zee" | |
| ZEE_TARGETS: linux-arm64,linux-x64,linux-x64-baseline,linux-arm64-musl,linux-x64-musl,linux-x64-musl-baseline,win32-x64,win32-x64-baseline | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for changes since last release | |
| id: changes | |
| run: | | |
| # Get the latest release tag | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$LATEST_TAG" ]; then | |
| echo "No previous release found, will publish" | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Check if there are commits since the last tag | |
| COMMITS=$(git rev-list ${LATEST_TAG}..HEAD --count) | |
| if [ "$COMMITS" -gt 0 ] || [ "${{ inputs.force }}" = "true" ]; then | |
| echo "Found $COMMITS commits since $LATEST_TAG" | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No changes since $LATEST_TAG" | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Bun | |
| if: steps.changes.outputs.has_changes == 'true' | |
| uses: ./.github/actions/setup-bun | |
| - name: Setup Node.js | |
| if: steps.changes.outputs.has_changes == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install dependencies | |
| if: steps.changes.outputs.has_changes == 'true' | |
| run: bun install | |
| - name: Set nightly version | |
| if: steps.changes.outputs.has_changes == 'true' | |
| id: version | |
| run: | | |
| DATE=$(date +%Y%m%d) | |
| # Read current version from package.json and increment patch | |
| CURRENT=$(jq -r '.version' packages/zee/package.json) | |
| # Strip any prerelease suffix (e.g., -alpha, -alpha.nightly.*) | |
| BASE=$(echo "$CURRENT" | sed 's/-.*//') | |
| # Parse major.minor.patch | |
| MAJOR=$(echo "$BASE" | cut -d. -f1) | |
| MINOR=$(echo "$BASE" | cut -d. -f2) | |
| PATCH=$(echo "$BASE" | cut -d. -f3) | |
| # Increment patch | |
| PATCH=$((PATCH + 1)) | |
| VERSION="${MAJOR}.${MINOR}.${PATCH}-alpha.nightly.${DATE}.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| # Update package.json versions using sed (npm version fails on catalog: refs) | |
| sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"${VERSION}\"/" packages/zee/package.json | |
| sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"${VERSION}\"/" package.json | |
| echo "Updated versions to ${VERSION}" | |
| grep '"version"' packages/zee/package.json | |
| - name: Check if nightly version already exists on npm | |
| if: steps.changes.outputs.has_changes == 'true' | |
| id: package | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if npm view "${NPM_PACKAGE_NAME}@${VERSION}" version >/dev/null 2>&1; then | |
| echo "already_published=true" >> "$GITHUB_OUTPUT" | |
| echo "${NPM_PACKAGE_NAME}@${VERSION} already exists on npm. Skipping publish." | |
| else | |
| echo "already_published=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Export release metadata | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' | |
| run: | | |
| echo "ZEE_VERSION=${{ steps.version.outputs.version }}" >> "$GITHUB_ENV" | |
| - name: Build | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' | |
| run: | | |
| cd packages/zee | |
| bun run build | |
| - name: Verify built binary | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' | |
| run: packages/zee/dist/@adolago/zee-linux-x64/bin/zee --version | |
| - name: Prepare release package | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' | |
| run: | | |
| cd packages/zee | |
| bun run script/prepare-release.ts | |
| - name: Publish dist packages to npm | |
| id: publish | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' | |
| run: | | |
| set -o pipefail | |
| cd packages/zee | |
| LOG_FILE="$(mktemp)" | |
| if bun run script/publish-dist.ts 2>&1 | tee "$LOG_FILE"; then | |
| echo "published=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| if grep -Eiq 'npm error code E(401|403|404)|Not found - PUT https://registry.npmjs.org/@adolago%2fzee|authentication|unauthorized|forbidden|one-time password' "$LOG_FILE"; then | |
| echo "Publish skipped because npm credentials cannot publish ${NPM_PACKAGE_NAME}." | |
| echo "published=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| exit 1 | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| ZEE_PUBLISH_TAG: nightly | |
| - name: Create GitHub Release | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' && steps.publish.outputs.published == 'true' | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| # Generate changelog from commits | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -n "$LATEST_TAG" ]; then | |
| CHANGELOG=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s" | head -20) | |
| else | |
| CHANGELOG="Initial nightly release" | |
| fi | |
| gh release create "v${VERSION}" \ | |
| --title "Nightly ${VERSION}" \ | |
| --notes "## Nightly Build | |
| **Version:** ${VERSION} | |
| **Date:** $(date +%Y-%m-%d) | |
| ### Changes | |
| ${CHANGELOG} | |
| ### Install | |
| \`\`\`bash | |
| npm install -g @adolago/zee@nightly | |
| # or specific version | |
| npm install -g @adolago/zee@${VERSION} | |
| \`\`\` | |
| " \ | |
| --prerelease | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Upload artifacts | |
| if: steps.changes.outputs.has_changes == 'true' && steps.package.outputs.already_published != 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: zee-nightly-${{ steps.version.outputs.version }} | |
| path: packages/zee/dist |