Repository navigation
124 lines (106 loc) · 4.19 KB
/
Copy pathci.yml
File metadata and controls
124 lines (106 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: CI
# One workflow, one job graph:
#
# check ──→ image (main, release tags and manual runs: publish to GHCR)
#
# A pull request runs check alone. The image is built and published only once
# the code on main, or a release tag, has passed every check. A manual run
# publishes the chosen branch's image too, but only main moves `latest`.
on:
pull_request:
# Run by hand from the Actions tab, on any branch or tag.
workflow_dispatch:
push:
branches: [main]
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
# To publish the image to this repository's GHCR package.
packages: write
jobs:
# Every gate pre-commit runs, again, since hooks can be skipped.
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
# --locked fails if uv.lock disagrees with pyproject.toml, so a dependency
# added without its lockfile fails here rather than resolving afresh.
- name: Install
run: uv sync --locked
- name: Lint
run: uv run ruff check .
- name: Check formatting
run: uv run ruff format --check .
- name: Type check
run: uv run pyright
- name: Dead code
run: uv run vulture
# The e2e tier needs a running DSS; the `e2e` marker keeps it out of the
# default run (pyproject.toml). Coverage is printed and sent to Codecov,
# not gated. The XML report is written here only, not on local runs.
- name: Test
run: uv run pytest --cov-report=xml
# `!cancelled()`: a failing run is when the line-by-line report helps most.
# The job still fails; this only keeps the report.
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
# Named explicitly: without it Codecov resolves the repo from the token
# alone, which fails with an unclear "Repository not found".
slug: ${{ github.repository }}
files: ./coverage.xml
fail_ci_if_error: true
# Not on pull requests: one has already had every check, and an image it will
# never publish would cost a build on every push.
image:
if: github.event_name != 'pull_request'
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# GHCR names must be lowercase; the owner is "OpenAgriNet".
- name: Set image name
run: echo "IMAGE=ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
# `main` or the release tag, with any slash made safe for a tag.
- name: Set image tag
run: echo "TAG=$(echo '${{ github.ref_name }}' | tr '/' '-')" >> "$GITHUB_ENV"
# The ref (main, v1.2.0, a branch run by hand) and the exact commit. Only
# main also moves `latest`, so a manual run from a branch cannot replace
# what a deployment pulls.
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ env.IMAGE }}:${{ env.TAG }}
${{ env.IMAGE }}:${{ github.sha }}
${{ github.ref == 'refs/heads/main' && format('{0}:latest', env.IMAGE) || '' }}
# Links the package to this repository on GitHub, so it appears on the
# repo page and inherits its access.
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
# Reuse layers from earlier runs, so only what changed is rebuilt.
cache-from: type=gha
cache-to: type=gha,mode=max