Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 11 of 22

Re: Support for YAML anchors

This actually helped a lot with the simpler workflows, didn't realise the matrix options can be 'any' defined string

Although for the more complicated ones when I need multiple steps after a 'setup' action (above) anchors would really help

Highlighted
Copilot Lvl 2
Message 12 of 22

Re: Support for YAML anchors

This isn't quite hte same though, as it would result in a single job.


I want our users to see (without looking through logs) which part of the process failed, and multiple jobs are great for that.

Highlighted
Mission Specialist Lvl 1
Message 13 of 22

Re: Support for YAML anchors

Just had this same issue.

Highlighted
GBH
Copilot Lvl 2
Message 14 of 22

Re: Support for YAML anchors

Oh boy. I just made a pretty yaml file just to find out that anchors are not supported. Is there a technical reason why not? What Yaml parser cannot handle this?

 

I have 2 sets of jobs in my workflow that have exactly same steps save for the last few (2 test jobs and 2 deploy jobs). So now I have to copy-paste like 100+ lines of code for no good reason. And then I'll have to be extra vigilant about making sure that I don't forget to update same code in two different places.

 

Github pls.

Highlighted
Ground Controller Lvl 1
Message 15 of 22

Re: Support for YAML anchors

I also stumbled upon this and was disappointed :(
Please add support for YAML anchors asap, this is a must.

Highlighted
Ground Controller Lvl 2
Message 16 of 22

Re: Support for YAML anchors

GitHub simply do not follow the YAML spec, otherwise there would be support for anchors as every parser that follows the spec.

 

Since we cannot rely on the spec to use actions, they might as well call it a fork and publish their own specification. Sadly it is not a superset like GFM

GBH
Copilot Lvl 2
Message 17 of 22

Re: Support for YAML anchors

While Github figures out how to parse YAML files I'm doing a workaround:

 

- Step 1: Write Yaml file with anchors so steps can be reused

- Step 2: Have a script emit unrolled YAML file that Github can parse

 

#!/usr/bin/env ruby

require "yaml"
require "json"

yaml = YAML.load_file(File.expand_path("workflow_template.yml", __dir__))

File.write(File.expand_path("workflows/cicd.yml", __dir__), YAML.load(yaml.to_json).to_yaml(line_width: 1024))

puts "Workflow emitted!"
Highlighted
Copilot Lvl 3
Message 18 of 22

Re: Support for YAML anchors

GitHub, get this working and you'll resolve a *ton* of similar issues.

Highlighted
Copilot Lvl 2
Message 19 of 22

Re: Support for YAML anchors

Adding this feature would help with a number of other issues. For example, it would provide a workaround for inability to define complicated matrices (https://github.community/t5/GitHub-Actions/Improve-matrix-exclusion-feature/td-p/32592). With this feature, instead of defining one huge matrix with many exclusions, I could define several jobs with their own simple matrices, and re-use "steps" entry easily.

Highlighted
Copilot Lvl 3
Message 20 of 22

Re: Support for YAML anchors

I can understand their reasoning for not including anchors as I've seen some really awful use cases that actually makes the resulting file less comprehensible.  However, I too miss being able to define them from time to time.

 

As a compromise, I think docker-compose has a great solution.  It has what it calls extension fields as places where you can define anchors rather than let you define them anywhere and everywhere.

 

https://docs.docker.com/compose/compose-file/#extension-fields