Hi I’m having some trouble configuring my github actions workflow.
what I want to do is send a notification to my slack channel of the workflow outcomes whether if its successful or not.
I also wanted the slack messages displays different colors depending on the result of the workflow.
This used to work on my previous versions of my workflow but after I bumped up some of the package versions it seems to ignore the if: ${{ github.workflow == 'Unittest' }}
conditions.
enter image description here
this is my yml code ( I erased some sensitive values and left them blank)
name: Unittest
on:
workflow_call:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure aws credential
uses: aws-actions/configure-aws-credentials@v4
- name: Checkout firebase admin sdk
run:
- name: Set up MySQL
run:
env:
DB_DATABASE:
DB_LEGACY:
DB_USER:
DB_PASSWORD:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11.3"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv --user
pipenv run pipenv requirements --dev > requirements.txt
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# 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: Test with pytest
run: |
pytest --html=report.html --self-contained-html
env:
- name: Notification
if: ${{ github.workflow == 'Unittest' }}
uses: 8398a7/action-slack@v3
with:
status: custom
fields: workflow,job,commit,repo,ref,author,took
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_WORKFLOW}n${process.env.AS_JOB} (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Upload Report
if: ${{ github.workflow == 'Unittest' }}
uses: MeilCli/slack-upload-file@v4
with:
slack_token: ${{ secrets.ACTION_BOT_TOKEN }}
channel_id: C0278JD7H7B
file_path: "report.html"
initial_comment: "Unittest Report : ${{ github.repository }}"
I tried changing the if condition to always()
and worked. However I only want this Notification step to be executed when the Unittest
named workflow runs because this workflow is called in different workflows and don’t want the Notification step to be executed elsewhere.
I also echoed github.workflow
and printed out the exact str value that I wanted
I tried removing the brackets as so if: github.workflow == 'Unittest'
and also only added the brackets at github.workflow variable as so if: ${{ github.workflow }} == 'Unittest'
but doesn’t seem to do the trick.
I was hoping if anyone can point out what I’m missing.
Big thanks in advance.