Support for YAML anchors

@andreagriffiths11 Hi, has there been any update on this request since submitting to the appropriate teams?

It a pretty essential feature when maintaining many internal repositories that use the same workflow…

Thanks in advance!

2 Likes

No updates yet. We agree it’s important. It’s on our list to figure out.

6 Likes

chiming in because I’d like this too. It would reduce the repetition in our yaml files by a large chunk

2 Likes

In my daily work I have many repositories with similar YAMLs required by their workflows.

I have been utilizing Kojo with great success for deduplicating my work, and constructing YAMLs from smaller YAML snippets, like:

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    steps:
    @import git-checkout

    - name: Notify slack (started)
      run: "..."

    @import docker-login

    # ...

Obeviously, not a replacement for the much-needed anchors, but I thought it might help others who are dealing with YAML copy-paste hell, until anchor reinforcement arrives.

(Disclaimer: Kojo is a gem I wrote, hopefully this post is not considered a shameless plug).

2 Likes

I hate to say this, but you just need to switch to a real (i.e. conforming) YAML parser, **bleep** it. I’m sure there’s a good one in whatever language you’re working with.

4 Likes

Joining the requests from all the kind people above me.

YAML anchors are too useful to be left out.

:god:

3 Likes

Echo what everyone else is saying but anchors are a must…

+1 in the queue still waiting for anchors to help battle the dreaded copy-paste :expressionless:

3 Likes

Taxi Driver are you taking to me

Hi All,

If all you need is to reuse bash command across steps. I create an action to solve 90% of the needs!

https://github.com/ktmud/cached-dependencies

This action sources a bashlib.sh file in your .github/workflows folder before executing the commands you provide. It even comes with cache management where you can restore and save multiple cache targets in one step!

With this, it’s possible to write workflows as beautiful as this:

- name: Install dependencies
      uses: apache-superset/cached-dependencies@ddf7d7f
      with:
        run: |
          npm-install && npm-build
          pip-install && setup-postgres && testdata
          cypress-install

Just take a look at how clean the code is here: https://github.com/ktmud/incubator-superset/tree/github-actions/.github/workflows

Please give it a try and let me know what you think!

1 Like

Yet another +1, spent far too long searching for what I assumed would be an obvious use-case of actions…

Hi Andrea, an update on where this is on the roadmap?

Would really help us manage the yaml configs, which are now quite copy-pastey across jobs.

Any updates?

Thank you,

-zo

Any update on this after 8+ months?

I was pretty excited to switch over to GitHub actions from CircleCI, but without any way to reuse configs, either with YAML anchors, or something similar to thier Reusable Commands, I won’t be able to migrate anything.

Best.

5 Likes

Hi !
I just wanted to know if there is any update on this issue? I just had this error when I tried to use YAML anchors and I really want to avoid copy pasting my steps.
Thanks.

Looks like we may not get anchor support, but a better feature instead :pray: reusing/sharing/inheriting steps between jobs declarations

It’s not better, I still need YAML anchors.

2 Likes

Hard to believe that this issue is still unresolved, after such a long time. Seems like pretty basic feature, and should be easy to implement (a single simple pre-processing step of the YAML file).

I encountered this in How to share matrix between jobs, and there doesn’t seem to be a solution for this issue that doesn’t require me to manually serialize a JSON object (including nasty escape sequences).

1 Like

My solution is to heavily use anchors and then have exactly the pre-processing step you mentioned, just not on GH side, but manually before checking in. I previously did it using js-yaml, now I do it with kotlinx.serialization.

Another vote for YAML anchors.

1 Like

another +1 and I agree that you need to just use a standards conforming yaml parser. If there’s not one in the language you use, I’m sure you could write a library on top of the C one… and then open source that. https://yaml.org lot’s of parsers mentioned.