0.1.5 #15
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build and Publish | |
on: | |
release: | |
types: [published] | |
env: | |
DOCKER_IMAGE: zachrebuild/revect.io | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Setup Bun | |
uses: oven-sh/setup-bun@v1 | |
with: | |
bun-version: latest | |
- name: Install dependencies | |
run: bun install | |
- name: Run tests | |
env: | |
DATABASE_PATH: ":memory:" | |
run: bun test | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get previous release tag | |
id: prev_release | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const releases = await github.rest.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
// Find current release in the list | |
const currentReleaseTag = context.payload.release.tag_name; | |
const currentIndex = releases.data.findIndex(r => r.tag_name === currentReleaseTag); | |
// Get previous release if it exists | |
if (currentIndex >= 0 && releases.data.length > currentIndex + 1) { | |
const prevRelease = releases.data[currentIndex + 1]; | |
console.log(`Previous release: ${prevRelease.tag_name}`); | |
return prevRelease.tag_name; | |
} else { | |
console.log('No previous release found'); | |
return ''; | |
} | |
- name: Backwards compatibility check | |
if: steps.prev_release.outputs.result != '' | |
run: | | |
# Create directory for database | |
mkdir -p ./data | |
# Pull previous image | |
PREV_TAG=${{ steps.prev_release.outputs.result }} | |
docker pull ${{ env.DOCKER_IMAGE }}:${PREV_TAG} | |
# Run migrations on previous version | |
echo "Running migrations on previous version ${PREV_TAG}" | |
docker run --name prev-revect -v $(pwd)/data:/app/data ${{ env.DOCKER_IMAGE }}:${PREV_TAG} bun run /app/src/database/migrations.ts up | |
# Build current version for testing (only amd64 for testing) | |
docker build -t ${{ env.DOCKER_IMAGE }}:test . | |
# Test migrations with the new version | |
echo "Testing migrations on new version" | |
docker run --name new-revect -v $(pwd)/data:/app/data ${{ env.DOCKER_IMAGE }}:test bun run /app/src/database/migrations.ts up | |
# Cleanup | |
docker rm prev-revect new-revect | |
rm -rf ./data | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_IMAGE }} | |
tags: | | |
type=raw,value=${{ github.event.release.tag_name }} | |
type=raw,value=latest | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |