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

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.

Related

Github actions: should I test my python project with pytest or with tox?

I have a Python project that is automatically tested with the following Github Actions file:
name: pytest
on: push
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python: ["3.8", "3.9"]
steps:
- uses: actions/checkout#v2
- name: Setup Python
uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python }}
- name: Install pytest
run: python -m pip install pytest
- name: Install requirements
run: python -m pip install -r requirements.txt
- name: Run pytest
run: python -m pytest
It works fine, but I saw that other projects use an action for tox, which then runs pytest. I understand that tox automatically installs a virtual environment, but this is already done by GitHub Actions.
Is there a reason to replace my current Github Actions file with a file that runs tox?
You can run tox both local and on CI/GHA, so you can test your code against several Python versions without duplicating any test setups.
That is the main benefit.
PS: I am one of the tox maintainers.

Github Action Status check missing from the list of checks in Protected branch settings

I have the following github action setup that triggers fine on creation of Pull Request. But it does not show up in the status checks list of protected branch (main). I'm not sure what I'm doing wrong.
name: Python application
on:
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Set up Python 3.7
uses: actions/setup-python#v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: GitHub Action for pylint
uses: cclauss/GitHub-Action-for-pylint#0.7.0
- name: Github Action for pytest
run: python3 testing.py
I've also tried the same setting with:
on: [ pull_request ]
Edit:
Screenshot of the check missing:
Finally figured this out. I did not set a name for the job, so it defaulted to the property build in this case. I was searching by workflow name. Once I added the job name, I was able to search for it correctly. Later I also verified that searching for build brings up the check name in the list too.
jobs:
build:
name: python test
...
I just had a similar experience but it was because my Github Workflow had not been triggered in the past week. Once I got the Workflow to trigger it showed up in the search area.
Another solution may be to go to https://github.com/<org_name>/<repo_name>/actions and check to see if there's a button that says
Enable Actions on this repository
Then try closing/opening your existing PR to trigger the action.

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.

Github action not uploading artifact

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