feat: add gitea workflow
This commit is contained in:
149
.gitea/workflows/build-and-release.yml
Normal file
149
.gitea/workflows/build-and-release.yml
Normal file
@@ -0,0 +1,149 @@
|
||||
name: Build and Release Zed Editor
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
schedule:
|
||||
# Check daily at 2 AM for new versions
|
||||
- cron: '0 2 * * *'
|
||||
workflow_dispatch:
|
||||
# Allow manual triggering
|
||||
|
||||
jobs:
|
||||
check-version:
|
||||
runs-on: [ubuntu-latest]
|
||||
outputs:
|
||||
should_build: ${{ steps.version_check.outputs.should_build }}
|
||||
zed_version: ${{ steps.version_check.outputs.zed_version }}
|
||||
zed_version_tag: ${{ steps.version_check.outputs.zed_version_tag }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Check versions
|
||||
id: version_check
|
||||
run: |
|
||||
# Fetch the latest Zed version from GitHub
|
||||
ZED_VERSION=$(curl -s https://api.github.com/repos/zed-industries/zed/releases/latest | jq -r '.tag_name')
|
||||
ZED_VERSION_NUMBER=$(echo $ZED_VERSION | sed 's/^v//')
|
||||
|
||||
echo "Latest Zed version on GitHub: $ZED_VERSION"
|
||||
echo "zed_version=$ZED_VERSION_NUMBER" >> $GITHUB_OUTPUT
|
||||
echo "zed_version_tag=$ZED_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
# Fetch the latest release on Gitea (if it exists)
|
||||
GITEA_LATEST=$(curl -s "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/latest" | jq -r '.tag_name // "none"')
|
||||
echo "Latest Gitea release: $GITEA_LATEST"
|
||||
|
||||
# Compare versions
|
||||
if [ "$ZED_VERSION" = "$GITEA_LATEST" ]; then
|
||||
echo "Versions match ($ZED_VERSION). No build needed."
|
||||
echo "should_build=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "New version detected: $ZED_VERSION (current: $GITEA_LATEST)"
|
||||
echo "should_build=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
build-and-release:
|
||||
runs-on: [ubuntu-latest]
|
||||
needs: check-version
|
||||
if: needs.check-version.outputs.should_build == 'true'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y wget curl jq dpkg-dev
|
||||
|
||||
- name: Build DEB package
|
||||
run: |
|
||||
make all
|
||||
|
||||
- name: Get package info
|
||||
id: package_info
|
||||
run: |
|
||||
VERSION="${{ needs.check-version.outputs.zed_version }}"
|
||||
DEB_FILE="build/zed-editor_${VERSION}_amd64.deb"
|
||||
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "deb_path=$DEB_FILE" >> $GITHUB_OUTPUT
|
||||
echo "deb_filename=zed-editor_${VERSION}_amd64.deb" >> $GITHUB_OUTPUT
|
||||
|
||||
# Verify that the file exists
|
||||
if [ ! -f "$DEB_FILE" ]; then
|
||||
echo "Error: File $DEB_FILE does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Package created: $DEB_FILE"
|
||||
ls -lh "$DEB_FILE"
|
||||
|
||||
- name: Generate release notes
|
||||
id: release_notes
|
||||
run: |
|
||||
ZED_VERSION_TAG="${{ needs.check-version.outputs.zed_version_tag }}"
|
||||
|
||||
# Fetch release notes from GitHub
|
||||
RELEASE_BODY=$(curl -s "https://api.github.com/repos/zed-industries/zed/releases/tags/$ZED_VERSION_TAG" | jq -r '.body // "No release notes available."')
|
||||
|
||||
# Create release notes for Gitea
|
||||
cat > release_notes.md << 'EOF'
|
||||
## Zed Editor ${{ needs.check-version.outputs.zed_version }}
|
||||
|
||||
Unofficial Debian package for [Zed Editor](https://zed.dev/).
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
# Download and install the package
|
||||
wget https://git.rawleenc.dev/${{ gitea.repository }}/releases/download/${{ needs.check-version.outputs.zed_version_tag }}/zed-editor_${{ needs.check-version.outputs.zed_version }}_amd64.deb
|
||||
sudo dpkg -i zed-editor_${{ needs.check-version.outputs.zed_version }}_amd64.deb
|
||||
|
||||
# Or install from the APT repository (if configured)
|
||||
sudo apt update
|
||||
sudo apt install zed-editor
|
||||
```
|
||||
|
||||
### Upstream Release Notes
|
||||
|
||||
EOF
|
||||
|
||||
echo "$RELEASE_BODY" >> release_notes.md
|
||||
|
||||
# Store the content for use in the release action
|
||||
echo "notes_content<<EOF" >> $GITHUB_OUTPUT
|
||||
cat release_notes.md >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Release and upload assets
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
files: ${{ steps.package_info.outputs.deb_path }}
|
||||
title: "Zed Editor ${{ needs.check-version.outputs.zed_version }}"
|
||||
tag_name: ${{ needs.check-version.outputs.zed_version_tag }}
|
||||
body: |
|
||||
${{ steps.release_notes.outputs.notes_content }}
|
||||
|
||||
- name: Upload DEB package to Gitea repository
|
||||
if: ${{ secrets.PACKAGE_PUB_TOKEN != '' }}
|
||||
run: |
|
||||
DEB_FILE="${{ steps.package_info.outputs.deb_path }}"
|
||||
|
||||
# Extract the username from the repository
|
||||
OWNER=$(echo "${{ gitea.repository }}" | cut -d'/' -f1)
|
||||
|
||||
# Upload to Gitea Debian repository
|
||||
curl --fail --user "$OWNER:${{ secrets.PACKAGE_PUB_TOKEN }}" \
|
||||
--upload-file "$DEB_FILE" \
|
||||
"${{ gitea.server_url }}/api/packages/$OWNER/debian/pool/stable/main/upload"
|
||||
|
||||
echo "Package successfully published to Debian repository"
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: christopherhx/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: zed-editor-${{ needs.check-version.outputs.zed_version }}
|
||||
path: ${{ steps.package_info.outputs.deb_path }}
|
||||
Reference in New Issue
Block a user