[fix][render preview] Store page SSG fix #572
Workflow file for this run
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: Release Staging (Codecane) | |
on: | |
pull_request: | |
branches: ['main'] | |
# Ensure only one staging release runs at a time | |
concurrency: | |
group: staging-release | |
cancel-in-progress: false | |
permissions: | |
contents: write | |
jobs: | |
# First job: Check PR title and prepare staging release | |
prepare-and-commit-staging: | |
runs-on: ubuntu-latest | |
if: contains(github.event.pull_request.title, '[codecane]') | |
outputs: | |
new_version: ${{ steps.bump_version.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Set up Bun | |
uses: oven-sh/setup-bun@v2 | |
with: | |
bun-version: '1.2.16' | |
# Cache dependencies for speed | |
- name: Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
node_modules | |
*/node_modules | |
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lockb', '**/package.json') }} | |
restore-keys: | | |
${{ runner.os }}-deps-${{ hashFiles('**/bun.lockb') }} | |
${{ runner.os }}-deps- | |
- name: Install dependencies | |
run: bun install --frozen-lockfile | |
- name: Calculate and update staging version | |
id: bump_version | |
run: | | |
cd npm-app/release-staging | |
# Use the current package.json version as base | |
CURRENT_VERSION=$(node -e "console.log(require('./package.json').version)") | |
echo "Current package.json version: $CURRENT_VERSION" | |
# Get latest beta version from npm to check if we need to increment | |
echo "Fetching latest beta version from npm..." | |
LATEST_BETA=$(npm view codecane@latest version 2>/dev/null || echo "") | |
if [ -z "$LATEST_BETA" ]; then | |
echo "No beta version found on npm, using current version as base" | |
NEW_VERSION="$CURRENT_VERSION-beta.1" | |
else | |
echo "Latest beta version: $LATEST_BETA" | |
# Extract base version and beta number from npm | |
NPM_BASE_VERSION=$(echo "$LATEST_BETA" | sed 's/-beta\..*$//') | |
BETA_NUM=$(echo "$LATEST_BETA" | sed 's/.*-beta\.//') | |
# Compare base versions | |
if [ "$CURRENT_VERSION" = "$NPM_BASE_VERSION" ]; then | |
# Same base version, increment beta number | |
NEW_BETA_NUM=$((BETA_NUM + 1)) | |
NEW_VERSION="$CURRENT_VERSION-beta.$NEW_BETA_NUM" | |
else | |
# Different base version, start with beta.1 | |
NEW_VERSION="$CURRENT_VERSION-beta.1" | |
fi | |
fi | |
echo "New staging version: $NEW_VERSION" | |
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
# Update package.json with new version | |
node -e " | |
const fs = require('fs'); | |
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
pkg.version = '$NEW_VERSION'; | |
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
" | |
- name: Configure git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Commit staging release state | |
run: | | |
# Add all changes (current state + version bump) | |
git add -A | |
git commit -m "Staging Release v${{ steps.bump_version.outputs.new_version }} (codecane) | |
This commit captures the complete state being released for staging, | |
including any uncommitted changes and the version bump. | |
🤖 Generated with Codebuff | |
Co-Authored-By: Codebuff <[email protected]>" | |
- name: Create and push staging tag | |
run: | | |
# Show current commit info for debugging | |
echo "Current HEAD commit:" | |
git log -1 --format="%H %ci %s" | |
# Create tag on current HEAD (the commit we just made) | |
git tag "v${{ steps.bump_version.outputs.new_version }}" | |
git push origin "v${{ steps.bump_version.outputs.new_version }}" | |
echo "Tag created on commit:" | |
git show "v${{ steps.bump_version.outputs.new_version }}" --format="%H %ci %s" -s | |
- name: Upload updated package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: updated-staging-package | |
path: npm-app/release-staging/ | |
build-staging-binaries: | |
needs: prepare-and-commit-staging | |
uses: ./.github/workflows/npm-app-release-build.yml | |
with: | |
binary-name: codecane | |
new-version: ${{ needs.prepare-and-commit-staging.outputs.new_version }} | |
artifact-name: updated-staging-package | |
checkout-ref: ${{ github.event.pull_request.head.sha }} | |
env-overrides: '{"NEXT_PUBLIC_CB_ENVIRONMENT": "prod", "NEXT_PUBLIC_CODEBUFF_BACKEND_URL": "backend-pr-221-we0m.onrender.com"}' | |
secrets: inherit | |
# Create GitHub prerelease with all binaries | |
create-staging-release: | |
needs: [prepare-and-commit-staging, build-staging-binaries] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Clean up old prereleases | |
run: | | |
# Calculate date one week ago | |
ONE_WEEK_AGO=$(date -d '7 days ago' -u +%Y-%m-%dT%H:%M:%SZ) | |
echo "Current date: $(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
echo "Cleaning up prereleases older than: $ONE_WEEK_AGO" | |
# Get all prereleases | |
echo "Fetching releases from GitHub API..." | |
RELEASES=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/CodebuffAI/codebuff-community/releases?per_page=100") | |
# Check if we got a valid response | |
if echo "$RELEASES" | jq -e . >/dev/null 2>&1; then | |
echo "Successfully fetched releases JSON" | |
# Count total releases and prereleases | |
TOTAL_RELEASES=$(echo "$RELEASES" | jq '. | length') | |
PRERELEASE_COUNT=$(echo "$RELEASES" | jq '[.[] | select(.prerelease == true)] | length') | |
echo "Total releases: $TOTAL_RELEASES" | |
echo "Total prereleases: $PRERELEASE_COUNT" | |
# Show some example release dates for debugging | |
echo "Sample release dates:" | |
echo "$RELEASES" | jq -r '.[] | select(.prerelease == true) | "\(.tag_name): \(.created_at)"' | head -5 | |
# Filter and show old prereleases before deleting | |
OLD_PRERELEASES=$(echo "$RELEASES" | jq -r '.[] | select(.prerelease == true and .created_at < "'$ONE_WEEK_AGO'") | "\(.id):\(.tag_name):\(.created_at)"') | |
if [ -z "$OLD_PRERELEASES" ]; then | |
echo "No old prereleases found to delete" | |
else | |
echo "Found old prereleases to delete:" | |
echo "$OLD_PRERELEASES" | |
# Delete old prereleases | |
echo "$RELEASES" | jq -r '.[] | select(.prerelease == true and .created_at < "'$ONE_WEEK_AGO'") | .id' | while read release_id; do | |
if [ -n "$release_id" ]; then | |
echo "Deleting prerelease with ID: $release_id" | |
DELETE_RESPONSE=$(curl -s -w "HTTP Status: %{http_code}" -X DELETE \ | |
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/CodebuffAI/codebuff-community/releases/$release_id") | |
echo "Delete response: $DELETE_RESPONSE" | |
fi | |
done | |
fi | |
else | |
echo "Failed to fetch releases or invalid JSON response:" | |
echo "$RELEASES" | head -10 | |
fi | |
echo "Cleanup completed" | |
- name: Download all binary artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: binaries/ | |
- name: Download updated package | |
uses: actions/download-artifact@v4 | |
with: | |
name: updated-staging-package | |
path: npm-app/release-staging/ | |
- name: Create GitHub Prerelease | |
run: | | |
# Get current timestamp in ISO format | |
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
echo "Publishing release at: $CURRENT_TIME" | |
# Create release with current timestamp | |
curl -s -X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
https://api.github.com/repos/CodebuffAI/codebuff-community/releases \ | |
-d "{ | |
\"tag_name\": \"v${{ needs.prepare-and-commit-staging.outputs.new_version }}\", | |
\"name\": \"Staging Release v${{ needs.prepare-and-commit-staging.outputs.new_version }} (Codecane)\", | |
\"body\": \"## Codecane v${{ needs.prepare-and-commit-staging.outputs.new_version }} (Staging)\n\n**⚠️ This is a staging/beta release for testing purposes.**\n\nBinary releases for all supported platforms.\n\n### Installation\n\`\`\`bash\nnpm install -g codecane\n\`\`\`\n\n### Platform Binaries\n- \`codecane-linux-x64.tar.gz\` - Linux x64\n- \`codecane-linux-arm64.tar.gz\` - Linux ARM64\n- \`codecane-darwin-x64.tar.gz\` - macOS Intel\n- \`codecane-darwin-arm64.tar.gz\` - macOS Apple Silicon\n- \`codecane-win32-x64.tar.gz\` - Windows x64\", | |
\"prerelease\": true, | |
\"published_at\": \"$CURRENT_TIME\" | |
}" | |
- name: Upload release assets | |
run: | | |
# Get the release ID | |
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/CodebuffAI/codebuff-community/releases/tags/v${{ needs.prepare-and-commit-staging.outputs.new_version }}" | \ | |
jq -r '.id') | |
echo "Release ID: $RELEASE_ID" | |
# Upload all binary assets | |
for file in binaries/*/codecane-*; do | |
if [ -f "$file" ]; then | |
filename=$(basename "$file") | |
echo "Uploading $filename..." | |
curl -s -X POST \ | |
-H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/octet-stream" \ | |
--data-binary @"$file" \ | |
"https://uploads.github.com/repos/CodebuffAI/codebuff-community/releases/$RELEASE_ID/assets?name=$filename" | |
fi | |
done | |
# Publish npm package as prerelease | |
publish-staging-npm: | |
needs: [prepare-and-commit-staging, create-staging-release] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Download updated package | |
uses: actions/download-artifact@v4 | |
with: | |
name: updated-staging-package | |
path: npm-app/release-staging/ | |
- name: Set up Node.js for npm publishing | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://registry.npmjs.org/ | |
- name: Publish staging to npm | |
run: | | |
cd npm-app/release-staging | |
npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |