diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75c25b2..ae91a5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.64.5 + version: v2.12.2 args: --timeout=5m vuln: @@ -55,8 +55,10 @@ jobs: go-version-file: go.mod cache: true - name: build + shell: bash run: go build ./... - name: test + shell: bash run: go test -race -coverprofile=coverage.out -covermode=atomic ./... - name: upload coverage if: matrix.os == 'ubuntu-latest' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79e420e..06dc8d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,17 +47,31 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - name: Set up QEMU + if: env.DOCKERHUB_USERNAME != '' uses: docker/setup-qemu-action@v3 + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - name: Set up Docker Buildx + if: env.DOCKERHUB_USERNAME != '' uses: docker/setup-buildx-action@v3 + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + + - name: Compute goreleaser skip flags + id: skip + run: | + flags="" + [ -z "${{ secrets.DOCKERHUB_USERNAME }}" ] && flags="$flags --skip=docker" + [ -z "${{ secrets.TAP_GITHUB_TOKEN }}" ] && flags="$flags --skip=homebrew,scoop" + echo "flags=$flags" >> "$GITHUB_OUTPUT" - name: Run GoReleaser uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: "~> v2" - args: release --clean + args: release --clean ${{ steps.skip.outputs.flags }} env: # Default token can create the release on this repo. The # external tap/bucket repos need a PAT with `repo` scope diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e6b7579..abccea5 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -129,4 +129,4 @@ checksum: release: github: owner: ararahq - name: arara-cli + name: cli diff --git a/go.mod b/go.mod index 1ddf545..8c64e3e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ararahq/cli -go 1.26.1 +go 1.26.2 require ( github.com/charmbracelet/bubbles v1.0.0 diff --git a/workers/install-cli/README.md b/workers/install-cli/README.md new file mode 100644 index 0000000..fcb310e --- /dev/null +++ b/workers/install-cli/README.md @@ -0,0 +1,34 @@ +# arara-install-cli (Cloudflare Worker) + +Serve os scripts de instalação do AraraHQ CLI em `get.ararahq.com`. + +``` +GET https://get.ararahq.com/install-cli → install.sh (Unix) +GET https://get.ararahq.com/install-cli.ps1 → install.ps1 (Windows) +GET https://get.ararahq.com/ → 302 docs.ararahq.com/cli +``` + +Os scripts são puxados de `raw.githubusercontent.com/ararahq/cli/main/`. Cache de 5min na borda da Cloudflare. + +## Deploy + +1. **Instale o Wrangler** (uma vez): `npm i -g wrangler` +2. **Login**: `wrangler login` +3. **Deploy**: dentro deste diretório, `wrangler deploy` +4. **Custom domain**: dashboard Cloudflare → Workers → `arara-install-cli` → Settings → Triggers → Add Custom Domain → `get.ararahq.com` + +DNS é criado automaticamente quando você adiciona o custom domain (Cloudflare resolve internamente). + +## Testar antes do deploy + +```bash +wrangler dev +curl http://127.0.0.1:8787/install-cli +``` + +## Validar produção + +```bash +curl -fsSL https://get.ararahq.com/install-cli | head -20 +curl -I https://get.ararahq.com/install-cli.ps1 +``` diff --git a/workers/install-cli/src/worker.js b/workers/install-cli/src/worker.js new file mode 100644 index 0000000..b3c8f4a --- /dev/null +++ b/workers/install-cli/src/worker.js @@ -0,0 +1,56 @@ +const REPO = "ararahq/cli"; +const SH_URL = `https://raw.githubusercontent.com/${REPO}/main/install.sh`; +const PS1_URL = `https://raw.githubusercontent.com/${REPO}/main/install.ps1`; +const DOCS_URL = "https://docs.ararahq.com/cli"; + +const SH_HEADERS = { "Content-Type": "text/x-shellscript; charset=utf-8" }; +const PS1_HEADERS = { "Content-Type": "text/plain; charset=utf-8" }; +const CACHE_HEADER = { "Cache-Control": "public, max-age=300" }; + +export default { + async fetch(request) { + const url = new URL(request.url); + const ua = (request.headers.get("User-Agent") || "").toLowerCase(); + const looksLikeShell = /curl|wget|fetch/.test(ua); + + if (url.pathname === "/install-cli" || url.pathname === "/install-cli.sh") { + return proxy(SH_URL, SH_HEADERS); + } + + if (url.pathname === "/install-cli.ps1") { + return proxy(PS1_URL, PS1_HEADERS); + } + + // Root: serve install.sh when called by curl/wget (so `curl ... | sh` works), + // otherwise redirect humans to the docs. + if (url.pathname === "/" || url.pathname === "") { + if (looksLikeShell) { + return proxy(SH_URL, SH_HEADERS); + } + return Response.redirect(DOCS_URL, 302); + } + + return new Response("Not found. Try /install-cli or /install-cli.ps1\n", { + status: 404, + headers: { "Content-Type": "text/plain; charset=utf-8" }, + }); + }, +}; + +async function proxy(upstream, contentHeaders) { + const upstreamResponse = await fetch(upstream, { + cf: { cacheTtl: 300, cacheEverything: true }, + }); + + if (!upstreamResponse.ok) { + return new Response(`Upstream fetch failed (${upstreamResponse.status})\n`, { + status: 502, + headers: { "Content-Type": "text/plain; charset=utf-8" }, + }); + } + + return new Response(upstreamResponse.body, { + status: 200, + headers: { ...contentHeaders, ...CACHE_HEADER }, + }); +} diff --git a/workers/install-cli/wrangler.toml b/workers/install-cli/wrangler.toml new file mode 100644 index 0000000..ce8e9f0 --- /dev/null +++ b/workers/install-cli/wrangler.toml @@ -0,0 +1,10 @@ +name = "arara-install-cli" +main = "src/worker.js" +compatibility_date = "2025-01-01" + +# Custom domain attached via dashboard: +# get.ararahq.com → this worker +# Worker handles: +# GET /install-cli → install.sh (Unix) +# GET /install-cli.ps1 → install.ps1 (Windows) +# GET / → redirect to docs.ararahq.com/cli