Skip to content

Commit

Permalink
Reduce cost by collapsing workflow jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
nafarlee committed Nov 28, 2023
1 parent a8d62cf commit 9a50164
Showing 1 changed file with 15 additions and 38 deletions.
53 changes: 15 additions & 38 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,75 +1,52 @@
on: push
jobs:
single:
main:
runs-on: ubuntu-latest
outputs:
paths: ${{ steps.for-each-4.outputs.paths }}
steps:
- uses: actions/checkout@v3

- name: Run colpal/actions-for-each
id: for-each
id: for-each-1
uses: ./
with:
patterns: 'fixtures/*'
- run: echo $OUTPUT
env:
OUTPUT: ${{ steps.for-each.outputs.paths }}
- if: steps.for-each.outputs.paths != '["fixtures/function-a/","fixtures/function-b/","fixtures/function-c/","fixtures/run-a/","fixtures/run-b/"]'
- if: steps.for-each-1.outputs.paths != '["fixtures/function-a/","fixtures/function-b/","fixtures/function-c/","fixtures/run-a/","fixtures/run-b/"]'
run: exit 1

multiple-folders:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run colpal/actions-for-each
id: for-each
id: for-each-2
uses: ./
with:
patterns: |
fixtures/*
!fixtures/*-b
- run: echo $OUTPUT
env:
OUTPUT: ${{ steps.for-each.outputs.paths }}
- if: steps.for-each.outputs.paths != '["fixtures/function-a/","fixtures/function-c/","fixtures/run-a/"]'
- if: steps.for-each-2.outputs.paths != '["fixtures/function-a/","fixtures/function-c/","fixtures/run-a/"]'
run: exit 1

multiple-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run colpal/actions-for-each
id: for-each
id: for-each-3
uses: ./
with:
patterns: |
fixtures/**/file.txt
!fixtures/function-*/**
- run: echo $OUTPUT
env:
OUTPUT: ${{ steps.for-each.outputs.paths }}
- if: steps.for-each.outputs.paths != '["fixtures/run-a/file.txt","fixtures/run-b/file.txt"]'
- if: steps.for-each-3.outputs.paths != '["fixtures/run-a/file.txt","fixtures/run-b/file.txt"]'
run: exit 1

parallel-start:
runs-on: ubuntu-latest
outputs:
paths: ${{ steps.for-each.outputs.paths }}
steps:
- uses: actions/checkout@v3
- name: Run colpal/actions-for-each
id: for-each
id: for-each-4
uses: ./
with:
patterns: 'fixtures/*'
- run: echo $OUTPUT
env:
OUTPUT: ${{ steps.for-each.outputs.paths }}
patterns: 'fixtures/run-*'

parallel-end:
needs: parallel-start
parallel:
needs: main
runs-on: ubuntu-latest
strategy:
matrix:
path: ${{ fromJSON(needs.parallel-start.outputs.paths) }}
path: ${{ fromJSON(needs.main.outputs.paths) }}
steps:
- uses: actions/checkout@v3
- run: cat ${{ matrix.path }}file.txt

0 comments on commit 9a50164

Please sign in to comment.