Github Workflow Matrix Contion PHP Version Composer Require - github

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 }}

Related

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.

Github Actions - Cypress

I followed official Cypress documentation, and below I will attach my github workflow, but problem is it goes different way in my case. When actions run, Cypress starts downloading something, but it never ends (I waited 1.5 hour).
env:
NODE_PATH: 'src/'
#.. local env
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [ 14.x ]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- name: Server start
uses: cypress-io/github-action#v2
with:
build: npm run build
start: npm start
spec: cypress/integration/*.js
env:
ELECTRON_ENABLE_STACK_DUMPING: 1
- name: Exist check
# Only runs if all of the files exists
run: |
if [ -d "/..." ]
then
rm -r /...
mv build /...
fi
Problem is old version of ubuntu. change version or mention it in yaml.

how to run GitHub Action after outage?

As you may (or may not) know yesterday was a major incident of GitHub's services: https://www.githubstatus.com/incidents/tyc8wpsgr2r8.
Unfortunately I published a release during that time and the action responsible for building and publishing the code didn't trigger.
For actions which were executed at least once I have an option to "Re-run workflow" - but how can I proceed with an action which didn't even trigger - I can not see it anywhere whatsoever?
I think the last resort would be to just make another release, remove the problematic one etc. but I'd like to avoid that.
The workflow file:
name: Node.js CI
on:
push:
branches: [master]
release:
types: [published]
pull_request:
branches: [master]
jobs:
test:
name: Test Node.js v${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 16
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install --production=false --no-package-lock
- name: Lint 💅🏻
run: npm run lint
- run: npm test
release:
name: Publish NPM Package
if: startsWith(github.ref, 'refs/tags/')
needs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm install --production=false --no-package-lock
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
gh-pages:
name: Publish GitHub Pages
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
needs:
- test
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- name: Install ✔️
run: npm install --production=false --no-package-lock
- name: Build storybook 🏗️
run: npm run build-storybook
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action#4.1.3
with:
branch: gh-pages
folder: storybook-static
As you said in the comment, the easiest solution would be to remove the release and create it all over again.
Another option could be to add a workflow_dispatch event trigger to the workflow with a tag input, updating the jobs condition to use this input.tag variable if informed.
That way, if an automatic trigger failed (through push, release or pull_request), you could trigger it manually through the Github UI or the GH CLI as an alternative.

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

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

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 }}"