1+ name : Reusable Ruby Testing Workflow
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ ruby-versions :
7+ description : ' JSON array of Ruby versions to test against'
8+ required : false
9+ type : string
10+ default : ' ["2.7", "3.2", "jruby-9.4.12.0"]'
11+ platforms :
12+ description : ' JSON array of platforms to run tests on'
13+ required : false
14+ type : string
15+ default : ' ["ubuntu-latest"]'
16+ test-script :
17+ description : ' Test script to execute'
18+ required : false
19+ type : string
20+ default : ' ./run-tests.sh'
21+ examples-script :
22+ description : ' Examples script to execute'
23+ required : false
24+ type : string
25+ default : ' ./check-examples.sh'
26+ cache-version :
27+ description : ' Cache version for gem dependencies'
28+ required : false
29+ type : string
30+ default : ' '
31+ enable-status-reporting :
32+ description : ' Whether to post status checks to datadog-api-spec repo'
33+ required : false
34+ type : boolean
35+ default : false
36+ status-context :
37+ description : ' Context for status checks'
38+ required : false
39+ type : string
40+ default : ' master/unit'
41+ secrets :
42+ PIPELINE_GITHUB_APP_ID :
43+ required : false
44+ PIPELINE_GITHUB_APP_PRIVATE_KEY :
45+ required : false
46+ DD_API_KEY :
47+ required : false
48+
49+ jobs :
50+ pre-commit :
51+ runs-on : ubuntu-latest
52+ if : >
53+ (github.event.pull_request.draft == false &&
54+ !contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
55+ !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
56+ github.event_name == 'schedule'
57+ steps :
58+ - name : Get GitHub App token
59+ id : get_token
60+ uses : actions/create-github-app-token@v1
61+ with :
62+ app-id : ${{ secrets.PIPELINE_GITHUB_APP_ID }}
63+ private-key : ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
64+ - uses : actions/checkout@v3
65+ with :
66+ fetch-depth : 0
67+ ref : ${{ github.event.pull_request.head.sha }}
68+ token : ${{ steps.get_token.outputs.token }}
69+ - uses : actions/setup-python@v4
70+ with :
71+ python-version : ' 3.11'
72+ - name : Install pre-commit
73+ run : python -m pip install pre-commit
74+ - name : set PY
75+ run : echo "PY=$(python -c 'import platform;print(platform.python_version())')" >> $GITHUB_ENV
76+ - uses : actions/cache@v3
77+ with :
78+ path : ~/.cache/pre-commit
79+ key : pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
80+ - id : pre_commit
81+ name : Run pre-commit
82+ if : github.event.action != 'closed' && github.event.pull_request.merged != true
83+ run : |
84+ pre-commit run --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always
85+ env :
86+ FROM_REF : ${{ github.event.pull_request.base.sha }}
87+ TO_REF : ${{ github.event.pull_request.head.sha }}
88+ - name : Commit changes
89+ if : ${{ failure() }}
90+ run : |-
91+ git add -A
92+ git config user.name "${GIT_AUTHOR_NAME}"
93+ git config user.email "${GIT_AUTHOR_EMAIL}"
94+ git commit -m "pre-commit fixes"
95+ git push origin "HEAD:${HEAD_REF}"
96+ exit 1
97+ env :
98+ HEAD_REF : ${{ github.event.pull_request.head.ref }}
99+ GIT_AUTHOR_EMAIL : " packages@datadoghq.com"
100+ GIT_AUTHOR_NAME : " ci.datadog-api-spec"
101+ - id : pre_commit_schedule
102+ name : Run pre-commit in schedule
103+ if : github.event_name == 'schedule'
104+ run : |
105+ pre-commit run --all-files --show-diff-on-failure --color=always
106+
107+ test :
108+ strategy :
109+ matrix :
110+ ruby-version : ${{ fromJSON(inputs.ruby-versions) }}
111+ platform : ${{ fromJSON(inputs.platforms) }}
112+ runs-on : ${{ matrix.platform }}
113+ if : (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
114+ env :
115+ BUNDLE_WITHOUT : docs
116+ DD_PROFILING_NO_EXTENSION : true
117+ DD_CIVISIBILITY_AGENTLESS_ENABLED : true
118+ DD_ENV : prod
119+ DD_API_KEY : ${{ secrets.DD_API_KEY }}
120+ steps :
121+ - uses : actions/checkout@v3
122+ - name : Set up Ruby ${{ matrix.ruby-version }}
123+ uses : ruby/setup-ruby@v1
124+ with :
125+ ruby-version : ${{ matrix.ruby-version }}
126+ bundler-cache : true
127+ cache-version : ${{ inputs.cache-version }}
128+ - name : Test
129+ run : ${{ inputs.test-script }}
130+ shell : bash
131+
132+ examples :
133+ runs-on : ubuntu-latest
134+ if : (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
135+ env :
136+ DD_PROFILING_NO_EXTENSION : true
137+ steps :
138+ - uses : actions/checkout@v3
139+ - name : Set up Ruby
140+ uses : ruby/setup-ruby@v1
141+ with :
142+ ruby-version : " 2.7"
143+ bundler-cache : true
144+ cache-version : ${{ inputs.cache-version }}
145+ - name : Check examples
146+ run : ${{ inputs.examples-script }}
147+ shell : bash
148+
149+ report :
150+ runs-on : ubuntu-latest
151+ if : always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && inputs.enable-status-reporting
152+ needs :
153+ - test
154+ - examples
155+ steps :
156+ - name : Get GitHub App token
157+ if : github.event_name == 'pull_request'
158+ id : get_token
159+ uses : actions/create-github-app-token@v1
160+ with :
161+ app-id : ${{ secrets.PIPELINE_GITHUB_APP_ID }}
162+ private-key : ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
163+ repositories : datadog-api-spec
164+ - name : Post status check
165+ uses : DataDog/github-actions/post-status-check@v2
166+ with :
167+ github-token : ${{ steps.get_token.outputs.token }}
168+ repo : datadog-api-spec
169+ status : ${{ (needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }}
170+ context : ${{ inputs.status-context }}
0 commit comments