Skip to content

Commit

Permalink
Merge pull request #19 from wmutschl/main
Browse files Browse the repository at this point in the history
Improve GitHub Action
  • Loading branch information
JohannesPfeifer authored Jul 9, 2023
2 parents 1a76fd7 + 8a47a5a commit 7eb978f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 119 deletions.
64 changes: 6 additions & 58 deletions .github/workflows/dynare-4.6.4-matlab.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,16 @@
name: Dynare 4.6.4 with MATLAB R2021a
# This uses a modified official MATLAB docker container (https://de.mathworks.com/help/cloudcenter/ug/matlab-container-on-docker-hub.html) with the following pre-installed toolboxes:
# Distrib_Computing_Toolbox, GADS_Toolbox, Optimization_Toolbox, Statistics_Toolbox, Symbolic_Toolbox, Control_Toolbox, Econometrics_Toolbox,
# using the matlab-support package to rename GCC librariers AND with a pre-compiled version of Dynare which is in the PATH of MATLAB.
# The modified container is stored in a (private) Docker registry hosted at docker.mutschler.eu, see the docker compose file here: https://github.com/wmutschl/scripts
# You will need authentification for the registry, the user name is stored in a secret called DOCKER_REGISTRY_USER and the password in a secret called DOCKER_REGISTRY_PASSWORD.
# Please ask @wmutschl or write an email to [email protected] if you want access to the registry.
# Note that the container has a size of roughly 10GB (the GitHub runner usually takes about 20 minutes to download and verify).
# More importantly, you need to provide a valid license to the container (the different options are described here: https://de.mathworks.com/help/cloudcenter/ug/matlab-container-on-docker-hub.html).
# This is a recommended way:
# 0) Check whether your license allows for cloud and container usage: https://mathworks.com/help/install/license/licensing-for-mathworks-products-running-on-the-cloud.html
# 1) Generate a license file using MATHWORKS License Center, see Option 2 https://de.mathworks.com/matlabcentral/answers/235126-how-do-i-generate-a-matlab-license-file#answer_190013
# The host id is the MAC address used below in the env block, make sure that you pass the same MAC address to the docker run command.
# The user is called matlab.
# 2) Edit the license.lic file with a text editor and remove all the blocks except for MATLAB, Distrib_Computing_Toolbox, GADS_Toolbox, Optimization_Toolbox, Statistics_Toolbox, Symbolic_Toolbox, Control_Toolbox, Econometrics_Toolbox.
# 3) Use base64 to encode the stripped down file into a Base64 string: base64 -i license.lic -o license.lic.base64 as described here https://docs.github.com/en/actions/security-guides/encrypted-secrets#storing-base64-binary-blobs-as-secrets
# 4) Copy the content of license.lic.base64 and paste it as a Github secret named MATLAB_LICENSEFILE_BASE64.

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:

env:
CONTAINER_NAME: "dynare-matlab-with-toolboxes"
DYNARE_MATLAB_VERSION: "4.6.4-r2021a"
MATLAB_LICENSEFILE_BASE64: ${{ secrets.MATLAB_LICENSEFILE_BASE64 }}
DOCKER_REGISTRY_URL: "docker.mutschler.eu"
MAC_ADDRESS_FOR_LICENSE: "A6-7E-1A-F4-9A-92"

jobs:
Run_all_files:
runs-on: ubuntu-latest

steps:

- name: login to registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY_URL }}
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

- name: pull docker container with pre-compiled Dynare and pre-configured MATLAB
run: docker pull ${{ env.DOCKER_REGISTRY_URL }}/${{ env.CONTAINER_NAME }}:${{ env.DYNARE_MATLAB_VERSION }}

- name: Retrieve the secret and decode the base64 encoded license file
run: |
echo $MATLAB_LICENSEFILE_BASE64 | base64 --decode > ${{ github.workspace }}/license.lic
- name: run_all_files.m in Docker container
run: |
docker run --rm --shm-size=512M --mac-address ${{ env.MAC_ADDRESS_FOR_LICENSE }} \
-v ${{ github.workspace }}/license.lic:/licenses/license.lic:ro \
-e MLM_LICENSE_FILE=/licenses/license.lic \
${{ env.DOCKER_REGISTRY_URL }}/${{ env.CONTAINER_NAME }}:${{ env.DYNARE_MATLAB_VERSION }} /bin/bash -c "\
cd /home/matlab && \
git clone https://github.com/JohannesPfeifer/DSGE_mod && \
cd DSGE_mod && \
git checkout ${{ github.sha }} && \
sed -i -e '/^ dynare/ s/$/ console/' run_all_files.m && \
matlab -batch 'run_all_files'"
dynare_4_6_4_matlab_r2021a:
uses: ./.github/workflows/dynare-matlab-common.yml
with:
dynare-version: "4.6.4"
secrets:
matlab-licensefile-base64: ${{ secrets.MATLAB_LICENSEFILE_BASE64 }}
64 changes: 6 additions & 58 deletions .github/workflows/dynare-5.4-matlab.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,16 @@
name: Dynare 5.4 with MATLAB R2023a
# This uses a modified official MATLAB docker container (https://de.mathworks.com/help/cloudcenter/ug/matlab-container-on-docker-hub.html) with the following pre-installed toolboxes:
# Distrib_Computing_Toolbox, GADS_Toolbox, Optimization_Toolbox, Statistics_Toolbox, Symbolic_Toolbox, Control_Toolbox, Econometrics_Toolbox,
# using the matlab-support package to rename GCC librariers AND with a pre-compiled version of Dynare which is in the PATH of MATLAB.
# The modified container is stored in a (private) Docker registry hosted at docker.mutschler.eu, see the docker compose file here: https://github.com/wmutschl/scripts
# You will need authentification for the registry, the user name is stored in a secret called DOCKER_REGISTRY_USER and the password in a secret called DOCKER_REGISTRY_PASSWORD.
# Please ask @wmutschl or write an email to [email protected] if you want access to the registry.
# Note that the container has a size of roughly 10GB (the GitHub runner usually takes about 20 minutes to download and verify).
# More importantly, you need to provide a valid license to the container (the different options are described here: https://de.mathworks.com/help/cloudcenter/ug/matlab-container-on-docker-hub.html).
# This is a recommended way:
# 0) Check whether your license allows for cloud and container usage: https://mathworks.com/help/install/license/licensing-for-mathworks-products-running-on-the-cloud.html
# 1) Generate a license file using MATHWORKS License Center, see Option 2 https://de.mathworks.com/matlabcentral/answers/235126-how-do-i-generate-a-matlab-license-file#answer_190013
# The host id is the MAC address used below in the env block, make sure that you pass the same MAC address to the docker run command.
# The user is called matlab.
# 2) Edit the license.lic file with a text editor and remove all the blocks except for MATLAB, Distrib_Computing_Toolbox, GADS_Toolbox, Optimization_Toolbox, Statistics_Toolbox, Symbolic_Toolbox, Control_Toolbox, Econometrics_Toolbox.
# 3) Use base64 to encode the stripped down file into a Base64 string: base64 -i license.lic -o license.lic.base64 as described here https://docs.github.com/en/actions/security-guides/encrypted-secrets#storing-base64-binary-blobs-as-secrets
# 4) Copy the content of license.lic.base64 and paste it as a Github secret named MATLAB_LICENSEFILE_BASE64.

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:

env:
CONTAINER_NAME: "dynare-matlab-with-toolboxes"
DYNARE_MATLAB_VERSION: "5.4-r2023a"
MATLAB_LICENSEFILE_BASE64: ${{ secrets.MATLAB_LICENSEFILE_BASE64 }}
DOCKER_REGISTRY_URL: "docker.mutschler.eu"
MAC_ADDRESS_FOR_LICENSE: "A6-7E-1A-F4-9A-92"

jobs:
Run_all_files:
runs-on: ubuntu-latest

steps:

- name: login to registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY_URL }}
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

- name: pull docker container with pre-compiled Dynare and pre-configured MATLAB
run: docker pull ${{ env.DOCKER_REGISTRY_URL }}/${{ env.CONTAINER_NAME }}:${{ env.DYNARE_MATLAB_VERSION }}

- name: Retrieve the secret and decode the base64 encoded license file
run: |
echo $MATLAB_LICENSEFILE_BASE64 | base64 --decode > ${{ github.workspace }}/license.lic
- name: run_all_files.m in Docker container
run: |
docker run --rm --shm-size=512M --mac-address ${{ env.MAC_ADDRESS_FOR_LICENSE }} \
-v ${{ github.workspace }}/license.lic:/licenses/license.lic:ro \
-e MLM_LICENSE_FILE=/licenses/license.lic \
${{ env.DOCKER_REGISTRY_URL }}/${{ env.CONTAINER_NAME }}:${{ env.DYNARE_MATLAB_VERSION }} /bin/bash -c "\
cd /home/matlab && \
git clone https://github.com/JohannesPfeifer/DSGE_mod && \
cd DSGE_mod && \
git checkout ${{ github.sha }} && \
sed -i -e '/^ dynare/ s/$/ console/' run_all_files.m && \
matlab -batch 'run_all_files'"
dynare_5_4_matlab_r2023a:
uses: ./.github/workflows/dynare-matlab-common.yml
with:
dynare-version: "5.4"
secrets:
matlab-licensefile-base64: ${{ secrets.MATLAB_LICENSEFILE_BASE64 }}
52 changes: 52 additions & 0 deletions .github/workflows/dynare-matlab-common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Common Dynare with MATLAB Workflow
# You need to provide a valid license to the container (the different options are described here: https://de.mathworks.com/help/cloudcenter/ug/matlab-container-on-docker-hub.html).
# This is a recommended way:
# 1) Check whether your license allows for cloud and container usage: https://mathworks.com/help/install/license/licensing-for-mathworks-products-running-on-the-cloud.html
# 2) Generate a license file using MATHWORKS License Center, see Option 2 https://de.mathworks.com/matlabcentral/answers/235126-how-do-i-generate-a-matlab-license-file#answer_190013
# The host id is the MAC address used below in the env block, make sure that you pass the same MAC address to the docker run command.
# The user is called matlab.
# 3) Edit the license.lic file with a text editor and remove all the blocks except for MATLAB, Distrib_Computing_Toolbox, GADS_Toolbox, Optimization_Toolbox, Statistics_Toolbox, Symbolic_Toolbox, Control_Toolbox, Econometrics_Toolbox.
# 4) Use base64 to encode the stripped down file into a Base64 string: base64 -i license.lic -o license.lic.base64 as described here https://docs.github.com/en/actions/security-guides/encrypted-secrets#storing-base64-binary-blobs-as-secrets
# 5) Copy the content of license.lic.base64 and paste it as a Github secret named MATLAB_LICENSEFILE_BASE64.

on:
workflow_call:
inputs:
dynare-version:
required: true
type: string
secrets:
matlab-licensefile-base64:
required: true

jobs:
Run_all_files:
runs-on: ubuntu-latest
env:
DYNARE_VERSION: ${{ inputs.dynare-version }}
MATLAB_LICENSEFILE_BASE64: ${{ secrets.matlab-licensefile-base64 }}
MAC_ADDRESS_FOR_LICENSE: "A6-7E-1A-F4-9A-92"
USERNAME_IN_CONTAINER: "matlab"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: pull docker container with pre-compiled Dynare and pre-configured MATLAB from Docker Hub
run: docker pull docker.io/dynare/dynare:${{ env.DYNARE_VERSION }}

- name: Retrieve the secret and decode the base64 encoded license file
run: |
echo $MATLAB_LICENSEFILE_BASE64 | base64 --decode > ${{ github.workspace }}/license.lic
- name: run_all_files.m in Docker container
run: |
docker run --rm --shm-size=512M --mac-address ${{ env.MAC_ADDRESS_FOR_LICENSE }} \
-v ${{ github.workspace }}/license.lic:/licenses/license.lic:ro \
-v ${{ github.workspace }}:/home/matlab/${{ github.event.repository.name }} \
-e MLM_LICENSE_FILE=/licenses/license.lic \
docker.io/dynare/dynare:${{ env.DYNARE_VERSION }} /bin/bash -c "\
sudo chown -R ${{ env.USERNAME_IN_CONTAINER }}:${{ env.USERNAME_IN_CONTAINER }} /home/${{ env.USERNAME_IN_CONTAINER }}/${{ github.event.repository.name }} && \
cd /home/${{ env.USERNAME_IN_CONTAINER }}/${{ github.event.repository.name }} && \
sed -i -e '/^ dynare/ s/$/ console/' run_all_files.m && \
matlab -batch 'run_all_files'"
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![DOI](https://zenodo.org/badge/34334463.svg)](https://zenodo.org/badge/latestdoi/34334463)
[![Dynare 4.6.4](https://github.com/JohannesPfeifer/DSGE_mod/actions/workflows/dynare-4.6.4-matlab.yml/badge.svg)](https://github.com/JohannesPfeifer/DSGE_mod/actions/workflows/dynare-4.6.4-matlab.yml)
[![Dynare 5.4](https://github.com/JohannesPfeifer/DSGE_mod/actions/workflows/dynare-5.4-matlab.yml/badge.svg)](https://github.com/JohannesPfeifer/DSGE_mod/actions/workflows/dynare-5.4-matlab.yml)

[![Dynare 4.6.4](../../actions/workflows/dynare-4.6.4-matlab.yml/badge.svg)](../../actions/workflows/dynare-4.6.4-matlab.yml)
[![Dynare 5.4](../../actions/workflows/dynare-5.4-matlab.yml/badge.svg)](../../actions/workflows/dynare-5.4-matlab.yml)
# DSGE_mod

A collection of Dynare models. It aims at demonstrating Dynare best practices
Expand Down

0 comments on commit 7eb978f

Please sign in to comment.