212 lines
7.2 KiB
YAML
212 lines
7.2 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-and-release:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: code.foss.global/host.today/ht-docker-node:latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Deno
|
|
uses: denoland/setup-deno@v1
|
|
with:
|
|
deno-version: v2.x
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
|
|
- name: Enable corepack
|
|
run: corepack enable
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --ignore-scripts
|
|
|
|
- name: Get version from tag
|
|
id: version
|
|
run: |
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
|
|
echo "Building version: $VERSION"
|
|
|
|
- name: Verify deno.json version matches tag
|
|
run: |
|
|
DENO_VERSION=$(grep -o '"version": "[^"]*"' deno.json | cut -d'"' -f4)
|
|
TAG_VERSION="${{ steps.version.outputs.version_number }}"
|
|
echo "deno.json version: $DENO_VERSION"
|
|
echo "Tag version: $TAG_VERSION"
|
|
if [ "$DENO_VERSION" != "$TAG_VERSION" ]; then
|
|
echo "ERROR: Version mismatch!"
|
|
echo "deno.json has version $DENO_VERSION but tag is $TAG_VERSION"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Compile binaries for all platforms
|
|
run: mkdir -p dist/binaries && npx tsdeno compile
|
|
|
|
- name: Generate SHA256 checksums
|
|
run: |
|
|
cd dist/binaries
|
|
sha256sum * > SHA256SUMS.txt
|
|
cat SHA256SUMS.txt
|
|
cd ../..
|
|
|
|
- name: Extract changelog for this version
|
|
id: changelog
|
|
run: |
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
|
|
# Check if CHANGELOG.md exists
|
|
if [ ! -f CHANGELOG.md ] && [ ! -f changelog.md ]; then
|
|
echo "No changelog found, using default release notes"
|
|
cat > /tmp/release_notes.md << EOF
|
|
## Onebox $VERSION
|
|
|
|
Pre-compiled binaries for multiple platforms.
|
|
|
|
### Installation
|
|
|
|
Use the installation script:
|
|
\`\`\`bash
|
|
curl -sSL https://code.foss.global/serve.zone/onebox/raw/branch/main/install.sh | sudo bash
|
|
\`\`\`
|
|
|
|
Or download the binary for your platform and make it executable.
|
|
|
|
### Supported Platforms
|
|
- Linux x86_64 (x64)
|
|
- Linux ARM64 (aarch64)
|
|
- macOS x86_64 (Intel)
|
|
- macOS ARM64 (Apple Silicon)
|
|
- Windows x86_64
|
|
|
|
### Checksums
|
|
SHA256 checksums are provided in SHA256SUMS.txt
|
|
EOF
|
|
else
|
|
CHANGELOG_FILE=$([ -f CHANGELOG.md ] && echo "CHANGELOG.md" || echo "changelog.md")
|
|
awk "/## \[$VERSION\]/,/## \[/" "$CHANGELOG_FILE" | sed '$d' > /tmp/release_notes.md || cat > /tmp/release_notes.md << EOF
|
|
## Onebox $VERSION
|
|
|
|
See changelog.md for full details.
|
|
|
|
### Installation
|
|
|
|
Use the installation script:
|
|
\`\`\`bash
|
|
curl -sSL https://code.foss.global/serve.zone/onebox/raw/branch/main/install.sh | sudo bash
|
|
\`\`\`
|
|
EOF
|
|
fi
|
|
|
|
echo "Release notes:"
|
|
cat /tmp/release_notes.md
|
|
|
|
- name: Delete existing release if it exists
|
|
run: |
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
|
|
echo "Checking for existing release $VERSION..."
|
|
|
|
# Try to get existing release by tag
|
|
EXISTING_RELEASE_ID=$(curl -s \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/tags/$VERSION" \
|
|
| jq -r '.id // empty')
|
|
|
|
if [ -n "$EXISTING_RELEASE_ID" ]; then
|
|
echo "Found existing release (ID: $EXISTING_RELEASE_ID), deleting..."
|
|
curl -X DELETE -s \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/$EXISTING_RELEASE_ID"
|
|
echo "Existing release deleted"
|
|
sleep 2
|
|
else
|
|
echo "No existing release found, proceeding with creation"
|
|
fi
|
|
|
|
- name: Create Gitea Release
|
|
run: |
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
RELEASE_NOTES=$(cat /tmp/release_notes.md)
|
|
|
|
# Create the release
|
|
echo "Creating release for $VERSION..."
|
|
RELEASE_ID=$(curl -X POST -s \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"https://code.foss.global/api/v1/repos/serve.zone/onebox/releases" \
|
|
-d "{
|
|
\"tag_name\": \"$VERSION\",
|
|
\"name\": \"Onebox $VERSION\",
|
|
\"body\": $(jq -Rs . /tmp/release_notes.md),
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}" | jq -r '.id')
|
|
|
|
echo "Release created with ID: $RELEASE_ID"
|
|
|
|
# Upload binaries as release assets
|
|
for binary in dist/binaries/*; do
|
|
filename=$(basename "$binary")
|
|
echo "Uploading $filename..."
|
|
curl -X POST -s \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary "@$binary" \
|
|
"https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/$RELEASE_ID/assets?name=$filename"
|
|
done
|
|
|
|
echo "All assets uploaded successfully"
|
|
|
|
- name: Clean up old releases
|
|
run: |
|
|
echo "Cleaning up old releases (keeping only last 3)..."
|
|
|
|
# Fetch all releases sorted by creation date
|
|
RELEASES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://code.foss.global/api/v1/repos/serve.zone/onebox/releases" | \
|
|
jq -r 'sort_by(.created_at) | reverse | .[3:] | .[].id')
|
|
|
|
# Delete old releases
|
|
if [ -n "$RELEASES" ]; then
|
|
echo "Found releases to delete:"
|
|
for release_id in $RELEASES; do
|
|
echo " Deleting release ID: $release_id"
|
|
curl -X DELETE -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/$release_id"
|
|
done
|
|
echo "Old releases deleted successfully"
|
|
else
|
|
echo "No old releases to delete (less than 4 releases total)"
|
|
fi
|
|
echo ""
|
|
|
|
- name: Release Summary
|
|
run: |
|
|
echo "================================================"
|
|
echo " Release ${{ steps.version.outputs.version }} Complete!"
|
|
echo "================================================"
|
|
echo ""
|
|
echo "Binaries published:"
|
|
ls -lh dist/binaries/
|
|
echo ""
|
|
echo "Release URL:"
|
|
echo "https://code.foss.global/serve.zone/onebox/releases/tag/${{ steps.version.outputs.version }}"
|
|
echo ""
|
|
echo "Installation command:"
|
|
echo "curl -sSL https://code.foss.global/serve.zone/onebox/raw/branch/main/install.sh | sudo bash"
|
|
echo ""
|