Github action not uploading artifact - workflow

I'm having an issue with uploading artifacts to github from within a workflow.
This is my yaml file:
on:
push:
branches:
- master
jobs:
build:
name: build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Install robotframework and dependencies
run: |
pip install selenium
pip install robotframework
pip install robotframework-seleniumlibrary
pip install robotframework-imaplibrary
pip install robotframework-httplibrary
pip install robotframework-requests
- name: Download and install chromedriver
run: |
wget http://chromedriver.storage.googleapis.com/77.0.3865.10/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip -d /usr/local/bin
export CHROME_BIN=chromium-browser
- name: Run robot tests
run: |
cd robot/tests
python -m robot -i ready bookingform.robot
- name: publish test results
uses: actions/upload-artifact#v1
with:
name: report
path: report.html
- name: clean up stuff
run: |
history
pwd
Everything runs fine up until "publish test results", at which point nothing is written to the logs and no artifacts are uploaded. If I view the workflow log, there is a grey icon alongside that step (not the usual check or red x), so I'm really baffled at what could be happening. I added arbitrary stuff to the "clean up stuff" step just to test what happens, and that step isn't run either.
I've tried messing around with the path, thinking that it could be related to the path being invalid or something, but that hasn't helped. No matter what I add near the bottom of that file, the same behaviour occurs.
I have tried running another workflow file which uploads artifacts and that ran fine, the logs showed that the upload action was invoked and that the artifact was saved, but I don't see anything like that when my yaml file is used.

Each job step resets the working path to GITHUB_WORKSPACE, which will be the root of your repository after actions/checkout runs.
The upload-artifact action most likely can't find report.html because it's no longer in the correct directory.
Try changing the path as follows:
- name: publish test results
uses: actions/upload-artifact#v1
with:
name: report
path: robot/tests/report.html
There is also a working-directory that you can set for a step. However, it seems to be incompatible with uses for actions. It can only apply to run script steps.
Using working-directory with uses will NOT work:
- name: publish test results
working-directory: robot/tests
uses: actions/upload-artifact#v1
with:
name: report
path: report.html
Using working-directory with run will work:
- name: print test results
working-directory: robot/tests
run: cat report.html

Tasks are not executed, if previous Tasks have failed; see Status check functions.
Using if: ${{ failure() }} a Task only executes, if the previous Task has failed.
So for me it solved the Problem to add if: ${{ failure() }}:
- name: Upload Cypress Artifacts
if: ${{ failure() }}
uses: actions/upload-artifact#v3
with:
path: ./cypress

Related

Github Actions: warning about set-output, but not using it

I am using a GitHub actions to "build" a python app (running linting, code coverage, and tests). At the end of the action I get the following warning:
1 warning
build
The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
but my python-app.yml does not use set-output:
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout#v3
- name: Set up Python 3.10
uses: actions/setup-python#v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with pylint
run: |
pylint src
continue-on-error: false
- name: Test with pytest
run: |
pytest
- name: pytest coverage
run:
pytest --cov=./ --cov-report=xml:tests/coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action#v3
and so I am not sure how to amend my .yml in order to make it compliant for the future.
In your workflow, there may be indirect dependencies on actions that have yet not been updated for GITHUB_OUTPUT against the set-output deprecation.
You need to check all the actions in your workflow one by one for version updates with the set-output fix.
In your case, visiting https://github.com/actions/setup-python reveals that there's a new version available. And, searching for the set-output string in the repo results in relevant references e.g. issues, commit, etc. For example, this issue (https://github.com/actions/setup-python/issues/578) verifies that it has been fixed in #v4.
So, as of now, using #v4 should fix it i.e.:
- uses: actions/setup-python#v4
The actions are being updated gradually. Hopefully, all of them will be updated soon and we won't be seeing that warning anymore.

GitHub actions unable to run wdio test

I've been trying to get github actions to do the CI part of this particular test that has been created however, I also encounter a similar error when running the test. The test works locally, so that's great. When it's solely being ran with GitHub actions, it doesn't.
I first see a warning:
WARN #wdio/mocha-framework: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
which eventually becomes an error on the test:
ERROR #wdio/runner: Error: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
What else do I need to do in GitHub actions to get this to run the test and pass as it should?
The yml file has been set up to do the following:
name: CI
on: [push, pull_request]
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Install Chromium
run: sudo apt-get install chromium-browser
- uses: actions/setup-node#v1
with:
node-version: 18
- name: Install
run: npm install
- name: Test
run: npx wdio wdio.git.js
- uses: actions/upload-artifact#v1
if: failure()
with:
name: logs
path: logs
You can also see the repo here: https://github.com/saucechaffe/sauceonsauceoff
I've attempted to change the yml file to configure different things, I've read that it isn't necessary to build chrome on the ubuntu machine but on some hands it is so I've left it in there for now. I've also attempted this: How to run WebdriverIO tests with GitHub Actions? but just keep getting stuck in the process.
Resolved this by removing a line of code that required chrome webdriver as it was causing the error and wasn't needed/being used.

Working directory is not working in my Github action

I'm starting to use Github actions. When I ran the process in my Ubuntu server, one of the config options was to select the work folder, by default, I leave _work. But previously, I had my repository in another folder.
So, I'm trying to add a specific value for working-directory to my yml, file but is not using the value in the build process.
YML File:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
defaults:
run:
working-directory: /../../../../var/www/mysite.com
jobs:
deployment:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Use Node.js
uses: actions/setup-node#v3
with:
node-version: '14.x'
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Restart server application
run: pm2 restart pm2_script.json
The process ran ok, but is doing all the process (checkout, build, etc) inside _work and not inside working-directory
What I'm doing wrong?
Thanks!!

Pytest not finding tests on GitHub actions

I'm trying to generate code coverage for a python package I work on and created a GitHub action to do this, which uses the codecov-action. The workflow looks like this:
name: Code Coverage
on: [push]
jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout#master
- name: Setup Python
uses: actions/setup-python#master
with:
python-version: 3.7
- name: Install dependencies
run: |
pip install pytest
pip install pytest-cov
pip install -r requirements.txt
- name: Generate coverage report
run: |
pytest --cov=./epispot --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action#v1
with:
verbose: true
fail_ci_if_error: true
When it's run, it outputs an error, which you can view here. Pytest outputs error code 5 - meaning that no tests were found - but when I run it on my computer, it works properly. Why is this happening?
It may be not the case with you but I had this issue when I was adding a Python test in a branch but added a Github action with pytest to master branch. So, pytest was not finding any tests because there were in fact none.
After I merged master branch with the workflow into that branch with a test, Python build with pytest passed.

github action: run a test file on pull request

I want to run a test file when someone sends a pull request.
This is my action.yml file.
name: "GitHub Actions Test"
on:
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
# - uses: actions/checkout#v1
- name: 'Install Node'
uses: actions/setup-node#v1
- name: Install mocha
run: npm install -g mocha
- name: Install dependencies
run: npm install
- name: "Run Test"
run: mocha test-mocha.test.js
but when running the test from github, I got the following error:
Error: No test files found: "test-mocha.test.js"
I wonder something is wrong on the last line of my yml file.
how to fix this?
This is because you've commented out the line that checks out your code:
# - uses: actions/checkout#v1 # Remove the comment from this line
By default, your code is not checked out in the workflow's directory. As such, you have to use the Checkout GitHub Action to check out your code.
From the README:
This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.