Skip to content

Commit

Permalink
Skip duplicate Github Actions runs (#2929) (#3008)
Browse files Browse the repository at this point in the history
* Skip duplicate Github Actions runs (#2929)

Closes #2929

Skip conditions have been added at the step level for matrix jobs because of:
https://github.com/marketplace/actions/skip-duplicate-actions#how-to-use-skip-check-with-required-matrix-jobs

* Update the skip_duplicate_workflow_runs workflow

Remove the `cancel_others` setting since cancelling workflow runs from outdated commits requires the `actions: write` permission.
  • Loading branch information
MemunaHaruna authored Nov 2, 2022
1 parent 1a3a46a commit d27820f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 36 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/rack2.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
name: Rack_v2

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
skip_duplicate_runs:
uses: ./.github/workflows/skip_duplicate_workflow_runs.yaml

rack_v2:
name: >-
Rack_v2: ${{ matrix.os }} ${{ matrix.ruby }}
needs: skip_duplicate_runs
env:
CI: true
TESTOPTS: -v
Expand All @@ -35,9 +32,11 @@ jobs:

steps:
- name: repo checkout
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: actions/checkout@v3

- name: load ruby
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: ruby/setup-ruby-pkgs@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -50,18 +49,23 @@ jobs:

# fixes 'has a bug that prevents `required_ruby_version`'
- name: update rubygems for Ruby 2.4 - 2.5
if: contains('2.4 2.5', matrix.ruby)
if: |
contains('2.4 2.5', matrix.ruby) &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
run: gem update --system 3.3.14 --no-document
continue-on-error: true
timeout-minutes: 5

- name: set WERRORFLAG
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
shell: bash
run: echo 'PUMA_MAKE_WARNINGS_INTO_ERRORS=true' >> $GITHUB_ENV

- name: compile
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
run: bundle exec rake compile

- name: test
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
timeout-minutes: 10
run: bundle exec rake test:all
24 changes: 13 additions & 11 deletions .github/workflows/ragel.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
name: ragel

on:
push:
paths:
- 'ext/**'
- '.github/workflows/ragel.yml'
pull_request:
paths:
- 'ext/**'
- '.github/workflows/ragel.yml'
workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
skip_duplicate_runs:
uses: ./.github/workflows/skip_duplicate_workflow_runs.yaml
with:
paths: '["ext/**", ".github/workflows/ragel.yml"]'

ragel:
name: >-
ragel ${{ matrix.os }} ${{ matrix.ruby }}
needs: skip_duplicate_runs
env:
PUMA_NO_RUBOCOP: true
PUMA_TEST_DEBUG: true
Expand All @@ -37,15 +34,19 @@ jobs:
steps:
# windows git will convert \n to \r\n
- name: git config
if: startsWith(matrix.os, 'windows')
if: |
startsWith(matrix.os, 'windows') &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: repo checkout
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: actions/checkout@v3

- name: load ruby
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: ruby/setup-ruby-pkgs@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -55,6 +56,7 @@ jobs:
timeout-minutes: 10

- name: check ragel generation
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
shell: pwsh
run: |
ragel --version
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/skip_duplicate_workflow_runs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Skip Duplicate Workflow Runs

on:
workflow_call:
inputs:
paths:
description: 'A JSON-array with path patterns'
default: '[]'
required: false
type: string
outputs:
should_skip:
description: "The output from the skip_duplicate_runs job"
value: ${{ jobs.skip_duplicate_runs.outputs.should_skip }}

permissions:
contents: read

jobs:
skip_duplicate_runs:
name: 'Skip Duplicate Runs'
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5.2.0
with:
paths_ignore: '["**.md"]'
paths: ${{ inputs.paths }}
concurrent_skipping: 'same_content_newer' # skip newer runs with same content
skip_after_successful_duplicate: 'true'
52 changes: 36 additions & 16 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name: Tests

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
skip_duplicate_runs:
uses: ./.github/workflows/skip_duplicate_workflow_runs.yaml

rubocop:
name: 'Rubocop linting'
needs: skip_duplicate_runs
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -28,7 +26,7 @@ jobs:
test_mri:
name: >-
MRI: ${{ matrix.os }} ${{ matrix.ruby }}${{ matrix.no-ssl }}${{ matrix.yjit }}
needs: rubocop
needs: [rubocop, skip_duplicate_runs]
env:
CI: true
PUMA_TEST_DEBUG: true
Expand Down Expand Up @@ -63,9 +61,11 @@ jobs:

steps:
- name: repo checkout
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: actions/checkout@v3

- name: load ruby
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: ruby/setup-ruby-pkgs@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -78,35 +78,45 @@ jobs:

# fixes 'has a bug that prevents `required_ruby_version`'
- name: update rubygems for Ruby 2.4 - 2.5
if: contains('2.4 2.5', matrix.ruby)
if: |
contains('2.4 2.5', matrix.ruby) &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
run: gem update --system 3.3.14 --no-document
continue-on-error: true
timeout-minutes: 5

- name: Compile Puma without SSL support
if: matrix.no-ssl == ' no SSL'
if: |
(matrix.no-ssl == ' no SSL') &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
shell: bash
run: echo 'PUMA_DISABLE_SSL=true' >> $GITHUB_ENV

- name: set WERRORFLAG
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
shell: bash
run: echo 'PUMA_MAKE_WARNINGS_INTO_ERRORS=true' >> $GITHUB_ENV

- name: compile
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
run: bundle exec rake compile

- name: Use yjit
if: matrix.yjit == ' yjit'
if: |
(matrix.yjit == ' yjit') &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
shell: bash
run: echo 'RUBYOPT=--yjit' >> $GITHUB_ENV

- name: test
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
timeout-minutes: 10
run: bundle exec rake test:all

test_non_mri:
name: >-
NON-MRI: ${{ matrix.os }} ${{ matrix.ruby }}${{ matrix.no-ssl }}
needs: rubocop
needs: [rubocop, skip_duplicate_runs]
env:
CI: true
TESTOPTS: -v
Expand All @@ -133,15 +143,19 @@ jobs:

steps:
- name: repo checkout
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: actions/checkout@v3

- name: set JAVA_HOME
if: startsWith(matrix.os, 'macos')
if: |
startsWith(matrix.os, 'macos') &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
shell: bash
run: |
echo JAVA_HOME=$JAVA_HOME_11_X64 >> $GITHUB_ENV
- name: load ruby, ragel
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
uses: ruby/setup-ruby-pkgs@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -152,22 +166,28 @@ jobs:
timeout-minutes: 10

- name: Compile Puma without SSL support
if: matrix.no-ssl == ' no SSL'
if: |
(matrix.no-ssl == ' no SSL') &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
shell: bash
run: echo 'PUMA_DISABLE_SSL=true' >> $GITHUB_ENV

- name: set WERRORFLAG
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
shell: bash
run: echo 'PUMA_MAKE_WARNINGS_INTO_ERRORS=true' >> $GITHUB_ENV

- name: compile
if: ${{ needs.skip_duplicate_runs.outputs.should_skip != 'true' }}
run: bundle exec rake compile

- name: test
id: test
timeout-minutes: 12
continue-on-error: ${{ matrix.allow-failure || false }}
if: success() # only run if previous steps have succeeded
if: | # only run if previous steps have succeeded
success() &&
(needs.skip_duplicate_runs.outputs.should_skip != 'true')
run: bundle exec rake test:all

- name: >-
Expand Down

0 comments on commit d27820f

Please sign in to comment.