How to skip a configuration of a matrix with GitHub actions? - workflow

I have the following job on GitHub actions. And I would to like to skip the macOS x86 configuration: is there a way to do this?
build-and-push-native-libraries:
name: Build and push native library on ${{ matrix.os }} ${{ matrix.architecture }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macOS, windows-latest]
java: [15]
architecture: [x86, x64]
include:
- compiler: gcc
gcc: 8
runs-on: ${{ matrix.os }}
steps:
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java#v1
with:
java-version: ${{ matrix.java }}
architecture: ${{ matrix.architecture }}
- uses: actions/checkout#v2
- if: startsWith(matrix.os, 'ubuntu') == true
name: Change the permissions of the build script of external classes
run: chmod +x ./java/src/main/resources/compileExternalClasses.sh
- name: Build and push native library
run: |
mvn -B clean package -DskipTests=true --file ./native/pom.xml
git config user.name "${{ github.event.head_commit.committer.name }}"
git config user.email "${{ github.event.head_commit.committer.email }}"
git pull origin experimental
git commit -am "Generated library for ${{ matrix.os }} ${{ matrix.architecture }}" --allow-empty
git push

You can use exclude
You can remove a specific configurations defined in the build matrix using the exclude option. Using exclude removes a job defined by the build matrix. The number of jobs is the cross product of the number of operating systems (os) included in the arrays you provide, minus any subtractions (exclude).
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-18.04]
node: [8, 10, 12, 14]
exclude:
# excludes node 8 on macOS
- os: macos-latest
node: 8
In your case it would be:
matrix:
os: [ubuntu-latest, macOS, windows-latest]
java: [15]
architecture: [x86, x64]
include:
- compiler: gcc
gcc: 8
exclude:
- os: macOS

Related

Github actions not including variable

I have a github actions workflow like this:
name: Print test type
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
test_type: ['test-alpha', 'test-beta']
os: [ubuntu-latest]
python-version: ['3.7', '3.9']
include:
- os: windows-latest
python-version: '3.8'
runs-on: ${{ matrix.os }}
steps:
- name: Print Alpha
if: ${{ matrix.test_type == 'test-alpha'}}
run: echo "test type is alpha. the os name is ${{ runner.os }}"
- name: Print Beta
if: ${{ matrix.test_type == 'test-beta'}}
run: echo "test type is beta. the os name is ${{ runner.os }}"
When I run this workflow, the windows CI starts and completes but it is not showing any output. In particular, the if statements are not getting executed. Am I missing some point here? Because when I include the test-type in matrix, I expect to also see windows X py3.8 X {alpha, beta} combination in workflow.
In the ubuntu CI, it works fine - getting executed for all combinations in the matrix (ubuntu X {py3.7,py3.9} X {alpha,beta}.)
The include method does not work here because Github tries to extend the already existing run configurations. If this does not work (which is the case here), then a new configuration is created for each include. (For more information: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations)
In your case, however, the new created configurations do not contain a specified test-type. Now there are two possibilities. Either add the test-type manually:
name: Print test type
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
test_type: ['test-alpha', 'test-beta']
os: [ubuntu-latest]
python-version: ['3.7', '3.9']
include:
- os: windows-latest
python-version: '3.8'
test_type: 'test-alpha'
- os: windows-latest
python-version: '3.8'
test_type: 'test-beta'
runs-on: ${{ matrix.os }}
steps:
- name: Print Alpha
if: ${{ matrix.test_type == 'test-alpha'}}
run: echo "test type is alpha. the os name is ${{ runner.os }}"
- name: Print Beta
if: ${{ matrix.test_type == 'test-beta'}}
run: echo "test type is beta. the os name is ${{ runner.os }}"
or remove the unwanted combinations:
name: Print test type
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
test_type: ['test-alpha', 'test-beta']
os: [ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9']
exclude:
- os: windows-latest
python-version: '3.7'
- os: windows-latest
python-version: '3.9'
- os: ubuntu-latest
python-version: '3.8'
runs-on: ${{ matrix.os }}
steps:
- name: Print Alpha
if: ${{ matrix.test_type == 'test-alpha'}}
run: echo "test type is alpha. the os name is ${{ runner.os }}"
- name: Print Beta
if: ${{ matrix.test_type == 'test-beta'}}
run: echo "test type is beta. the os name is ${{ runner.os }}"

Github Workflow Matrix Contion PHP Version Composer Require

I'm trying to build a composer library that I would like to be compatible back to PHP 7.0 but for this to work I need to use different PHPUnit versions.
I am trying to update the require component based on if-statements, but either none of them or all of them run. I don't really understand why.
I have tried to take inspiration from this post:
github-action: does the IF have an ELSE?
name: PHP CI
on:
pull_request:
branches:
- "master"
workflow_dispatch:
jobs:
render-php:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: ["ubuntu-latest"]
php-versions: ["7.0", "7.4", "8.0"]
phpunit-versions: ["latest"]
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0
- run: git merge origin/master --no-commit --ff-only
- uses: shivammathur/setup-php#v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: phpunit:${{ matrix.phpunit-versions }}
- run: echo "${{ matrix.php-versions }}"
- name: "PHP 7.0"
if: "${{ matrix.php-versions }} == 7.0"
run: composer require --dev --with-all-dependencies --no-install phpunit/phpunit 6.0
- name: "PHP 7.4"
if: "${{ matrix.php-versions }} == 7.4"
run: composer require --dev --with-all-dependencies --no-install phpunit/phpunit 8.0
- name: "PHP >8.0"
if: "${{ matrix.php-versions }} >= 8.0"
run: composer require --dev --with-all-dependencies --no-install phpunit/phpunit
- run: composer install
- run: ./vendor/bin/phpunit
What exactly am I doing wrong or not understanding properly?
It was me who did not understand the way IF-statements worked, it should be states as such instead:
if: ${{ matrix.php-versions == 7.0 }}

Flake8 CI Worflow GitHub

Trying to implement flake8 inside a workflow in github is causing me error because is not recognising .flake8 file.
It works perfectly from the terminal:
[flake8]
max-line-length = 79
exclude =
migrations
views.py
tests.py
serializers.py
models.py
When I try to apply it to the .yml file of Django it's giving error because doesn't take in account the config file:
name: Django CI
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.8, 3.9]
steps:
- uses: actions/checkout#v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python#v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
cd scoretize_backend/
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with Flake8
run: flake8 scoretize_backend/
- name: Run Tests
run: |
cd scoretize_backend/
python manage.py test
I've tried to add a new workflow just for this but same case:
name: flake8 Lint
on: [push, pull_request]
jobs:
flake8-lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout#v2
- name: Set up Python environment
uses: actions/setup-python#v2
with:
python-version: "3.9"
exclude: "./scoretize_backend/api/models.py"
- name: flake8 Lint
uses: py-actions/flake8#v2
Tried to add with & exclude but it's not working. Could I config this with the .flake8 file? Thank you so much.
Thank you Anthony! I had the file inside the Django app but the workflow needed the file on the top of the directories. Solved.

AWS CI/CD with GItHub Actions and Code Deploy to the EC2 instance

I am trying to do ci/cd with github actions and aws code deploy to the ec2 instance.
I have one ec2 instance and three github repositories(each repository has their own gitflow as well)
name: Deployment
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
buildAndTest:
name: CI Pipeline
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ '14.x' ]
steps:
- uses: actions/checkout#v2
# Initialize Node.js
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
# Install project dependencies, test and build
- name: Install dependencies
run: yarn
- name: Run build
run: yarn build
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['14.x']
appname: ['app_name']
deploy-group: ['group_name']
region: ['region']
needs: [buildAndTest]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout#v2
# Initialize Node.js
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
# Step 1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ matrix.region }}
# Step 2
- name: Create CodeDeploy Deployment
id: deploy
run: |
aws deploy create-deployment \
--application-name ${{ matrix.appname }} \
--deployment-group-name ${{ matrix.deploy-group }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--github-location repository=${{ github.repository }},commitId=${{ github.sha }}
It works good when I push or do pull request to one repo, but when I push two repo at once which means I am gonna push and deploy concurrently, only one is success and another one is failed.
version: 0.0
os: linux
files:
- source: .
destination: /var/www/source
hooks:
ApplicationStart:
- location: deploy.sh // yarn install and restart server.
timeout: 300
runas: root
What is really curious is that except main location(in ec2), some files excluding build or so in other repos(two) are removed ???
I am using the same application and group id for three repositories and Is it a problem?
Any help would be super helpful :)
AWS CodeDeploy application group can not make two deployments at the same time.

Upload Multiple (Parallel) Files to a Single Release

I'm quite new to github actions. I already managed to build my C++ program using CMAKE for ubuntu-latest and windows-latest, now I'm having problems uploading it to a release.
I'm using a strategy matrix, so the different OS jobs run in parallel.
My goal is to upload build files to a single Release Tag in which each file will have a custom name based on OS platform.
ex.:
Release Tag: V0.2.0
Files: main_0.2.0_windows.exe
main_0.2.0_ubuntu
...
main_0.2.0_other-OS.ext
Can someone help me to do so? Below is my current workflow yml.
** I already managed to upload single files to single release tags for ubuntu-latest. For windows-latest I got an error saying that the file to upload is not found :( .
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
trigger:
required: false
default: 'workflow_dispatcher'
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
VERSION: 0.2.0
jobs:
build:
strategy:
matrix:
platform: [ ubuntu-latest, windows-latest ]
python-version: ['2.7', '3.6']
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team#latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout#v2
- uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip & setuptools
run: python -m pip install --upgrade pip setuptools
- name: Install matplotlib & numpy
run: python -m pip install matplotlib numpy
- name: Copy numpy core to include folder
run: python ${{github.workspace}}/cp-numpy-core.py
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target main
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
- name: Rename Ubuntu Files
if: ${{ matrix.platform == 'ubuntu-latest' }}
run: mv ${{github.workspace}}/build/main ${{github.workspace}}/build/main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}
- name: Rename Windows Files
if: ${{ matrix.platform == 'windows-latest' }}
run: Ren "${{github.workspace}}\build\${{ env.BUILD_TYPE }}\main.exe" "${{github.workspace}}\build\${{ env.BUILD_TYPE }}\main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}.exe"
- name: Upload Artifacts
- uses: "marvinpinto/action-automatic-releases#latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ env.BUILD_TYPE }}${{ env.VERSION }}/${{ matrix.platform }}/Python${{ matrix.python-version }}"
prerelease: true
title: "${{ env.BUILD_TYPE }} V${{ env.VERSION }} - OS: ${{ matrix.platform }} - Python: ${{ matrix.python-version }}"
files: |
${{github.workspace}}/build/main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}
${{github.workspace}}\build\${{ env.BUILD_TYPE }}\main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}.exe
Best regards & Keep coding!
Solved by using svenstaro/upload-release-action#2.2.1, that allowed me to upload assets to releases. The only downside is that I had to implement a different step for windows and ubuntu.
workflow action:
name: Build and Publish Pre Release
on:
push:
branches: [ master ]
workflow_dispatch:
inputs:
trigger:
required: false
default: 'workflow_dispatcher'
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build-source:
# Environment where to build
strategy:
matrix:
platform: [ ubuntu-latest, windows-latest ]
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9' ]
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team#latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout#v2
- uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade Pip & Setuptools
run: python -m pip install --upgrade pip setuptools
- name: Install Matplotlib & Numpy
run: python -m pip install matplotlib numpy
- name: Copy Numpy Core to Include Folder
run: python ${{github.workspace}}/cp-numpy-core.py
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build Source
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target main
- name: Test Build
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
- name: Upload Files to a GitHub Release (Ubuntu)
if: ${{ matrix.platform == 'ubuntu-latest' }}
uses: svenstaro/upload-release-action#2.2.1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/main
asset_name: main-linux_amd64-python${{ matrix.python-version }}
tag: latest
overwrite: true
prerelease: true
body: "${{ env.BUILD_TYPE }} for ${{ matrix.platform }}"
- name: Upload Files to a GitHub Release (Windows)
if: ${{ matrix.platform == 'windows-latest' }}
uses: svenstaro/upload-release-action#2.2.1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build\${{ env.BUILD_TYPE }}\main.exe
asset_name: main-windows_amd64-python${{ matrix.python-version }}.exe
tag: latest
overwrite: true
prerelease: true
body: "${{ env.BUILD_TYPE }} for ${{ matrix.platform }}"