I've just discovered Github workflows and I've been trying to create two for a private C++ repository of mine, which contains a small C++ library.
I've succeeded in creating one that runs on Ubuntu (i.e., it runs and completes successfully), but the other that runs on Windows (almost an exact copy of that one that runs on Ubuntu) fails due to a missing C library.
This is the .yml file of the workflow that runs on Windows:
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# the directory of the library's source code (and which contains the CMakeLists.txt)
LAL_DIR: D:\a\linear-arrangement-library\linear-arrangement-library/lal
# directories of the different builds
REL_DIR: ${{github.workspace}}/windows-build-release
DEB_DIR: ${{github.workspace}}/windows-build-debug
jobs:
windows_build:
runs-on: windows-2019
steps:
- uses: actions/checkout#v2
- name: Configure CMake on Windows
run: cmake -G "MSYS Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ${{env.LAL_DIR}} -B ${{env.REL_DIR}} -DCMAKE_BUILD_TYPE=Release ;
cmake -G "MSYS Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ${{env.LAL_DIR}} -B ${{env.DEB_DIR}} -DCMAKE_BUILD_TYPE=Debug
- name: Build on Windows
run: cmake --build ${{env.REL_DIR}} --config Release -j4 ;
cmake --build ${{env.DEB_DIR}} --config Debug -j4
I'm new on this, so I don't know if I applied the "best practices" (if there are any).
The error I get is the following:
In file included from D:/a/linear-arrangement-library/linear-arrangement-library/lal/generate/rand_ulab_rooted_trees.hpp:50,
from D:/a/linear-arrangement-library/linear-arrangement-library/lal/generate/rand_ulab_free_trees.hpp:50,
from D:/a/linear-arrangement-library/linear-arrangement-library/lal/generate/rand_ulab_free_trees.cpp:42:
D:/a/linear-arrangement-library/linear-arrangement-library/lal/numeric/integer.hpp:45:10: fatal error: gmp.h: No such file or directory
#include <gmp.h>
^~~~~~~
compilation terminated.
The error is telling me that g++ can't find the file gmp.h. The workflow running on Ubuntu, however, does not fail.
I guess that the system executing Ubuntu's workflow simply has the gmp library installed, whereas the one executing Window's workflow doesn't. How can I resolve this? (if it is actually possible, that is)
Thank you very much.
Related
I have a GitHub Actions workflow job that seems like a simple thing, but one that I'm really struggling to implement.
Essentially I want to use rsync to copy several files from the checkout repository to another existing folder in the checkout repository. Here is a snippet of my action:
steps:
- name: Checkout
uses: actions/checkout#v3
with:
token: ${{ secrets.token }}
fetch-depth: '0'
- name: Rsync Test Files
working-directory: ./tests/amazon-linux-2/integration-test
run: |
rsync -av ../../../ . --exclude tests --exclude .github --exclude .releaserc --exclude README.md --exclude .git
There are several files and folders in the root of the checkout repo that I want to copy to ./tests/amazon-linux-2/integration-test. For info, tests is a folder in the project root.
The error I'm getting from the Rsync Test Files step is:
OCI runtime exec failed: exec failed: unable to start container process: chdir to cwd ("/__w/<repo name>/<repo name>/./tests/amazon-linux-2/integration-test") set in config.json failed: no such file or directory: unknown
Two things confuse me that may or may not be related to the problem. There is an additional . between and tests. Also, the repo name is appearing twice in the path.
I have tried setting the working directory of the Rsync Test Files tasks in multiple places and tweking the rsync command accordingly, but nothing works, with variations of the same error.
I noticed when I was trying to run my github workflow to deploy my dockerized VUE app to Elastic Beanstalk that I kept getting an error in my logs saying no eslint config found, since I had just a handful of ignore lines.
So when I added a step in the workflow to ls the files being checked out, I saw it did not grab any of the files formatted as .*.
I would assume it should at least be getting the .eslintrc.* file since it is supposed to come featured to run npm install and npm run lint it would look at the checked out config file to determine if the rules pass.
Here is my workflow up to this point:
name: Deploy to Staging Environment
on: [workflow_dispatch]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Latest Repo
uses: actions/checkout#v2
- name: List Checked Out files
run: ls
# DOES NOT SHOW ANY .* files checked out
Is anyone else noticing the same? What should I try?
I'm quite new to using Actions, and I'm having some trouble. My YML file looks like this:
name: Build
on:
workflow_dispatch:
push:
branches: ["main", "master"]
jobs:
build:
runs-on: windows-latest
steps:
- name: Build with py2exe
run: |
pip install py2exe
cd app
python setup.py py2exe
I'm trying to compile app/main.py into a .exe file. I'm able to run these commands from my Windows 10 computer, but with Actions, it fails with:
Line |
3 | cd app
| ~~~~~~
| Cannot find path 'D:\a\Pokemon-PythonRed\Pokemon-PythonRed\app' because it does not exist.
I'm sure there's an app directory, you can check for yourself here.
What am I doing wrong? Thank you in advance.
You need to check out the repo to access it in the workflow:
https://github.com/actions/checkout
I use GitHub for source control my HTML, CSS and JS. I use Netlify / Cloudflare Pages to host my website (which is trigger off of a GitHub commit).
I work with static files (.html, .js and .css) and do not use programming frameworks like Ruby on Rails, Django, etc.
I’d like to create a GitHub Action that triggers on a git commit, to do the following:
a. Purge unused CSS.
b. Minify the HTML, CSS and JS
c. In-line the CSS & JS into the HTML file.
That way my site is minified, merged and purged of unused elements before it is automatically hosted by Netlify / Cloudflare Pages.
How would I go about doing this with GitHub Actions? I’ve looked into esbuild, webpack etc but all seem to come up short of being able to do all I need.
My approach to this is a Github action that:
checks out the main branch
performs the minification/purging etc
pushes the changes to a build branch
Then you just need to point Github Pages (or Netlify in your case) at the build branch rather than the main branch.
You'd need to choose appropriate CLI tools to perform the minifying/purging in the virtual machine that the action spins up. There are lots of options here. I'd suggest using packages that can be installed through node so that you only have to install that on the VM. For example:
PurgeCSS: Removes unneeded CSS
terser: Minifies JS
csso-cli: Minifies CSS
html-minifier: Minifies HTML
I'm not aware of any tools that you could use to inline your JS/CSS (and don't know why you'd want to), but I suspect they exist.
This is relatively straightforward with a Github action that looks a bit like this:
# A Github Action that minifies html/css/js and pushes it to a new branch
name: purge-and-minify
on:
push:
branches:
- 'main'
jobs:
checkout-minify-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
# Install CLI tools
- uses: actions/setup-node#v3
with:
node-version: '16'
- run: npm install -g terser
- run: npm install -g csso-cli
- run: npm install -g html-minifier
# Use CLI tools to minify, overwriting existing files
- run: for i in ./js/*.js; do terser $i --compress -o $i; done
- run: for i in ./css/*.css; do csso $i -o $i; done
- run: for i in ./html/*.html; do html-minifier [--your-options-here] $i -o $i; done
# Push changes to `build` branch
- run: |
git config user.name github-username
git config user.email github-username#user.noreply.github.com
git commit -am 'Automated minify of ${{ github.sha }}'
git push --force -u origin main:build
I just start with GitHub Actions and I'm trying to configure correctly jobs. Now I have a job - build which set up python and installs dependencies, I have a job with behave test too which needs the dependencies to run.
When I have the test and build in the one job, everything works fine. But I want to have build and test in separate jobs. But when I run them in this configuration, I get the error behave: command not found. I install the Behave in requirementx.txt file. What am I doing wrong? Is this configuration generally possible?
name: CI test
on:
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Python 3.8
uses: actions/setup-python#v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
cc_test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Run cc test
run: |
behave --no-capture --no-skipped -t guest -t cc -D driver=BROWSERSTACK features
As riQQ and documentation says
A job is a set of steps that execute on the same runner. By default, a workflow with multiple jobs will run those jobs in parallel. You can also configure a workflow to run jobs sequentially. For example, a workflow can have two sequential jobs that build and test code, where the test job is dependent on the status of the build job. If the build job fails, the test job will not run.
In your case it would be the best to have one job build and test and do both things in this one job. Putting tests in separate jobs can be a good move, but it would require one of two:
prepare testable package in previous step and share it (it could still requires to install some dependencies)
checkout code, install dependencies, build code and run tests what means that you need to repeat all steps from previous job