openrewrite / openrewrite/rewrite-github-actions
Recipe - Refactor similar jobs with a matrix
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1
- Forks
- 9
- Avg merge
- 5h 27m
- Merged PRs (30d)
- 12
Description
Given the following workflow definition https://raw.githubusercontent.com/asyncer-io/r2dbc-mysql/f4ca1652219074c337d7db12d2572686da2c3a64/.github/workflows/unit-tests.yml
name: Unit tests
on: [ pull_request ]
jobs:
build_java_8:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up Temurin 8
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
cache: maven
- name: Unit test with Maven
run: ./mvnw -B test -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
build_java_11:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up Temurin 11
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
cache: maven
- name: Unit test with Maven
run: ./mvnw -B test -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
build_java_17:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up Temurin 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: maven
- name: Unit test with Maven
run: ./mvnw -B test -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
One could rewrite this workflow using a matrix configuration like so
name: Unit tests
on: [ pull_request ]
jobs:
build:
name: "Build ${{ matrix.java }}"
strategy:
fail-fast: false
matrix:
java: [8, 11, 17]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: "Set up Temurin ${{ matrix.java }}"
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: maven
- name: Unit test with Maven
run: ./mvnw -B test -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the referenced .github/workflows/unit-tests.yml and compare its three Java-version jobs with the matrix example in the issue. Implement the recipe so the workflow runs Java 8, 11, and 17 through one matrix job, then verify that the generated workflow retains the checkout, Maven cache, and unit-test steps.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github-actions
- Domain
- ci-cd, devops
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100