Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose GitHub actions as a single GitHub action #438

Closed
ghost opened this issue Apr 21, 2020 · 23 comments
Closed

Compose GitHub actions as a single GitHub action #438

ghost opened this issue Apr 21, 2020 · 23 comments
Labels
Runner Feature Feature scope to the runner

Comments

@ghost
Copy link

ghost commented Apr 21, 2020

What I like from GitHub action is we can ensure that our action is up-to-date with available fixes in the upstream. E.g.: we can use actions/checkout@v2 and the CI will still run with the latest version of checkout@v2.

Unfortunately, this facility can't be used while we're creating a GitHub action. I think it's better if we can compose multiple GitHub actions into a single GitHub action, or maybe just use one or two GitHub actions for the trivial tasks and continue the other in Javascript or Docker container.

This is an imaginary action.yml to serve as an example, maybe it's cool if we can do this:

name: 'imaginary-extension'
description: 'Imaginary extension about composing actions'
runs:
  using: composite
  steps:
    - name: Python 3
      uses: actions/setup-python@v1
      with:
        python-version: 3.8
    - name: Requirements
      run: pip install -r requirements.txt
@ghost ghost added the enhancement New feature or request label Apr 21, 2020
@TingluoHuang
Copy link
Member

It feels like a template reuse scenario, so you can share a list of reusable steps with others.

@chrispat @ericsciple for an idea.

@ericsciple
Copy link
Collaborator

Yep it's something we want to do. Currently behind other priorities.

@ghost
Copy link
Author

ghost commented Apr 22, 2020

Please tell me about the progress later. I'm interested in this feature.

@TingluoHuang TingluoHuang added runner Runner Feature Feature scope to the runner and removed enhancement New feature or request runner labels Jun 8, 2020
@hross
Copy link
Contributor

hross commented Jun 14, 2020

We are picking up work here so keep an eye out for activity. We will update things as we go.

@ghost
Copy link
Author

ghost commented Jun 15, 2020

Super cool. Thank you!

@pelotom
Copy link

pelotom commented Jul 13, 2020

This is our team's number 1 pain point with GH actions, would love to see something like this implemented, or alternatively support for YAML anchors (how we used to accomplish DRY with Travis).

@vanppo
Copy link

vanppo commented Jul 14, 2020

This is our team's number 1 pain point with GH actions, would love to see something like this implemented, or alternatively support for YAML anchors (how we used to accomplish DRY with Travis).

YAML anchors may not be good enough. For the action below, we can not share common steps between jobs by YAML anchors.

test-job:
  steps:
    - checkout
    - cache
    - dependencies
    - test

build-job:
  steps:
    - checkout
    - cache
    - dependencies
    - build

Syntax below may be the resolution.

defaults:
  steps:
    - checkout
    - cache
    - dependencies
jobs:
  test-job:
    - test
  build-job:
    - build

@Enrico2
Copy link

Enrico2 commented Jul 14, 2020

A single step must be able to reference outputs of previous steps, and so in order to define a step in a centralized way, there must be a way to provide inputs to that step.
I like the idea of being able to define a composed set of steps as an action with inputs:
E.g.

composites:
  init: 
    input:
      - branch
    steps:
      - uses: actions/checkout@v2
        with: {{ input.branch }}
      - actions/cache...
      - actions/test
        
job1:
  steps:
    - if: {{ event == release }}
      run: ... set some output, on a e.g. my_var
      id: is_release
    - uses: composites.init
       with:
         branch: steps.is_release.outputs.my_var
    - run: ...

@hross
Copy link
Contributor

hross commented Jul 15, 2020

We are working through this scenario. The first feature we need to get working is multiple run steps, after which we would allow more complex action composition. Right now we plan to do it with a separate action template/definition.

You can see this work in progress for how we are going to support multiple run steps (then imagine this gets extended to more complicated steps (there is more technical work to support things like uses/etc): #591

Also see the full ADR for more detail on syntax/usage: https://github.com/actions/runner/blob/main/docs/adrs/0549-composite-run-steps.md

vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
vguerci added a commit to criteo/ios-publisher-sdk that referenced this issue Jul 21, 2020
We cannot reuse worklow jobs on GA, worth subscribing:
actions/runner#438
JIRA: EE-1157
@Vampire
Copy link

Vampire commented Jul 31, 2020

As the mentioned PR is now merged, when can we expect this to be publicly available? :-)

@ThibaultVlacich
Copy link

@timharris777 The comment right above yours...

@timharris777
Copy link

timharris777 commented Aug 7, 2020

@timharris777 The comment right above yours...

Sorry @ThibaultVlacich, I'm not following you. This is already released and I have been using it today. It was in the latest runner features from like 9 days ago and it was announced today. https://github.blog/changelog/2020-08-07-github-actions-composite-run-steps/

@sidvishnoi
Copy link

@timharris777 See #646

@timharris777
Copy link

@timharris777 See #646

Thanks for pointing that out @sidvishnoi , just read it. Looks like their long term plan is to support actions within actions and this is a step in that direction-- but for now they are just supporting run commands from different shells.

@mikedrexler
Copy link

Hi @timharris777 ! It would appear that your answer arrived before I saw your question. Tracking in the Chick-Fil-A customer repository at https://github.com/githubcustomers/Chick-Fil-A/issues/11.

@nsheff
Copy link

nsheff commented Aug 7, 2020

The 'composite' action type allows us to run sequential commands natively, but is there any way to put together docker-based actions? For instance, I'd like one of the steps in the composite action to be running a docker action.

@razor-x
Copy link

razor-x commented Aug 8, 2020

@nsheff Check out #646

@hross
Copy link
Contributor

hross commented Aug 17, 2020

We still have work to do on this feature. I'm linking this issue: #646 so everyone can see we are totally aware of the future work to get "actions in actions" working fully. See that issues for what's left to do and the state of the world for this feature.

@reitzig
Copy link

reitzig commented Oct 20, 2020

FWIW and for googlers landing here, I don't see how the closing MR offers more than YAML replacement for simple intermediate/wrapper scripts. Qualitively speaking; there seem to be some consequences how workflow runs show up in the UI, which are of secondary concern IMHO.
In particular, the core issue of (transparently) calling another action has not been addressed, at all.

Both the MR and #646 express that being able to express multiple steps in YAML is a major stepping stone towards that. I don't necessarily follow -- another route, such as before-steps: <array of uses> would have seemed feasible as well -- but I'll take your word for it. #612 was dealing with the core issue, though, so #646 remains the issue to watch.

@emilong
Copy link

emilong commented Nov 6, 2020

YAML anchors do everything I want, which includes sharing configuration not related to steps, i.e. stuff I want to share but don't want to run like container configuration.

To prove this to myself, I decided to create a .github/workflows-src/ directory with workflow yaml files which included anchors, but only defined under the top-level anchors key.

Here's an example (simplified) workflow yaml source file:

---
name: Integration

"on": [pull_request]

anchors:
  docker_hub_credentials: &docker_hub_credentials
    credentials:
      username: my-dockerhub-username
      password: ${{ secrets.DOCKER_HUB_PASSWORD }}

  postgres_service: &postgres_service
    postgres:
      image: mdillon/postgis:9.6
      <<: *docker_hub_credentials

  cache_gems: &cache_gems
    name: Cache Ruby Gems
    uses: actions/cache@v2
    env:
      cache-name: cache-gems
    with:
      path: vendor/bundle
      key: ${{ runner.os }}-build-${{ env.cache-name }}-gems-${{ hashFiles('Gemfile.lock') }}
      restore-keys: |
        ${{ runner.os }}-build-${{ env.cache-name }}-gems-
        ${{ runner.os }}-build-${{ env.cache-name }}-
        ${{ runner.os }}-build-
        ${{ runner.os }}-

jobs:
  lint_and_dependencies:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - *cache_gems
      - run: bundle install
      - name: Run Pronto
        run: >
          PRONTO_PULL_REQUEST_ID="${{ github.event.number }}"
          PRONTO_GITHUB_ACCESS_TOKEN="${{ github.token }}"
          bundle exec pronto run -f github_status github_pr -c origin/${{ github.base_ref }}
  run_rspec_tests:
    needs: lint_and_dependencies
    runs-on: ubuntu-latest
    services:
      <<: *postgres_service
    steps:
      - uses: actions/checkout@v2
      - *cache_gems
      - run: bundle install
      - name: Prepare database
        run: psql -h postgres -U test test_db < db/structure.sql
      - name: Run RSpec
        run: bundle exec rspec

Then I preprocess in a pre-commit hook with this script:

require "yaml"
require "json"

parsed = JSON.parse(YAML.load_file(ARGV.first).to_json)
parsed.delete("anchors")

puts YAML.dump(parsed)

Maybe this is of some use to others here, but also possibly an example of what many of us are looking for with YAML anchors for the GitHub team.

(P.S. I'm a little confused by the anchor parsing concerns as I'm not sure if I could turn off anchors in the transformation script above, but you all know your codebase better than me, of course)

@rhyek
Copy link

rhyek commented Feb 9, 2021

Per @emilong's example I tried it in an example repo of mine and it's working wonderfully. I included functionality to automatically merge/flatten steps lists, as well.

You can check out the example here. Hope someone finds it useful.

iguessthislldo added a commit to iguessthislldo/OpenDDS that referenced this issue Feb 27, 2021
I didn't write the anchors right, but while looking at the error message
I saw this:

> .github/workflows/build_and_test.yml: Anchors are not currently supported. Remove the anchor 'opendds_common_on'

WHY?!? 😨

Here's some links to places where this issue is being tracked, but it
doesn't look like Github is going to implement this even though it's
standard YAML...

- https://git.luolix.topmunity/t/support-for-yaml-anchors/16128
- https://git.luolix.topmunity/t/reusing-sharing-inheriting-steps-between-jobs-declarations/16851/14
- actions/runner#438

The choices seem to be:

- Revert to copy and paste, which I will do for now.
- Do some sort of prepossessing in the workflow using a compliment YAML
  tool like what some people are suggesting. I think we where also talking
  about something in a similar vain, but with having a program generate
  the file.
@b0g3r b0g3r mentioned this issue May 2, 2021
4 tasks
mxro added a commit to goldstack/goldstack that referenced this issue Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Runner Feature Feature scope to the runner
Projects
None yet
Development

No branches or pull requests