diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..6700406 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,92 @@ +name: CI + +on: + push: + branches: + - "**" + tags: + - "v*.*.*" + - "*.*.*" + pull_request: + +permissions: + contents: read + packages: write + +concurrency: + group: docker-${{ github.ref }} + cancel-in-progress: true + +env: + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/cloudflare-ddns-updater + +jobs: + checks: + name: ${{ matrix.check }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + check: + - typecheck + - format + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Set up Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.3.14 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Run ${{ matrix.check }} + run: bun run ${{ matrix.check }} + + build: + name: Build Docker Image + runs-on: ubuntu-latest + needs: checks + if: >- + github.event_name == 'pull_request' || + github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || + startsWith(github.ref, 'refs/tags/') + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v6 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{version}} + type=semver,pattern={{raw}} + + - name: Build and push Docker image + uses: docker/build-push-action@v7 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/package.json b/package.json index 82a85c4..c919a40 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ }, "scripts": { "typecheck": "tsc --noEmit", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "prettier --check .", + "format:fix": "prettier --write .", "dev": "bun --watch src/index.ts", "start": "bun src/index.ts", "build": "bun run typecheck",