diff --git a/.github/workflows/colour-demo.yml b/.github/workflows/colour-demo.yml deleted file mode 100644 index 3963d71b..00000000 --- a/.github/workflows/colour-demo.yml +++ /dev/null @@ -1,268 +0,0 @@ -# Demonstration workflow for #506 / #622. Builds the CLI at three points in -# history and prints `octopus --help` under a matrix of colour environment -# variables, so the behaviour can be seen in a real CI log rather than described. -# -# GitHub Actions renders ANSI colour in logs but does not attach a TTY, which is -# exactly the situation #506 is about. The second job re-runs the cases that only -# apply to a terminal under a pty allocated with `script`. -# -# This is a demo, not part of the build. It only runs on this branch and on -# manual dispatch, and can be deleted before merge. -name: Colour output demo (#506) - -on: - workflow_dispatch: - push: - branches: [nj/fix-506] - -env: - # The commit the reviewer tested: the PR before the FORCE_COLOR=0 fix. - PR_V1_SHA: ab6d3b5f2dd2d5ebaa4d16a8408ab18085e61516 - -jobs: - build: - name: Build the three binaries - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - - - name: Build main (before the PR) - run: | - git worktree add /tmp/src-main origin/main - cd /tmp/src-main && go build -o /tmp/octopus-main ./cmd/octopus - - - name: Build the PR as reviewed - run: | - git worktree add /tmp/src-pr-v1 "$PR_V1_SHA" - cd /tmp/src-pr-v1 && go build -o /tmp/octopus-pr-v1 ./cmd/octopus - - - name: Build the PR with the review fix - run: go build -o /tmp/octopus-pr-v2 ./cmd/octopus - - - uses: actions/upload-artifact@v4 - with: - name: binaries - path: /tmp/octopus-* - retention-days: 1 - - no-tty: - name: 'Issue #506: colour in CI (no TTY)' - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v4 - with: - name: binaries - path: /tmp - - run: chmod +x /tmp/octopus-* - - # Look at the logo in each step below. Cyan means colour is on. - - - name: 'BEFORE (main) — no env vars — plain, correct' - run: /tmp/octopus-main --help | head -22 - - - name: 'BEFORE (main) — FORCE_COLOR=1 — still plain, THIS IS THE BUG' - env: - FORCE_COLOR: '1' - run: /tmp/octopus-main --help | head -22 - - # GitHub's log viewer resets SGR state at every line break. The PR as - # reviewed wrapped the whole logo in one escape, so the codes were present - # but nothing rendered. Compare the next two steps. - - name: 'AS REVIEWED — FORCE_COLOR=1 — escapes emitted, but renders white here' - env: - FORCE_COLOR: '1' - run: /tmp/octopus-pr-v1 --help | head -22 - - - name: 'AFTER (PR) — no env vars — plain, deliberately unchanged' - run: /tmp/octopus-pr-v2 --help | head -22 - - - name: 'AFTER (PR) — FORCE_COLOR=1 — cyan, THIS IS THE FIX' - env: - FORCE_COLOR: '1' - run: /tmp/octopus-pr-v2 --help | head -22 - - - name: 'AFTER (PR) — CLICOLOR_FORCE=1 — cyan, equivalent opt-in' - env: - CLICOLOR_FORCE: '1' - run: /tmp/octopus-pr-v2 --help | head -22 - - - name: 'AFTER (PR) — FORCE_COLOR=1 + NO_COLOR=1 — plain, NO_COLOR wins' - env: - FORCE_COLOR: '1' - NO_COLOR: '1' - run: /tmp/octopus-pr-v2 --help | head -22 - - # The step above is only convincing if the colour is actually per line, so - # check that rather than trusting the screenshot. - - name: 'Assert the logo is coloured line by line' - env: - FORCE_COLOR: '1' - run: | - esc=$'\033[' - for label in pr-v1 pr-v2; do - total=$(/tmp/octopus-$label --help | grep -cF '####') - bare=$(/tmp/octopus-$label --help | grep -F '####' | grep -cvF "$esc" || true) - echo "$label: $total logo lines, $bare without an escape of their own" - done - - bare=$(/tmp/octopus-pr-v2 --help | grep -F '####' | grep -cvF "$esc" || true) - if [ "$bare" -ne 0 ]; then - echo "::error::$bare logo lines carry no escape; they will render plain in this log" - exit 1 - fi - - - name: Assert and summarise - run: | - esc=$'\033[' - fail=0 - - # colour_of [VAR=VALUE ...] -> "colour" | "plain" - colour_of() { - local bin="$1"; shift - if env "$@" "$bin" --help 2>&1 | grep -qF "$esc"; then - echo colour - else - echo plain - fi - } - - # expect