Skip to content

Commit 723a474

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 INSTALL_DIR changed to an absolute location due to actions/runner#1525 Signed-off-by: Unai Martinez-Corral <[email protected]>
1 parent 46e7584 commit 723a474

File tree

4 files changed

+94
-37
lines changed

4 files changed

+94
-37
lines changed

.github/scripts/generate_job_matrix.py renamed to .github/scripts/generate_matrices.py

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
@@ -10,29 +10,78 @@ jobs:
1010
runs-on: ubuntu-latest
1111
outputs:
1212
matrix: ${{ steps.generate.outputs.matrix }}
13+
images: ${{ steps.generate.outputs.images }}
1314

1415
steps:
1516

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

19-
- name: Generate examples matrix
20+
- name: Generate matrices
2021
id: generate
21-
run: ./.github/scripts/generate_job_matrix.py '${{ github.repository }}'
22+
run: ./.github/scripts/generate_matrices.py '${{ github.repository }}'
2223

2324

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

3384
env:
34-
LANG: "en_US.UTF-8"
35-
DEBIAN_FRONTEND: "noninteractive"
3685
GHA_PREEMPTIBLE: "false"
3786
SURELOG_CMD: ""
3887

@@ -104,36 +153,25 @@ jobs:
104153
GHA_PREEMPTIBLE: "false"
105154
SURELOG_CMD: "-parse -DSYNTHESIS"
106155

107-
container: ${{matrix.os}}:${{matrix.os-version}}
108-
109156
steps:
110-
- name: Install utils
111-
if: ${{matrix.os == 'ubuntu' || matrix.os == 'debian'}}
112-
run: apt -qqy update && apt -qqy install git wget locales && locale-gen $LANG
113-
114-
- name: Install utils
115-
if: ${{matrix.os == 'centos'}}
116-
run: yum -y install git wget
117-
118-
- name: Install utils
119-
if: ${{matrix.os == 'fedora'}}
120-
run: dnf install -y git wget
121157

122158
- name: Setup repository
123159
uses: actions/checkout@v3
124160
with:
125161
submodules: recursive
126162

127-
- name: Install tuttest
128-
run: |
129-
wget https://github.com/antmicro/tuttest/releases/download/v0.2-beta/tuttest -O /usr/bin/tuttest
130-
chmod a+rx /usr/bin/tuttest
131-
132-
- name: Install F4PGA toolchain
133-
run: bash .github/scripts/install-toolchain.sh ${{matrix.fpga-fam}} ${{matrix.os}}
163+
- name: Pull container image
164+
run: docker pull ${{matrix.image}}
134165

135166
- name: Build examples
136-
run: bash .github/scripts/build-examples.sh ${{matrix.fpga-fam}} ${{matrix.example}}
167+
# Workaround for 'uses: docker://${{matrix.image}}' not being supported.
168+
# See https://github.com/github/feedback/discussions/9049
169+
run: >-
170+
docker run --rm
171+
-v $(pwd):/wrk -w /wrk
172+
-e DEBIAN_FRONTEND="noninteractive"
173+
${{matrix.image}}
174+
bash .github/scripts/build-examples.sh ${{matrix.fpga-fam}} ${{matrix.example}}
137175
138176
- uses: actions/upload-artifact@v3
139177
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 INSTALL_DIR=~/opt/f4pga
12+
export 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 INSTALL_DIR=~/opt/f4pga
87+
export INSTALL_DIR=/opt/f4pga
8888
8989
Setup and download assets
9090
~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)