mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-16 03:02:16 +00:00
ci.yml also triggered on push to master/tags, so every such push ran the suite twice: once standalone, once as docker.yml's publish gate. Drop the push trigger; the gate becomes the only master/tag run, and docker waits on it — one suite run per commit, and a red suite still blocks the image. The gate runs on every non-PR push (its own `changes` job skips a docs-only diff), so a push touching no build input is still tested. A release tag runs the live-network suite through the gate, via an explicit `live` input computed by the caller (the called workflow's github.ref is not a dependable tag check).
187 lines
8.8 KiB
YAML
187 lines
8.8 KiB
YAML
name: CI
|
|
|
|
# Test/lint gate (offline, no secrets). Standalone on pull requests, schedule
|
|
# and manual dispatch; a master/tag push does not trigger it directly — that
|
|
# push is tested once, by docker.yml's `ci` gate, which calls this workflow
|
|
# with `gate: true` and blocks the image on the result.
|
|
#
|
|
# Layering:
|
|
# changes — decides whether anything but documentation changed; a docs-only
|
|
# diff skips `test` (which then reports as skipped, not missing).
|
|
# test — fmt + clippy + the full offline unit suite + a release-profile
|
|
# build + cargo-audit dependency gate. Runs on PRs, and for a
|
|
# master/tag push under the docker gate; no secrets needed.
|
|
# live — the #[ignore]d live-network tests plus the pixiv tests that are
|
|
# gated on PIXIV_REFRESH_TOKEN. Runs on schedule / manual dispatch,
|
|
# and on a release tag (through the docker gate), because pull
|
|
# requests from forks cannot read repository secrets.
|
|
# continue-on-error keeps a flaky external site from blocking,
|
|
# while the run still records the outcome.
|
|
#
|
|
# Every action is pinned to a commit SHA (Dependabot keeps the pins current);
|
|
# `dtolnay/rust-toolchain` deliberately stays on its channel ref, because the
|
|
# ref itself is what selects the toolchain (`@stable` = install stable).
|
|
#
|
|
# Test gating convention (keep in sync with AGENTS.md "Testing & QA"):
|
|
# - pure unit tests: plain #[test] / #[tokio::test], always run.
|
|
# - live-network tests: #[ignore = "live network: ..."], only run here.
|
|
# - token-gated tests (pixiv): #[tokio::test] with an early return when
|
|
# PIXIV_REFRESH_TOKEN is absent or empty (empty = unset CI secret).
|
|
|
|
on:
|
|
pull_request:
|
|
schedule:
|
|
# Weekly probe of the live endpoints, so external API changes surface.
|
|
- cron: '0 3 * * 1'
|
|
workflow_dispatch:
|
|
# Called by docker.yml as the publish gate. `gate` marks that call: its
|
|
# concurrency group is separate from the standalone run on the same ref, and
|
|
# it never cancels a superseded run, because each gate run carries its own
|
|
# commit's image (a docs-only follow-up must not drop the code commit's).
|
|
workflow_call:
|
|
inputs:
|
|
gate:
|
|
type: boolean
|
|
default: false
|
|
# Passed by docker.yml for a release tag: the caller computes it from its
|
|
# own `github.ref`, so the called workflow needs no ref check of its own.
|
|
# A string (not boolean) on purpose: a boolean input fed by an expression
|
|
# arrives as the string "true"/"false", and "false" is truthy in `if`.
|
|
live:
|
|
description: Run the live-network suite too (docker passes "true" on a release tag).
|
|
type: string
|
|
default: 'false'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
# A newer push to the same ref supersedes the older run; without this every
|
|
# intermediate commit of a PR branch keeps a runner busy to completion.
|
|
concurrency:
|
|
group: ci-${{ inputs.gate && 'gate-' || '' }}${{ github.ref }}
|
|
cancel-in-progress: ${{ !inputs.gate }}
|
|
|
|
env:
|
|
# Panicking tests print their backtrace; free when nothing fails.
|
|
RUST_BACKTRACE: 1
|
|
|
|
jobs:
|
|
# Docs-only changes skip the heavy job: a README edit does not need a four
|
|
# minute Rust build (and it cannot break one). A gate job rather than a
|
|
# workflow-level `paths` filter — that leaves the run without a `test` check
|
|
# at all, and a required status check then waits for something that will
|
|
# never be reported, while a *skipped* job reports as neutral.
|
|
changes:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
outputs:
|
|
code: ${{ steps.diff.outputs.code }}
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
with:
|
|
fetch-depth: 0 # the diff below needs the pushed range
|
|
- id: diff
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
zero=0000000000000000000000000000000000000000
|
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
base="origin/${{ github.base_ref }}"
|
|
git fetch --quiet --no-tags origin "${{ github.base_ref }}"
|
|
changed="$(git diff --name-only "$base...HEAD")"
|
|
else
|
|
before="${{ github.event.before }}"
|
|
if [ -z "$before" ] || [ "$before" = "$zero" ]; then
|
|
# New branch or force push: no usable base to compare against,
|
|
# so the full suite runs. Same for schedule/dispatch, which have
|
|
# no `before` at all.
|
|
changed=""
|
|
else
|
|
changed="$(git diff --name-only "$before..${{ github.sha }}")"
|
|
fi
|
|
fi
|
|
# Only a change that is *entirely* markdown may skip the job;
|
|
# anything else — and an empty diff, i.e. a re-run of the same
|
|
# commit — counts as code.
|
|
code=true
|
|
if [ -n "$changed" ] && ! grep -qvE '\.md$' <<<"$changed"; then
|
|
code=false
|
|
fi
|
|
echo "changed: ${changed:-<no diff>}"
|
|
echo "code=$code" >> "$GITHUB_OUTPUT"
|
|
|
|
test:
|
|
needs: changes
|
|
if: needs.changes.outputs.code == 'true'
|
|
runs-on: ubuntu-latest
|
|
# Generous on purpose: the release-profile build below is cold on the very
|
|
# first run (thin LTO + codegen-units = 1 across every dependency), and a
|
|
# timeout there would kill the job *before* rust-cache saves its cache —
|
|
# leaving every later run cold again.
|
|
timeout-minutes: 45
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
components: clippy, rustfmt
|
|
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
|
|
# `--locked` on every cargo invocation: the version bump edits
|
|
# Cargo.lock by hand (AGENTS.md), so a stale lock must fail here instead
|
|
# of being silently re-resolved — otherwise CI tests a different
|
|
# dependency set than the one committed, and than the one the released
|
|
# image is built from.
|
|
- name: Check formatting
|
|
run: cargo fmt --check
|
|
- name: Lint (deny warnings)
|
|
run: cargo clippy --workspace --all-targets --locked -- -D warnings
|
|
- name: Run offline tests
|
|
run: cargo test --workspace --locked
|
|
# The release profile (lto/strip/codegen-units=1, overflow checks off)
|
|
# was otherwise only exercised by the Docker build on master/tag. Same
|
|
# package the Dockerfile builds; the cache keeps it cheap after the
|
|
# first run.
|
|
- name: Build release profile
|
|
run: cargo build --release --locked -p xmedia-bot
|
|
# Dependency vulnerability gate: fails the build when a crate in
|
|
# Cargo.lock has an unfixed security advisory. Unmaintained/unsound
|
|
# *warnings* (dotenv, proc-macro-error2, anyhow transitive) do not fail
|
|
# the build by default; the advisory DB is cached across runs.
|
|
- name: Audit dependencies
|
|
uses: actions-rust-lang/audit@72c09e02f132669d52284a3323acdb503cfc1a24 # v1
|
|
|
|
live:
|
|
needs: test
|
|
if: ${{ inputs.live == 'true' || (!inputs.gate && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')) }}
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
continue-on-error: true
|
|
env:
|
|
PIXIV_REFRESH_TOKEN: ${{ secrets.PIXIV_REFRESH_TOKEN }}
|
|
TWITTER_AUTH_TOKEN: ${{ secrets.TWITTER_AUTH_TOKEN }}
|
|
BILIBILI_COOKIE: ${{ secrets.BILIBILI_COOKIE }}
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
- uses: dtolnay/rust-toolchain@stable
|
|
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
|
|
# All #[ignore]d live tests, by the "live" name filter, in both crates:
|
|
# the bot crate has two of its own (repair refetch, text-only link)
|
|
# whose fetches are network-bound but whose sends go through MockSender.
|
|
# --show-output keeps each test's stdout — the SKIP lines printed by a
|
|
# skipped test are what the summary step below greps, so a skip stays
|
|
# distinguishable from a pass.
|
|
- name: Run live-network tests (x-media)
|
|
run: cargo test -p x-media --locked -- --ignored live --show-output 2>&1 | tee live-x-media.log
|
|
- name: Run live-network tests (xmedia-bot)
|
|
run: cargo test -p xmedia-bot --locked -- --ignored live --show-output 2>&1 | tee live-bot.log
|
|
# A green live run must not be able to mean "nothing actually ran"
|
|
# (pixiv without its secret, bilibili risk-controlling the runner IP):
|
|
# collect every SKIP line into the run summary.
|
|
- name: Surface skipped live tests
|
|
if: always()
|
|
run: |
|
|
skips=$(grep -h '^SKIP ' live-*.log 2>/dev/null || true)
|
|
if [ -n "$skips" ]; then
|
|
echo "::warning::live job skipped tests, see the job summary"
|
|
{ echo "### Live tests skipped"; echo "$skips" | sed 's/^/- /'; } >> "$GITHUB_STEP_SUMMARY"
|
|
fi
|