diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..3afc472 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,81 @@ +name: Continuous Integration + +on: + push: + branches: [main] + tags: ['v*'] + pull_request: + branches: [main] + +env: + REGISTRY: gitea.lucaswinther.info + +jobs: + lint-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + - name: Install dependencies + run: bun install --frozen-lockfile + - name: Typecheck + run: bunx tsc --noEmit + - name: Run test suite + run: bun test + - name: Build app + run: bun run build + + docker-build-and-push: + runs-on: ubuntu-latest + needs: [lint-and-test] + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Gitea's job token cannot publish packages; use a package-write PAT. + - name: Log in to Gitea Container Registry + if: gitea.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ gitea.actor }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ gitea.repository }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=branch + type=semver,pattern={{version}} + type=sha,prefix=sha- + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ gitea.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Pull and smoke-test published image + if: gitea.event_name != 'pull_request' + env: + PUBLISHED_TAGS: ${{ steps.meta.outputs.tags }} + run: | + image="$(printf '%s\n' "$PUBLISHED_TAGS" | head -n 1)" + docker pull "$image" + docker run -d --rm -p 3000:3000 --name budget2-ci "$image" + trap 'docker stop budget2-ci' EXIT + for i in $(seq 1 30); do + if curl -fsS http://localhost:3000/ > /dev/null; then break; fi + sleep 1 + done + curl -fsS http://localhost:3000/ | grep -q "Budget" + curl -fsS http://localhost:3000/sw.js > /dev/null + curl -fsS http://localhost:3000/manifest.webmanifest > /dev/null diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3afc472..9261a06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,77 +1,31 @@ -name: Continuous Integration +name: CI on: push: branches: [main] - tags: ['v*'] pull_request: - branches: [main] - -env: - REGISTRY: gitea.lucaswinther.info jobs: - lint-and-test: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 with: bun-version: latest - - name: Install dependencies - run: bun install --frozen-lockfile - - name: Typecheck - run: bunx tsc --noEmit - - name: Run test suite - run: bun test - - name: Build app - run: bun run build + - run: bun install --frozen-lockfile + - run: bun test + - run: bunx tsc --noEmit + - run: bun run build - docker-build-and-push: + docker: runs-on: ubuntu-latest - needs: [lint-and-test] steps: - uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # Gitea's job token cannot publish packages; use a package-write PAT. - - name: Log in to Gitea Container Registry - if: gitea.event_name != 'pull_request' - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ gitea.actor }} - password: ${{ secrets.REGISTRY_TOKEN }} - - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ gitea.repository }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=ref,event=branch - type=semver,pattern={{version}} - type=sha,prefix=sha- - - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - push: ${{ gitea.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Pull and smoke-test published image - if: gitea.event_name != 'pull_request' - env: - PUBLISHED_TAGS: ${{ steps.meta.outputs.tags }} + - run: docker build -t budget2 . + - name: Serve the image and check it responds run: | - image="$(printf '%s\n' "$PUBLISHED_TAGS" | head -n 1)" - docker pull "$image" - docker run -d --rm -p 3000:3000 --name budget2-ci "$image" - trap 'docker stop budget2-ci' EXIT + docker run -d --rm -p 3000:3000 --name budget2 budget2 for i in $(seq 1 30); do if curl -fsS http://localhost:3000/ > /dev/null; then break; fi sleep 1 @@ -79,3 +33,4 @@ jobs: curl -fsS http://localhost:3000/ | grep -q "Budget" curl -fsS http://localhost:3000/sw.js > /dev/null curl -fsS http://localhost:3000/manifest.webmanifest > /dev/null + docker stop budget2