Skip to content

Commit ae8877b

Browse files
jaymzhfacebook-github-bot
authored andcommitted
Factor lint into a reuseable workflow (facebook#333)
Summary: This factors all of the lint/unit into a reusable workflow other repos can use. Here's a successful example of using this: jaymzh/chef-fb-api-cookbooks#4 It's currently pointed at my fork of the repo, in order to reference this PR, but it works. Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: facebook#333 Differential Revision: D79009406 fbshipit-source-id: a8ff1d7bf026f2aa448afb02538f20f1702b540a
1 parent 76c1d6d commit ae8877b

File tree

3 files changed

+105
-162
lines changed

3 files changed

+105
-162
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
11
name: Continuous Integration
2+
23
on:
34
push:
45
branches: [main]
56
pull_request:
6-
jobs:
7-
ruby:
8-
strategy:
9-
fail-fast: false
10-
matrix:
11-
ruby: ['3.1', '3.3']
12-
runs-on: ubuntu-latest
13-
steps:
14-
- name: Checkout repository
15-
uses: actions/checkout@v4
16-
- name: Setup Ruby
17-
uses: ruby/setup-ruby@v1
18-
with:
19-
ruby-version: ${{ matrix.ruby }}
20-
- name: Install dependencies
21-
run: bundle install
22-
- name: Run rspec
23-
run: ./scripts/run_chefspec
24-
- name: Run cookstyle
25-
run: ./scripts/run_cookstyle
26-
shellcheck:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- name: Checkout repository
30-
uses: actions/checkout@v4
31-
- name: Run Shellcheck
32-
uses: ludeeus/action-shellcheck@2.0.0
33-
markdownlint:
34-
runs-on: ubuntu-latest
35-
steps:
36-
- name: Checkout repository
37-
uses: actions/checkout@v4
38-
- name: Run mdl
39-
uses: actionshub/markdownlint@main
407

8+
jobs:
9+
ci:
10+
uses: ./.github/workflows/reusable-ci.yml

.github/workflows/reusable-ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Reusable CI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
universe:
7+
description: 'Run in universe mode (checkout chef-cookbooks and copy upstream cookbooks)'
8+
type: boolean
9+
required: false
10+
default: false
11+
additional_ruby_versions:
12+
description: 'JSON string array of additional Ruby versions to add to the matrix (e.g., ["3.2", "3.3"])'
13+
required: false
14+
type: string
15+
default: '[]'
16+
17+
jobs:
18+
prepare-matrix:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
ruby_matrix_json: ${{ steps.generate_matrix.outputs.ruby_matrix_json }}
22+
env:
23+
BASE_RUBY_LIST: '["3.1", "3.3"]'
24+
steps:
25+
- name: Generate Ruby Version Matrix JSON
26+
id: generate_matrix
27+
run: |
28+
if ! command -v jq &> /dev/null; then
29+
echo "jq not found, installing..."
30+
sudo apt-get update && sudo apt-get install -y jq
31+
fi
32+
33+
COMBINED=$(jq -c -n \
34+
--argjson base "${BASE_RUBY_LIST}" \
35+
--argjson extra '${{ inputs.additional_ruby_versions }}' \
36+
'$base + $extra | unique')
37+
38+
echo "ruby_matrix_json=$COMBINED" >> "$GITHUB_OUTPUT"
39+
echo "Final Ruby matrix: $COMBINED"
40+
shell: bash
41+
42+
ruby:
43+
needs: prepare-matrix
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
ruby: ${{ fromJSON(needs.prepare-matrix.outputs.ruby_matrix_json) }}
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout current repository
51+
uses: actions/checkout@v4
52+
with:
53+
path: ${{ inputs.universe && 'universe' || '.' }}
54+
55+
- name: Checkout chef-cookbooks (Universe Mode)
56+
if: inputs.universe
57+
uses: actions/checkout@v4
58+
with:
59+
repository: facebook/chef-cookbooks
60+
path: chef-cookbooks
61+
62+
- name: Setup Ruby
63+
uses: ruby/setup-ruby@v1
64+
with:
65+
ruby-version: ${{ matrix.ruby }}
66+
67+
- name: Install dependencies
68+
run: bundle install
69+
working-directory: ${{ inputs.universe && 'chef-cookbooks' || '.' }}
70+
71+
- name: Run rspec
72+
run: ./scripts/run_chefspec ${{ inputs.universe && '../universe' || '' }}
73+
working-directory: ${{ inputs.universe && 'chef-cookbooks' || '.' }}
74+
75+
- name: Run cookstyle
76+
run: ./scripts/run_cookstyle ${{ inputs.universe && '-C ../universe' || '' }}
77+
working-directory: ${{ inputs.universe && 'chef-cookbooks' || '.' }}
78+
79+
- name: Copy MDL config (Universe Mode)
80+
if: inputs.universe
81+
run: |-
82+
# MDL action won't accept a working-path arg, so it runs from
83+
# the base directory, so that's where we put the configs, and then
84+
# we just tell it what path to check
85+
cp chef-cookbooks/.mdl* .
86+
87+
- name: Run mdl
88+
uses: actionshub/markdownlint@main
89+
with:
90+
path: ${{ inputs.universe && 'universe' || '.' }}
91+
92+
shellcheck:
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout current repository
96+
uses: actions/checkout@v4
97+
98+
- name: Run Shellcheck
99+
uses: ludeeus/action-shellcheck@2.0.0
100+
with:
101+
working-directory: ${{ inputs.universe && 'universe' || '.' }}

scripts/run_mdl

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)