Skip to content

Commit

Permalink
ci: avoid installing the toolchain from scratch in each job
Browse files Browse the repository at this point in the history
* 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 <umartinezcorral@antmicro.com>
  • Loading branch information
umarcor committed Feb 21, 2022
1 parent 4d3c60d commit 4998609
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from sys import argv as sys_argv

registry = 'ghcr.io/chipsalliance/f4pga/dev/conda'

isFork = len(sys_argv)>1 and sys_argv[1] != 'chipsalliance/f4pga-examples'

runs_on = (
Expand Down Expand Up @@ -73,19 +75,44 @@
jobs += [{
'runs-on': runs_on,
'fpga-fam': "xc7",
'os': osver[0],
'os-version': osver[1],
'example': example
'image': f'{registry}/{osver[0]}/{osver[1]}/xc7',
'example': example,
'name': f'xc7 | {osver[0]}/{osver[1]} | {example}'
} for example in examples]

jobs += [{
'runs-on': runs_on,
'fpga-fam': "eos-s3",
'os': osver[0],
'os-version': osver[1],
'example': "counter"
'image': f'{registry}/{osver[0]}/{osver[1]}/eos-s3',
'example': "counter",
'name': f'eos-s3 | {osver[0]}/{osver[1]} | counter',
} for osver in osvers]

print(f'::set-output name=matrix::{jobs!s}')
print('::set-output name=matrix::' + str(jobs))


def utils(osver):
data = {
'ubuntu': ['apt -qqy update && apt -qqy install wget locales && locale-gen $LANG'],
'debian': ['apt -qqy update && apt -qqy install wget locales && locale-gen $LANG'],
'centos': ['yum -y install wget'],
'fedora': ['dnf install -y wget'],
'centos:8': [
"sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*'",
"sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*",
]
}
idx = f"{osver[0]}:{osver[1]}"
return (data[idx] if idx in data else []) + data[osver[0]]

images = [
{
'registry': f'{registry}',
'image': f'{osver[0]}/{osver[1]}/{fam}',
'from': f'{osver[0]}:{osver[1]}',
'utils': ' && '.join(utils(osver)),
'args': f'{fam} {osver[0]}'
} for osver in osvers for fam in ['xc7', 'eos-s3']
]

print(str(jobs))
print('::set-output name=images::' + str(images))
91 changes: 64 additions & 27 deletions .github/workflows/sphinx-tuttest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,98 @@ jobs:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
images: ${{ steps.generate.outputs.images }}

steps:

- name: Setup repository
uses: actions/checkout@v2

- name: Generate examples matrix
- name: Generate matrices
id: generate
run: ./.github/scripts/generate_job_matrix.py '${{ github.repository }}'
run: ./.github/scripts/generate_matrices.py '${{ github.repository }}'


Test:
Packages:
needs: Matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.Matrix.outputs.images) }}
name: 'Image: ${{ matrix.image }}'
env:
DOCKER_BUILDKIT: 1

steps:

- name: Setup repository
uses: actions/checkout@v2
with:
submodules: recursive

- name: Build container image
run: |
docker build -t ${{ matrix.registry }}/${{ matrix.image }} . -f- <<'EOF'
FROM ${{ matrix.from }}
ENV LANG en_US.UTF-8
# Install utils
RUN ${{ matrix.utils }}
# Install tuttest
RUN wget https://github.com/antmicro/tuttest/releases/download/v0.2-beta/tuttest -O /usr/bin/tuttest \
&& chmod a+rx /usr/bin/tuttest
# Install F4PGA toolchain
RUN --mount=type=bind,target=/tmp/ctx cp -vr /tmp/ctx /tmp/repo \
&& cd /tmp/repo && bash /tmp/repo/.github/scripts/install-toolchain.sh ${{ matrix.args }} \
&& cd .. && rm -rf /tmp/repo
EOF
- name: Push container image
uses: pyTooling/Actions/with-post-step@r0
with:
main: |
echo '${{ github.token }}' | docker login ghcr.io -u GitHub-Actions --password-stdin
docker push ${{ matrix.registry }}/${{ matrix.image }}
post: docker logout ghcr.io


Test:
needs:
- Matrix
- Packages
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.Matrix.outputs.matrix) }}
runs-on: ${{ matrix.runs-on }}
name: ${{ matrix.fpga-fam }} | ${{ matrix.os }} ${{ matrix.os-version }} | ${{ matrix.example }}
name: ${{ matrix.name }}

env:
LANG: "en_US.UTF-8"
DEBIAN_FRONTEND: "noninteractive"
GHA_PREEMPTIBLE: "false"

container: ${{matrix.os}}:${{matrix.os-version}}

steps:
- name: Install utils
if: ${{matrix.os == 'ubuntu' || matrix.os == 'debian'}}
run: apt -qqy update && apt -qqy install git wget locales && locale-gen $LANG

- name: Install utils
if: ${{matrix.os == 'centos'}}
run: yum -y install git wget

- name: Install utils
if: ${{matrix.os == 'fedora'}}
run: dnf install -y git wget

- name: Setup repository
uses: actions/checkout@v2
with:
submodules: recursive

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

- name: Build examples
run: bash .github/scripts/build-examples.sh ${{matrix.fpga-fam}} ${{matrix.example}}
# Workaround for 'uses: docker://${{matrix.image}}' not being supported.
# See https://github.com/github/feedback/discussions/9049
run: >-
docker run --rm
-v $(pwd):/wrk -w /wrk
-e DEBIAN_FRONTEND="noninteractive"
${{matrix.image}}
bash .github/scripts/build-examples.sh ${{matrix.fpga-fam}} ${{matrix.example}}
- uses: actions/upload-artifact@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions docs/building-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set it to earlier, for example:
.. code-block:: bash
:name: export-install-dir
export INSTALL_DIR=~/opt/f4pga
export INSTALL_DIR=/opt/f4pga
Select your FPGA family:

Expand Down Expand Up @@ -99,7 +99,7 @@ Enter the directory that contains examples for Xilinx 7-Series FPGAs:
:file: templates/example.jinja

.. jinja:: xc7_pulse_width_led
:file: templates/example.jinja
:file: templates/example.jinja



Expand Down
2 changes: 1 addition & 1 deletion docs/getting-f4pga.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ and so you will need to add some ``sudo`` commands to the instructions below.
.. code-block:: bash
:name: conda-install-dir
export INSTALL_DIR=~/opt/f4pga
export INSTALL_DIR=/opt/f4pga
Toolchain
~~~~~~~~~
Expand Down

0 comments on commit 4998609

Please sign in to comment.