Public Access
125 lines
4.6 KiB
YAML
125 lines
4.6 KiB
YAML
name: Release Pipeline
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
|
|
jobs:
|
|
build-and-release:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "22"
|
|
|
|
- name: Install Frontend Dependencies
|
|
working-directory: ./frontend
|
|
run: npm ci --legacy-peer-deps
|
|
|
|
- name: Run Frontend Tests
|
|
working-directory: ./frontend
|
|
run: npm run test:run || echo "Tests failed or not configured, continuing..."
|
|
|
|
- name: Install Backend Dependencies
|
|
working-directory: ./backend
|
|
run: npm ci
|
|
|
|
- name: Run Backend Tests
|
|
working-directory: ./backend
|
|
run: npm run test || echo "Tests failed or not configured, continuing..."
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build amd64 Docker Image
|
|
run: docker buildx build --platform linux/amd64 --load -t brainwave:${{ github.ref_name }}-amd64 .
|
|
|
|
- name: Build arm64 Docker Image
|
|
run: docker buildx build --platform linux/arm64 --load -t brainwave:${{ github.ref_name }}-arm64 .
|
|
|
|
- name: Save Docker Images to Tarballs
|
|
run: |
|
|
docker save brainwave:${{ github.ref_name }}-amd64 | gzip > brainwave-amd64.tar.gz
|
|
docker save brainwave:${{ github.ref_name }}-arm64 | gzip > brainwave-arm64.tar.gz
|
|
|
|
- name: Generate Docker Compose Files
|
|
run: |
|
|
cat > docker-compose.amd64.yml << 'EOF'
|
|
services:
|
|
brainwave:
|
|
image: brainwave:${{ github.ref_name }}-amd64
|
|
platform: linux/amd64
|
|
ports:
|
|
- "3001:3001"
|
|
volumes:
|
|
- brainwave-db:/app/backend/db
|
|
restart: unless-stopped
|
|
volumes:
|
|
brainwave-db:
|
|
EOF
|
|
|
|
cat > docker-compose.arm64.yml << 'EOF'
|
|
services:
|
|
brainwave:
|
|
image: brainwave:${{ github.ref_name }}-arm64
|
|
platform: linux/arm64
|
|
ports:
|
|
- "3001:3001"
|
|
volumes:
|
|
- brainwave-db:/app/backend/db
|
|
restart: unless-stopped
|
|
volumes:
|
|
brainwave-db:
|
|
EOF
|
|
|
|
- name: Create Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
TAG: ${{ github.ref_name }}
|
|
run: |
|
|
# 1. Create the release
|
|
echo "Creating release for tag: ${TAG}"
|
|
RELEASE_RESPONSE=$(curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\", \"name\":\"Release ${TAG}\", \"body\":\"Automated release for version ${TAG}\", \"draft\":false, \"prerelease\":false}" \
|
|
"${SERVER_URL}/api/v1/repos/${REPOSITORY}/releases")
|
|
|
|
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('id', data.get('message', 'ERROR')))")
|
|
|
|
if [ "$RELEASE_ID" = "ERROR" ] || [ "$RELEASE_ID" = "release already exists for this tag" ]; then
|
|
echo "Release might already exist, attempting to find it..."
|
|
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${SERVER_URL}/api/v1/repos/${REPOSITORY}/releases" \
|
|
| python3 -c "import sys, json; releases=json.load(sys.stdin); print(next((r['id'] for r in releases if r['tag_name'] == '${TAG}'), 'ERROR'))")
|
|
fi
|
|
|
|
if [ "$RELEASE_ID" = "ERROR" ]; then
|
|
echo "Failed to create or find release: $RELEASE_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Uploading assets to release ID: ${RELEASE_ID}"
|
|
for FILE in brainwave-amd64.tar.gz brainwave-arm64.tar.gz docker-compose.amd64.yml docker-compose.arm64.yml; do
|
|
echo "Uploading ${FILE}..."
|
|
UPLOAD_RESPONSE=$(curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${FILE}" \
|
|
"${SERVER_URL}/api/v1/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILE}")
|
|
echo "${UPLOAD_RESPONSE}" | python3 -c "import sys, json; data=json.load(sys.stdin); exit(0 if 'id' in data else 1)" \
|
|
|| { echo "Failed to upload ${FILE}"; echo "Response: ${UPLOAD_RESPONSE}"; exit 1; }
|
|
done
|
|
echo "Release completed successfully!"
|