-
Notifications
You must be signed in to change notification settings - Fork 5
128 lines (121 loc) · 4.26 KB
/
Copy pathci.yml
File metadata and controls
128 lines (121 loc) · 4.26 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
125
126
127
128
name: CI
on: [pull_request, push]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
env:
# https://github.com/pytest-dev/pytest/issues/2042#issuecomment-429289164
PY_IGNORE_IMPORTMISMATCH: 1
jobs:
pytest:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
fail-fast: false
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Build frontend bundle
# bowser.main mounts src/bowser/dist/ at import time, so the backend
# tests can't load the app without a built frontend. The dir is
# gitignored, so produce it on the runner.
run: |
npm ci
npm run build
- name: Setup pixi
uses: prefix-dev/setup-pixi@v0.9.6
with:
pixi-version: v0.65.0
cache: false
- name: Install environment
run: |
pixi install
pixi install -e all
- name: Test
run: |
pixi run -e all pytest
dockerize:
name: Build Docker image and push to GHCR
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Build frontend bundle
# Dockerfile copies src/ which must contain the built frontend at
# src/bowser/dist/. That directory is gitignored, so it has to be
# produced on the runner before `docker build` is invoked.
run: |
npm ci
npm run build
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Compute version from setuptools_scm
run: |
pip install setuptools_scm
version=$(python -m setuptools_scm)
# BOWSER_VERSION stays PEP 440 (keeps '+') — used for the build arg
# so setuptools_scm can read it back inside the image.
# BOWSER_IMAGE_TAG sanitizes '+' to '-' because Docker tags forbid '+'.
echo "BOWSER_VERSION=${version}" >> "$GITHUB_ENV"
echo "BOWSER_IMAGE_TAG=${version//+/-}" >> "$GITHUB_ENV"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build, tag, and push image to GHCR
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
build-args: |
VERSION=${{ env.BOWSER_VERSION }}
tags: |
ghcr.io/${{ github.repository }}:${{ env.BOWSER_IMAGE_TAG }}
labels: |
org.opencontainers.image.version=${{ env.BOWSER_VERSION }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
# GHA-cache layers across runs — biggest win is the pixi conda solve
# in stage 1, which otherwise re-runs from scratch each build.
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Add develop tag (main branch only)
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: akhilerm/tag-push-action@v2.3.0
with:
src: ghcr.io/${{ github.repository }}:${{ env.BOWSER_IMAGE_TAG }}
dst: ghcr.io/${{ github.repository }}:develop
- name: Add latest tag (release tags only)
if: startsWith(github.ref, 'refs/tags/v')
uses: akhilerm/tag-push-action@v2.3.0
with:
src: ghcr.io/${{ github.repository }}:${{ env.BOWSER_IMAGE_TAG }}
dst: ghcr.io/${{ github.repository }}:latest