Skip to content

Commit c21bdd4

Browse files
committed
ci: avoid installing the toolchain from scratch in each job
* Use GitHub Packages * Use container in a step, instead of a container job F4PGA_INSTALL_DIR changed to an absolute location due to actions/runner#1525 Signed-off-by: Unai Martinez-Corral <[email protected]>
1 parent 69268da commit c21bdd4

File tree

4 files changed

+94
-37
lines changed

4 files changed

+94
-37
lines changed
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from sys import argv as sys_argv
2020

21+
registry = 'ghcr.io/chipsalliance/f4pga/dev/conda'
22+
2123
isFork = len(sys_argv)>1 and sys_argv[1] != 'chipsalliance/f4pga-examples'
2224
usesSurelog = len(sys_argv)>2 and sys_argv[2] == 'Surelog'
2325

@@ -85,19 +87,36 @@
8587
jobs += [{
8688
'runs-on': runs_on,
8789
'fpga-fam': "xc7",
88-
'os': osver[0],
89-
'os-version': osver[1],
90-
'example': example
90+
'image': f'{registry}/{osver[0]}/{osver[1]}/xc7',
91+
'example': example,
92+
'name': f'xc7 | {osver[0]}/{osver[1]} | {example}'
9193
} for example in examples]
9294

9395
jobs += [{
9496
'runs-on': runs_on,
9597
'fpga-fam': "eos-s3",
96-
'os': osver[0],
97-
'os-version': osver[1],
98-
'example': "counter"
98+
'image': f'{registry}/{osver[0]}/{osver[1]}/eos-s3',
99+
'example': "counter",
100+
'name': f'eos-s3 | {osver[0]}/{osver[1]} | counter',
99101
} for osver in osvers]
100102

101-
print(f'::set-output name=matrix::{jobs!s}')
103+
print('::set-output name=matrix::' + str(jobs))
104+
105+
utils = {
106+
'ubuntu': 'apt -qqy update && apt -qqy install wget locales && locale-gen $LANG',
107+
'debian': 'apt -qqy update && apt -qqy install wget locales && locale-gen $LANG',
108+
'centos': 'yum -y install wget',
109+
'fedora': 'dnf install -y wget'
110+
}
111+
112+
images = [
113+
{
114+
'registry': f'{registry}',
115+
'image': f'{osver[0]}/{osver[1]}/{fam}',
116+
'from': f'{osver[0]}:{osver[1]}',
117+
'utils': utils[osver[0]],
118+
'args': f'{fam} {osver[0]}'
119+
} for osver in osvers for fam in ['xc7', 'eos-s3']
120+
]
102121

103-
print(str(jobs))
122+
print('::set-output name=images::' + str(images))

.github/workflows/sphinx-tuttest.yml

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,82 @@ jobs:
1111
outputs:
1212
matrix: ${{ steps.generate.outputs.matrix }}
1313
surelog-matrix: ${{ steps.generate-surelog.outputs.matrix }}
14+
images: ${{ steps.generate.outputs.images }}
1415

1516
steps:
1617

1718
- name: Setup repository
1819
uses: actions/checkout@v3
1920

20-
- name: Generate examples matrix
21+
- name: Generate matrices
2122
id: generate
22-
run: ./.github/scripts/generate_job_matrix.py '${{ github.repository }}'
23+
run: ./.github/scripts/generate_matrices.py '${{ github.repository }}'
24+
25+
26+
Packages:
27+
needs: Matrix
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include: ${{ fromJson(needs.Matrix.outputs.images) }}
33+
name: 'Image: ${{ matrix.image }}'
34+
env:
35+
DOCKER_BUILDKIT: 1
36+
37+
steps:
38+
39+
- name: Setup repository
40+
uses: actions/checkout@v2
41+
with:
42+
submodules: recursive
43+
44+
- name: Build container image
45+
run: |
46+
docker build -t ${{ matrix.registry }}/${{ matrix.image }} . -f- <<'EOF'
47+
FROM ${{ matrix.from }}
48+
49+
ENV LANG en_US.UTF-8
50+
51+
# Install utils
52+
RUN ${{ matrix.utils }}
53+
54+
# Install tuttest
55+
RUN wget https://github.com/antmicro/tuttest/releases/download/v0.2-beta/tuttest -O /usr/bin/tuttest \
56+
&& chmod a+rx /usr/bin/tuttest
57+
58+
# Install F4PGA toolchain
59+
RUN --mount=type=bind,target=/tmp/ctx cp -vr /tmp/ctx /tmp/repo \
60+
&& cd /tmp/repo && bash /tmp/repo/.github/scripts/install-toolchain.sh ${{ matrix.args }} \
61+
&& cd .. && rm -rf /tmp/repo
62+
EOF
63+
64+
- name: Push container image
65+
if: ${{ github.event_name != 'pull_request' }}
66+
uses: pyTooling/Actions/with-post-step@r0
67+
with:
68+
main: |
69+
echo '${{ github.token }}' | docker login ghcr.io -u GitHub-Actions --password-stdin
70+
docker push ${{ matrix.registry }}/${{ matrix.image }}
71+
post: docker logout ghcr.io
2372

2473
- name: Generate examples matrix
2574
id: generate-surelog
2675
run: ./.github/scripts/generate_job_matrix.py '${{ github.repository }}' Surelog
2776

2877

2978
Test:
30-
needs: Matrix
79+
needs:
80+
- Matrix
81+
- Packages
3182
strategy:
3283
fail-fast: false
3384
matrix:
3485
include: ${{ fromJson(needs.Matrix.outputs.matrix) }}
3586
runs-on: ${{ matrix.runs-on }}
36-
name: ${{ matrix.fpga-fam }} | ${{ matrix.os }} ${{ matrix.os-version }} | ${{ matrix.example }}
87+
name: ${{ matrix.name }}
3788

3889
env:
39-
LANG: "en_US.UTF-8"
40-
DEBIAN_FRONTEND: "noninteractive"
4190
GHA_PREEMPTIBLE: "false"
4291
SURELOG_CMD: ""
4392

@@ -99,36 +148,25 @@ jobs:
99148
GHA_PREEMPTIBLE: "false"
100149
SURELOG_CMD: "-parse -DSYNTHESIS"
101150

102-
container: ${{matrix.os}}:${{matrix.os-version}}
103-
104151
steps:
105-
- name: Install utils
106-
if: ${{matrix.os == 'ubuntu' || matrix.os == 'debian'}}
107-
run: apt -qqy update && apt -qqy install git wget locales && locale-gen $LANG
108-
109-
- name: Install utils
110-
if: ${{matrix.os == 'centos'}}
111-
run: yum -y install git wget
112-
113-
- name: Install utils
114-
if: ${{matrix.os == 'fedora'}}
115-
run: dnf install -y git wget
116152

117153
- name: Setup repository
118154
uses: actions/checkout@v3
119155
with:
120156
submodules: recursive
121157

122-
- name: Install tuttest
123-
run: |
124-
wget https://github.com/antmicro/tuttest/releases/download/v0.2-beta/tuttest -O /usr/bin/tuttest
125-
chmod a+rx /usr/bin/tuttest
126-
127-
- name: Install F4PGA toolchain
128-
run: bash .github/scripts/install-toolchain.sh ${{matrix.fpga-fam}} ${{matrix.os}}
158+
- name: Pull container image
159+
run: docker pull ${{matrix.image}}
129160

130161
- name: Build examples
131-
run: bash .github/scripts/build-examples.sh ${{matrix.fpga-fam}} ${{matrix.example}}
162+
# Workaround for 'uses: docker://${{matrix.image}}' not being supported.
163+
# See https://github.com/github/feedback/discussions/9049
164+
run: >-
165+
docker run --rm
166+
-v $(pwd):/wrk -w /wrk
167+
-e DEBIAN_FRONTEND="noninteractive"
168+
${{matrix.image}}
169+
bash .github/scripts/build-examples.sh ${{matrix.fpga-fam}} ${{matrix.example}}
132170
133171
- uses: actions/upload-artifact@v3
134172
with:

docs/building-examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set it to earlier, for example:
99
.. code-block:: bash
1010
:name: export-install-dir
1111
12-
export F4PGA_INSTALL_DIR=~/opt/f4pga
12+
export F4PGA_INSTALL_DIR=/opt/f4pga
1313
1414
Select your FPGA family:
1515

docs/getting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ and so you will need to add some ``sudo`` commands to the instructions below.
8484
.. code-block:: bash
8585
:name: conda-install-dir
8686
87-
export F4PGA_INSTALL_DIR=~/opt/f4pga
87+
export F4PGA_INSTALL_DIR=/opt/f4pga
8888
8989
Setup and download assets
9090
~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)