I have written a custom action in Golang, which has a function that makes two output names.
The output names are created for later use in the workflow, so I can call the action in one job ("Calculate version"), catch the output names, and use it in a different job ("Build")
The Go function inside the action to create the output name is:
func SetTag(value string){
fmt.Printf(`::set-output name=repo_tag::%s`, value)
fmt.Printf(`::set-output name=ecr_tag::%s`, "v" value)
}
And the workflow that uses the said output is like so:
Version:
name: Calculate Version
runs-on: ubuntu-latest
outputs:
repo_version_env: ${{ steps.version.outputs.repo_tag }}
ecr_version_env: ${{ steps.version.outputs.ecr_tag }}
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Calculate version
id: version
uses: my_custom_action/version@v1
Build:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Build
run: |
echo ${{ needs.Version.outputs.ecr_version_env }}
echo ${{ needs.Version.outputs.repo_version_env }}
When I run the workflow, The echo commands give me the following in the action build output:
1 echo
2 echo v1.4.1::set-output name=ecr_tag::1.4.1
Instead of:
1 echo v1.4.1
2 echo 1.4.1
What am I doing wrong?
If there are better ways to use the variables outputted from the action, between different jobs in the workflow I will be happy to hear as well.
Thanks a lot.
CodePudding user response:
For what I tested here, the problem is that the go function will print the datas like this:
::set-output name=repo_tag::1.4.1::set-output name=ecr_tag::v1.4.1%
And the problem seems related to the fact that you didn't break the line.
It should work by updating the Go function to:
func SetTag(value string){
fmt.Printf(`::set-output name=repo_tag::%s`, value)
fmt.Print("\n")
fmt.Printf(`::set-output name=ecr_tag::%s`, "v" value)
fmt.Print("\n")
}
Note that the second fmt.Print("\n")
will remove the %
symbol on the terminal.
If you want to check the test I made: