Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 92 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,66 @@ on:

env:
REGISTRY: ghcr.io
IMAGE: ghcr.io/spacedriveapp/spacebot
IMAGE: ghcr.io/${{ github.repository_owner }}/spacebot

jobs:
build:
build-binaries:
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-24.04
archive: tar.gz
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
archive: tar.gz
runs-on: ${{ matrix.runner }}
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler

- name: Determine version tag
id: version
run: |
if [ -n "${{ github.event.inputs.tag }}" ]; then
VERSION="${{ github.event.inputs.tag }}"
elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="dev-$(echo $GITHUB_SHA | head -c 7)"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Build binary
run: cargo build --release --target ${{ matrix.target }}

- name: Package binary
run: |
cd target/${{ matrix.target }}/release
mkdir -p spacebot-${{ steps.version.outputs.version }}-${{ matrix.target }}
cp spacebot spacebot-${{ steps.version.outputs.version }}-${{ matrix.target }}/
tar -czvf ../../../spacebot-${{ steps.version.outputs.version }}-${{ matrix.target }}.${{ matrix.archive }} spacebot-${{ steps.version.outputs.version }}-${{ matrix.target }}

- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: spacebot-${{ matrix.target }}
path: spacebot-${{ steps.version.outputs.version }}-${{ matrix.target }}.${{ matrix.archive }}
retention-days: 1

build-docker:
strategy:
matrix:
include:
Expand Down Expand Up @@ -81,8 +137,8 @@ jobs:
cache-from: type=gha,scope=full-${{ steps.platform.outputs.pair }}
cache-to: type=gha,mode=max,scope=full-${{ steps.platform.outputs.pair }}

merge:
needs: build
merge-docker:
needs: build-docker
runs-on: ubuntu-24.04
permissions:
contents: write
Expand All @@ -102,45 +158,70 @@ jobs:
- name: Create slim multi-arch manifest
run: |
docker buildx imagetools create \
--tag ${{ env.IMAGE }}:${{ needs.build.outputs.version }}-slim \
--tag ${{ env.IMAGE }}:${{ needs.build-docker.outputs.version }}-slim \
--tag ${{ env.IMAGE }}:slim \
${{ env.IMAGE }}:slim-linux-amd64 \
${{ env.IMAGE }}:slim-linux-arm64

- name: Create full multi-arch manifest
run: |
docker buildx imagetools create \
--tag ${{ env.IMAGE }}:${{ needs.build.outputs.version }}-full \
--tag ${{ env.IMAGE }}:${{ needs.build-docker.outputs.version }}-full \
--tag ${{ env.IMAGE }}:full \
--tag ${{ env.IMAGE }}:latest \
${{ env.IMAGE }}:full-linux-amd64 \
${{ env.IMAGE }}:full-linux-arm64

- name: Log in to Fly registry
if: github.repository_owner == 'spacedriveapp'
uses: docker/login-action@v3
with:
registry: registry.fly.io
username: x
password: ${{ secrets.FLY_API_TOKEN }}

- name: Push to Fly registry
if: github.repository_owner == 'spacedriveapp'
run: |
docker buildx imagetools create \
--tag registry.fly.io/spacebot-image:${{ needs.build.outputs.version }} \
--tag registry.fly.io/spacebot-image:${{ needs.build-docker.outputs.version }} \
--tag registry.fly.io/spacebot-image:latest \
${{ env.IMAGE }}:latest

- name: Roll out to hosted instances
if: success()
if: github.repository_owner == 'spacedriveapp'
run: |
curl -sf -X POST https://api.spacebot.sh/api/admin/rollout \
-H "Content-Type: application/json" \
-H "X-Internal-Key: ${{ secrets.PLATFORM_INTERNAL_KEY }}" \
-d '{"image_tag": "${{ needs.build.outputs.version }}"}'
-d '{"image_tag": "${{ needs.build-docker.outputs.version }}"}'

create-release:
needs: build-binaries
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Download all binary artifacts
uses: actions/download-artifact@v4
with:
path: binaries
pattern: spacebot-*
merge-multiple: false

- name: Flatten artifacts
run: |
mkdir -p release-assets
find binaries -name "*.tar.gz" -exec cp {} release-assets/ \;
ls -la release-assets/

- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.version }}
tag_name: ${{ needs.build-binaries.outputs.version }}
generate_release_notes: true
files: release-assets/*