GitHub Action workflow_call does not use up to date input values - github

I am encountering a strange behaviour with GitHub Action workflow_call.
Basically, everything works fine after the initial setup, but when I edit the input parameters of the workflow files it does not use the updated values. Hard to explain in words, so let me show you an example.
Consider this basic setup:
File: start-pipeline.yml
name: Start Pipeline
on:
workflow_dispatch:
inputs:
release_type:
required: true
type: choice
options:
- patch
- minor
- major
jobs:
call-sub-workflow:
uses: codezalot/workflow-call-issue/.github/workflows/sub-workflow.yml#main
with:
release_type: ${{ github.event.inputs.release_type }}
File: sub-workflow.yml
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
I then start the pipeline with the value patch and the sub-workflow prints the input just fine:
I then update the workflow files and add an additional input value like this:
File: start-pipeline.yml
...
jobs:
call-sub-workflow:
uses: codezalot/workflow-call-issue/.github/workflows/sub-workflow.yml#main
with:
release_type: ${{ github.event.inputs.release_type }}
some_other_value: ${{ github.event.inputs.release_type }}
File: sub-workflow.yml
...
inputs:
...
some_other_value:
type: string
required: true
jobs:
...
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
echo "Release Type: ${{ github.event.inputs.some_other_value }}"
I then run the pipeline again, once with release_type patch, once with minor.
The value some_other_value is missing however, see:
.
I have been playing around with this issue for hours, but I do not understand what is going wrong. For it does seem to be using the latest SHA versions of the files, just the input parameters cause an issue.
Does anyone know what's going on here?

According to the documentation: "When a workflow is triggered with the workflow_call event, the event payload in the called workflow is the same event payload from the calling workflow." In other words, the event parameter in the github context is the same for the called workflow as for the original workflow.
Consequently, there is no github.event.input.some_other_value parameter since the original workflow did not have this input. For inputs defined in a reusable workflow you can use the inputs context which contains the input properties passed to the reusable workflow.
To sum up, here is a working sub-workflow.yml file:
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
some_other_value:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ inputs.release_type }}"
echo "Release Type: ${{ inputs.some_other_value }}"
Result:

Related

GitHub Actions - Reuse outputs from other reusable workflows

I'm not sure if it's possible, but I'm attempting to use outputs from one reusable workflow, in another, that's part of the same caller workflow. For reference, please see the configs below:
Caller Workflow:
jobs:
call-workflow-calver:
uses: ./.github/workflows/called-workflow1.yaml
secrets: inherit
call-workflow-echo:
needs: call-workflow-calver
uses: ./.github/workflows/called-workflow2.yaml
secrets: inherit
Job for creating the CalVer tag (it outputs as $VERSION as part of the action)
Called Workflow 1:
...
jobs:
calver:
name: Create CalVer tag
...
steps:
- name: Calver tag
uses: StephaneBour/actions-calver#1.4.4
if: ${{ github.ref == 'refs/heads/main' }}
id: calVer
with:
date_format: "%Y-%m-%d"
release: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
...
Trying to use the CalVer $VERSION output from another caller workflow
Called Workflow 2:
...
- name: Echo
run: |
echo ${{needs.calver.outputs.VERSION}}
...
The basic concept is I'm trying to use outputs from one reusable workflow in another for setting CalVer versions in workflow 1, calling that in workflow 2 so I can set it as an image version. I will eventually use in a 3rd reusable workflow to deploy said image. If this is possible, that would be great!
Hopefully, this all makes a bit of sense, but if anything needs clarifying, please do let me know!
Many thanks in advance!
According to the official documentation, you can now declare outputs to reusable workflows.
These work just like job outputs and are available via needs.<reusable>.outputs.<output> format once you declare the output.
Example
1. Reusable workflow configuration:
name: Reusable workflow
on:
workflow_call:
# Map the workflow outputs to job outputs
outputs:
firstword:
description: "The first output string"
value: ${{ jobs.example_job.outputs.output1 }}
secondword:
description: "The second output string"
value: ${{ jobs.example_job.outputs.output2 }}
jobs:
example_job:
name: Generate output
runs-on: ubuntu-latest
# Map the job outputs to step outputs
outputs:
output1: ${{ steps.step1.outputs.firstword }}
output2: ${{ steps.step2.outputs.secondword }}
steps:
- id: step1
run: echo "::set-output name=firstword::hello"
- id: step2
run: echo "::set-output name=secondword::world"
2. Workflow using the reusable:
name: Call a reusable workflow and use its outputs
on:
workflow_dispatch:
jobs:
job1:
uses: octo-org/example-repo/.github/workflows/called-workflow.yml#v1
job2:
runs-on: ubuntu-latest
needs: job1
steps:
- run: echo ${{ needs.job1.outputs.firstword }} ${{ needs.job1.outputs.secondword }}
Note that if a reusable workflow that sets an output is executed with a matrix strategy, the output will be the output set by the last successful completing reusable workflow of the matrix which actually sets a value. That means if the last successful completing reusable workflow sets an empty string for its output, and the second last successful completing reusable workflow sets an actual value for its output, the output will contain the value of the second last completing reusable workflow.
I used this workflow as example here if you want to check the logs of the workflow run.

Github Action - Reusable workflow AND manual trigger

I'm surprised that I haven't seen this asked anywhere (unless my googlefu is not as strong as I thought!)
I'm trying to get a reusable workflow only to run if manually triggered, even after being called by the caller workflow.
Here are a few examples of how I thought it should work:
Caller Workflow
name: Calling reusable workflow
on:
push:
branches:
- release
- develop
- main
jobs:
call-workflow:
uses: ./.github/workflows/reusable-workflow1.yaml
secrets: inherit
Reusable workflow
name: Reusable Workflow
on:
workflow_call:
secrets:
secret_1:
description: The Environment secret for secret_1
required: true
workflow_dispatch:
inputs:
test_choice:
type: choice
description: "Select a choice"
required: true
options:
- Test1
- Test2
- Test3
env:
GITHUB_RUN_ID: $GITHUB_RUN_ID
jobs:
log-the-inputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "Choice: $choice"
echo "Secret: $secret"
echo "GitHub Run ID: $GITHUB_RUN_ID"
env:
choice: ${{ inputs.test_choice }}
secret: ${{ secrets.secret_1 }}
So when testing, once the main caller workflow is started, it just calls the reusable workflow right away, which as you can expect will fail due to it not having the inputs.choice as it hasn't asked for it as part of the manual trigger.
Has anyone found a way to do this at all/if this is even possible?
Many thanks in advance!

Reusable workflow not being invoked on release action in Github

I hope someone can help me out with this github action issue.
I am trying to set a github action pipeline that parse the some tags and invoke another reusable workflow.
Here is what the code looks like:
name: release per tag
on:
release:
types: [ published ]
permissions:
actions: write
checks: write
contents: write
deployments: write
issues: write
packages: write
pull-requests: write
repository-projects: write
security-events: write
statuses: write
jobs:
get_project_folder:
name: "Find project folder"
runs-on: ubuntu-latest
outputs:
project_folder: ${{ steps.regex-match.outputs.name }}
steps:
- id: regex-match
uses: actions-ecosystem/action-regex-match#v2
with:
text: ${{ github.event.release.tag_name }}
regex: '.*(?=\-)'
- id: to-variable
run: echo "::set-output name=project_name::${{ steps.regex-match.outputs.match }}"
build_release_package:
name: "Invoke standard release tag yaml"
uses: ./.github/workflows/standard_release_tag.yaml
with:
project_name: ${{ needs.get_project_folder.outputs.project_folder }}
environment: Production
secrets:
INSTALL_PKG_PAT: ${{ secrets.INSTALL_PKG_PAT }}
HOST_URL: ${{ secrets.HOST_URL }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
ENV: prod
Somehow this pipeline is not being able to call the standard_release_tag.yaml even it exists on the repository.
Is this something happened to anyone? I googled but only saw this happen for a different trigger event and was fixed by Github team.
Thanks.
Solved by validating that the pipeline was invoking and old version of the yaml pipeline.

In a GitHub Action how to conditionalize a step based off the previous step's output?

Building a GitHub action based on the commit message I'm trying to base a step on whether the commit message contains a particular string, set it to a variable and then in the next step check with a condition.
My current implementation of my action works:
name: Smoke Test
on:
push:
branches:
- main
permissions:
contents: read
issues: write
jobs:
smoking:
runs-on: [ubuntu-latest]
steps:
- name: Run smoke tests
if: ${{ !contains(github.event.head_commit.message, 'smoke_test') }}
run: |
echo 'Smoke Test not requested'
exit 1
stuff:
needs: smoking
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: JasonEtco/create-an-issue#v2
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
filename: .github/ISSUE_TEMPLATE/smoke-test.md
id: create-issue
- run: 'echo Created issue number ${{ steps.create-issue.outputs.number }}'
- run: 'echo Created ${{ steps.create-issue.outputs.url }}'
but with the implementation of:
exit 1
causes the action to indicate it error'ed out in the action panel and while that works that isn't technically accurate because I don't need it to error I just don't want the remaining steps to run.
I've tried setting a variable:
if: ${{ contains(github.event.head_commit.message, 'smoke_test') }}
with:
run-smoke-test: true
run: |
echo 'Smoke Test requested'
but it's not passing to the next step.
Research
Use environment variable in github action if
How to pass variable between two successive GitHub Actions jobs?
github-action: does the IF have an ELSE?
How to fail a job in GitHub Actions?
GitHub Actions - trigger another action after one action is completed
Without relying on another GitHub action is there a way in step smoking to set an env variable that step stuff would need to validate for before running the step?
Edit
After reading the answer and implementing job outputs I've written:
name: Smoke Test
on:
push:
branches:
- main
permissions:
contents: read
issues: write
jobs:
commitMessage:
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.isSmoke.outputs.test }}
steps:
- id: isSmoke
if: ${{ contains(github.event.head_commit.message, 'smoke_test') }}
run: echo "::set-output name=test::true"
smokeTest:
runs-on: ubuntu-latest
needs: commitMessage
steps:
- uses: actions/checkout#v2
- uses: JasonEtco/create-an-issue#v2
if: steps.isSmoke.output.test == true
env:
GITHUB_TOKEN: ${{ secrets.DEV_TOKEN }}
with:
filename: .github/ISSUE_TEMPLATE/smoke-test.md
but when the commit message of smoke_test is used it bypasses create-an-issue:
and I'm basing my condition after reading "Run github actions step based on output condition" and reading:
Contexts
Expressions
Using conditions to control job execution
Can a condition come before a step and/or what is the correct way to run a step based off the previous step?
You are looking for job outputs, which allow you to send data to the following jobs.

Github action how to access the inputs

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
I have the following inputs:
Which branch do I want to use
Input fields
How do I access the information that I enter and then use it later in the github action script?
You now (June 2022) have an alternative:
You could try and take advantage of a new feature (June 2022)
GitHub Actions: Inputs unified across manual and reusable workflows
Workflows triggered by workflow_dispatch and workflow_call can now access their inputs using the inputs context.
Previously workflow_dispatch inputs were in the event payload.
This made it difficult for workflow authors who wanted to have one workflow that was both reusable and manually triggered.
Now a workflow author can write a single workflow triggered by workflow_dispatch and workflow_call and use the inputs context to access the input values.
For workflows triggered by workflow_dispatch, inputs are still available in the github.event.inputs context to maintain compatibility.
Using the inputs context in GitHub Actions.
In your case:
jobs:
printInputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "Log level: ${{ inputs.logLevel }}"
echo "Tags: ${{ inputs.tags }}"
To use an input from the workflow_dispatch trigger on your yaml file, you need to use the following syntax ${{ github.event.inputs.<input_name> }} or ${{ inputs.<input_name> }}.
For example, in your case:
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
jobs:
printInputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "Log level: ${{ github.event.inputs.logLevel }}"
echo "Tags: ${{ github.event.inputs.tags }}"
Here is a simple demo if you want to check:
workflow file
workflow run
You can also check the official documentation about it.