I have a workflow to run Cypress tests that is recording to Cypress Cloud and for some reason it's not passing over the commit message.
Right now I have the following:
name: Cypress Tests
on: [push, deployment_status]
jobs:
cypress-run:
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
env:
COMMIT_INFO_MESSAGE: ${{ toJson(github.event.head_commit.message) }} (by ${{ toJson(github.event.head_commit.author) }})
COMMIT_INFO_AUTHOR: ${{ toJson(github.event.head_commit.author) }}
container: cypress/included:cypress-12.7.0-node-18.14.1-chrome-110.0.5481.96-1-ff-109.0-edge-110.0.1587.41-1
steps:
- name: Checkout 🛎
uses: actions/checkout@v3
- name: Cypress run
uses: cypress-io/github-action@v6.6.0
with:
install-command: npm install
start: npm run cypress:run:dev --verbose
project: apps/game-zone-e2e
browser: chrome
record: true
parallel: true
env:
# DEBUG: 'cypress:*'
CYPRESS_PROJECT_ID: ${{ vars.CYPRESS_PROJECT_ID }}
CYPRESS_BASE_URL: ${{ github.event.deployment_status.target_url }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_INFO_MESSAGE: ${{ env.COMMIT_INFO_MESSAGE }}
COMMIT_INFO_AUTHOR: ${{ env.COMMIT_INFO_AUTHOR }}
I have echo'ed these out in the job level and I am getting the values out so i know the notation is correct but it's showing "null (by null)" for COMMIT_INFO_MESSAGE
.
What am I doing wrong here? Whats even more strange to me is github.event.deployment_status.target_url
is fine and working in that env var.
I wish there was a cleaner solution here, but never the less it works well. I had to use git commands in an additional step to extract the commit, author and other git info for cypress.
steps:
- name: Checkout 🛎
uses: actions/checkout@v3
- name: Save Git values
# pass env variables from this step to other steps
# using GitHub Actions environment file
# https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#environment-files
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
echo COMMIT_INFO_BRANCH=$(git show-branch --no-name HEAD) >> $GITHUB_ENV
echo COMMIT_INFO_MESSAGE=$(git show -s --format='%h %s') >> $GITHUB_ENV
echo COMMIT_INFO_EMAIL=$(git show -s --pretty=%ae) >> $GITHUB_ENV
echo COMMIT_INFO_AUTHOR=$(git show -s --pretty=%an) >> $GITHUB_ENV
echo COMMIT_INFO_SHA=$(git show -s --pretty=%H) >> $GITHUB_ENV
echo COMMIT_INFO_TIMESTAMP=$(git show -s --pretty=%ct) >> $GITHUB_ENV
echo COMMIT_INFO_REMOTE=$(git config --get remote.origin.url) >> $GITHUB_ENV
# delete the .git folder afterwords to use the environment values
rm -rf .git