Skip to content

fix: release in a loop #14

fix: release in a loop

fix: release in a loop #14

name: Release Please
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
actions: write
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release-created: ${{ steps.release.outputs.release_created }}
tag-name: ${{ steps.release.outputs.tag_name }}
version: ${{ steps.release.outputs.version }}
steps:
- name: Release Please
id: release
uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: codekeeper-guardrails
skip-labeling: true
publish-main-release:
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release-created == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: ./.github/actions/setup-node
with:
install-dependencies: 'true'
- name: Run comprehensive tests before release
run: |
echo "🧪 Running comprehensive tests before main release..."
npm test
node test-validation/test-eslint-plugin.js
echo "✅ All tests passed"
- name: Create GitHub Release Assets
run: |
echo "📦 Creating release assets..."
# Create a comprehensive release package
mkdir -p release-assets
# Copy validation scripts
cp -r scripts/ release-assets/
# Copy examples
cp -r examples/ release-assets/
# Copy documentation
cp -r docs/ release-assets/ || echo "No docs directory found"
# Create installation script
cat > release-assets/install-codekeeper.sh << 'EOF'
#!/bin/bash
# CodeKeeper Installation Script
echo "🛡️ Installing CodeKeeper Validation Scripts..."
# Copy validation scripts
if [ ! -d "scripts" ]; then
mkdir -p scripts
fi
cp -r scripts/validation scripts/
echo "✅ CodeKeeper validation scripts installed successfully!"
echo "📚 See examples/ directory for usage examples"
EOF
chmod +x release-assets/install-codekeeper.sh
# Include key documentation
cp README.md release-assets/
cp LICENSE release-assets/ || echo "No LICENSE file found"
cp CHANGELOG.md release-assets/ || echo "No CHANGELOG file found"
# Create archive
tar -czf codekeeper-${{ needs.release-please.outputs.tag-name }}.tar.gz -C release-assets .
echo "✅ Release assets created successfully"
- name: Upload Release Assets
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
try {
// Find the release created by release-please
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 5
});
const targetRelease = releases.data.find(release =>
release.tag_name === '${{ needs.release-please.outputs.tag-name }}'
);
if (!targetRelease) {
console.log('⚠️ Release not found yet, it may still be creating...');
return;
}
console.log(`📎 Uploading assets to release ${targetRelease.tag_name}...`);
// Upload the tar.gz archive
if (fs.existsSync('codekeeper-${{ needs.release-please.outputs.tag-name }}.tar.gz')) {
const assetData = fs.readFileSync('codekeeper-${{ needs.release-please.outputs.tag-name }}.tar.gz');
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: targetRelease.id,
name: 'codekeeper-${{ needs.release-please.outputs.tag-name }}.tar.gz',
data: assetData,
headers: {
'content-type': 'application/gzip',
'content-length': assetData.length
}
});
console.log('✅ Archive uploaded successfully');
}
// Update release body with installation instructions
const installInstructions = `
## 📦 Installation
Download and extract the release archive:
\`\`\`bash
curl -L https://github.com/${{ github.repository }}/releases/download/${{ needs.release-please.outputs.tag-name }}/codekeeper-${{ needs.release-please.outputs.tag-name }}.tar.gz | tar -xz
\`\`\`
Or run the installation script:
\`\`\`bash
./install-codekeeper.sh
\`\`\`
`;
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: targetRelease.id,
body: targetRelease.body + installInstructions
});
console.log('✅ Release updated with installation instructions');
} catch (error) {
console.error('Error uploading release assets:', error);
core.setFailed(error.message);
}
notify-release:
name: Release Notification
runs-on: ubuntu-latest
needs: [release-please, publish-main-release]
if: always() && needs.release-please.outputs.release-created == 'true'
steps:
- name: Send notification
uses: actions/github-script@v7
with:
script: |
let message = '# 🚀 New Release Published!\n\n';
if ('${{ needs.release-please.outputs.release-created }}' === 'true') {
message += `### 🛡️ CodeKeeper: ${{ needs.release-please.outputs.tag-name }}\n`;
message += '- Validation scripts and guardrails\n';
message += '- Examples and documentation\n';
message += '- Installation script included\n\n';
message += `[View Release](https://github.com/${{ github.repository }}/releases/tag/${{ needs.release-please.outputs.tag-name }})`;
}
console.log(message);
// You could send this to Slack, Discord, or other notification services
// For now, just log it to the workflow