-
Notifications
You must be signed in to change notification settings - Fork 3
193 lines (175 loc) · 6.04 KB
/
build.yml
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: Build
on:
push:
pull_request:
jobs:
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
test:
runs-on: ubuntu-22.04
strategy:
# Do not cancel all jobs if one fails
fail-fast: false
matrix:
python_version: ["3.9"]
container_engine:
- podman
repo_type:
# Only test a subset of the repo2docker tests since we're testing podman,
# not the full repo2docker functionality
- base
- conda/py310-requirements-file
- dockerfile
# - external
# - julia
# - memlimit
# - nix
# - pipfile
# - r
- unit
- venv/default
include:
- python_version: "3.11"
container_engine: docker
repo_type: base
- python_version: "3.11"
container_engine: docker
repo_type: venv/default
- python_version: "3.11"
container_engine: nerdctl
repo_type: base
- python_version: "3.11"
container_engine: nerdctl
repo_type: venv/default
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
cache: pip
cache-dependency-path: dev-requirements.txt
- name: Install nerdctl
if: matrix.container_engine == 'nerdctl'
run: |
NERDCTL_VERSION=1.7.5
sudo systemctl disable --now docker
curl -sfL https://github.com/containerd/nerdctl/releases/download/v$NERDCTL_VERSION/nerdctl-full-$NERDCTL_VERSION-linux-amd64.tar.gz | sudo tar -zxvf - -C /usr/local
containerd-rootless-setuptool.sh install
containerd-rootless-setuptool.sh install-buildkit
- name: Install
run: |
pip install -r dev-requirements.txt
# Make a wheel and install it to catch possible issues with releases
python -m build --wheel
pip install dist/*.whl
pip freeze
- name: Fetch repo2docker tests
run: |
# Tests need to match the r2d version, need to convert YYYY.M.N to YYYY.MM.N
R2D_PY_VERSION=$(grep jupyter-repo2docker== dev-requirements.txt | cut -d= -f3)
GIT_TAG=$(echo $R2D_PY_VERSION | sed -re 's/\.([[:digit:]])\./.0\1./')
echo "Cloning repo2docker test from tag: $GIT_TAG"
git clone --depth 1 --branch=$GIT_TAG https://github.com/jupyter/repo2docker tests-repo2docker
for d in ./tests-repo2docker/tests/*/; do
if [ "${d##*tests/}" != "unit/" ]; then
cp -a $d tests
fi
done
- name: Run tests
run: |
export CONTAINER_ENGINE=${{ matrix.container_engine }}
which $CONTAINER_ENGINE
$CONTAINER_ENGINE version
pytest -v tests/${{ matrix.repo_type }}
# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
publish-pypi:
name: Pypi
needs:
# Only publish if other jobs passed
- lint
- test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install pypa/build
run: python -m pip install build
- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_API_TOKEN }}
container:
name: Build container
needs:
# Only publish if other jobs passed
- lint
- test
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get short reference (e.g. branch or tag)
# If there are multiple / (e.g. refs/prs/123/merge) use the last component
run: |
echo "SHORT_REF=${GITHUB_REF##refs*/}" >> $GITHUB_ENV
# https://www.redhat.com/en/blog/build-ubi-containers-github-actions-buildah-and-podman
- name: Buildah Action
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ env.SHORT_REF }}
containerfiles: |
./Dockerfile
- name: Log in to the GitHub Container registry
if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main')
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GitHub Container Repository
if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main')
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.REGISTRY }}
- name: Run repo2docker image
run: |
podman run ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.SHORT_REF }} repo2docker --version
# Provides a single status_all check that can be used in GitHub branch
# protection rules instead of having to list each matrix job
# https://github.community/t/status-check-for-a-matrix-jobs/127354/7
status_all:
name: Status matrix Test
if: always()
runs-on: ubuntu-22.04
needs:
- lint
- test
- publish-pypi
- container
steps:
- name: Check matrix status
run: |
result="${{ needs.test.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi