name: Release

on:
  push:
    branches: [main]

jobs:
  release-please:
    name: Make release

    runs-on: ubuntu-latest

    permissions:
      contents: write
      pull-requests: write

    outputs:
      release_created: ${{ steps.release-please-run.outputs.release_created }}
      tag_name: ${{ steps.release-please-run.outputs.tag_name }}

    steps:
      - uses: googleapis/release-please-action@v4
        id: release-please-run
        with:
          release-type: simple
          package-name: catppuccin/nix

  publish:
    name: Publish to Flake registries
    if: ${{ needs.release-please.outputs.release_created }}
    needs: release-please

    runs-on: ubuntu-latest

    env:
      TAG_NAME: ${{ needs.release-please.outputs.tag_name }}

    permissions:
      id-token: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ref: ${{ env.TAG_NAME }}

      - name: Install Nix
        uses: cachix/install-nix-action@V27

      - name: Publish on Flakestry
        uses: flakestry/flakestry-publish@main
        with:
          version: ${{ env.TAG_NAME }}

      - name: Push to FlakeHub
        uses: DeterminateSystems/flakehub-push@v5
        with:
          tag: ${{ env.TAG_NAME }}
          visibility: "public"
