#!/usr/bin/env -S deno run --check --allow-write=. --allow-read=. --lock=./tools/deno.lock.json
// Copyright 2018-2026 the Deno authors. MIT license.
import { createWorkflow, step } from "jsr:@david/gagen@0.3.1";

const workflow = createWorkflow({
  name: "start_release",
  on: {
    workflow_dispatch: {
      inputs: {
        releaseKind: {
          description: "Kind of release",
          default: "patch",
          type: "choice",
          options: ["patch", "minor", "major"],
          required: true,
        },
      },
    },
  },
  jobs: [{
    id: "build",
    name: "start release",
    runsOn: "ubuntu-24.04",
    timeoutMinutes: 30,
    env: {
      CARGO_TERM_COLOR: "always",
      RUST_BACKTRACE: "full",
      RUSTC_FORCE_INCREMENTAL: 1,
    },
    steps: [
      step({
        name: "Configure git",
        run: [
          "git config --global core.symlinks true",
          "git config --global fetch.parallel 32",
        ],
      }),
      step({
        name: "Clone repository",
        uses: "actions/checkout@v6",
      }),
      step({
        name: "Install deno",
        uses: "denoland/setup-deno@v2",
        with: { "deno-version": "v2.x" },
      }),
      step({
        name: "Create Gist URL",
        env: {
          GITHUB_TOKEN: "${{ secrets.DENOBOT_GIST_PAT }}",
          GH_WORKFLOW_ACTOR: "${{ github.actor }}",
        },
        run:
          "./tools/release/00_start_release.ts --${{github.event.inputs.releaseKind}}",
      }),
    ],
  }],
});

const header = "# GENERATED BY ./start_release.ts -- DO NOT DIRECTLY EDIT";

export function generate() {
  return workflow.toYamlString({ header });
}

export const START_RELEASE_YML_URL = new URL(
  "./start_release.generated.yml",
  import.meta.url,
);

if (import.meta.main) {
  workflow.writeOrLint({ filePath: START_RELEASE_YML_URL, header });
}
