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 }}"
Related
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 }}
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.
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
I have a github action which is building the React app (based on create-react-app) and deploying it to AWS S3. I have to pass some environment variables to correctly run yarn build command.
I could hold them directly in .env file, but I don't want to hold them inside the repository. Currently I'm just adding environment variables right before the yarn build command, but it's annoying solution and seems to be a bit hacky. Ideally, I'd like to inject .env.local file with my own configuration, but I don't have any good idea how to do it.
Here's my build.yml file:
name: Build
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.13.1]
steps:
- uses: actions/checkout#v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Yarn install
run: yarn install
- name: Build
run: REACT_APP_GRAPHQL_URL=https://some.url/graphql CI=false yarn build
- name: Deploy to S3
uses: jakejarvis/s3-sync-action#master
with:
args: --acl public-read --delete
env:
AWS_S3_BUCKET: my-bucket-name
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: "build"
So as you can see the magic happens here:
run: REACT_APP_GRAPHQL_URL=https://some.url/graphql CI=false yarn build
How can I make it look nicer? It's quite ok when I have two variables, but what if I'll have dozens of them?
By the way - it's a private repository, if it makes any difference.
And I don't want to use another CI solution, currently Github Actions seems to be enough for me.
you can do magic like this,
name: Build
on:
push:
branches:
- master
env:
CI : false
REACT_APP_GRAPHQL_URL : https://some.url/graphql
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.13.1]
steps:
- uses: actions/checkout#v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Yarn install
run: yarn install
- name: Build
run: yarn build
- name: Deploy to S3
uses: jakejarvis/s3-sync-action#master
with:
args: --acl public-read --delete
env:
AWS_S3_BUCKET: my-bucket-name
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: "build"
I think it makes look nicer
Below workflow fails when deploying the artifacts to S3. In the last line, in the deployment job, it's complaining that ./build doesn't exist, probably because it can't find the artifacts.
The user-provided path ./build does not exist.
##[error]Process completed with exit code 255.
How do I make it recognise the artifacts created in the build job?
name: Build and deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-18.04
strategy:
matrix:
node-version: [10.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 i -D
npm test --if-present
npm run build:prod
env:
CI: true
- name: Upload Artifact
uses: actions/upload-artifact#master
with:
name: build
path: build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout#master
- name: Deploy to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws s3 cp \
--recursive \
--acl public-read \
--region ap-southeast-2 \
./build s3://example
You need to download the artifact in the deploy job. See the actions/download-artifact action.
deploy:
name: Deploy
needs: build
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout#master
- name: Download Artifact
uses: actions/download-artifact#master
with:
name: build
path: build
- name: Deploy to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws s3 cp \
--recursive \
--acl public-read \
--region ap-southeast-2 \
./build s3://example