Build, Test and Publish the Dockerfile #65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2022-2023 The MathWorks, Inc. | |
name: Build, Test and Publish the Dockerfile | |
# Trigger this workflow either manually or when a new change is pushed to the | |
# repo (except .md files) | |
on: | |
workflow_dispatch: | |
push: | |
# Trigger the workflow is the Dockerfile or any file under tests/ is modified | |
paths: | |
- "Dockerfile" | |
- "tests/**" | |
- "!tests/**.md" | |
schedule: | |
# Run at 00:00 on every Monday (1st Day of the Week) | |
- cron: "0 0 * * 1" | |
env: | |
IMAGE_BASE_NAME: ghcr.io/${{ github.repository }}/matlab | |
LICENSE_FILE_PATH: ${{ github.workspace }}/license.lic | |
jobs: | |
build-test-push-image: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
matlab-release: [r2023b, r2023a, r2022b, r2022a, r2021b, r2021a, r2020b] | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build image locally | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64 | |
load: true | |
build-args: | | |
MATLAB_RELEASE=${{ matrix.matlab-release }} | |
tags: | | |
${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} | |
- name: Set up Python 3 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install test dependencies | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi | |
- name: Generate license file | |
run: echo '${{ secrets.MATLAB_LICENSE_SECRET }}' > ${{ env.LICENSE_FILE_PATH }} | |
- name: Test container | |
env: | |
IMAGE_NAME: ${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} | |
working-directory: tests | |
run: python -m unittest | |
- name: Push the image to ghcr.io | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} |