1+ # A lot of this was inspired by https://brunoscheufler.com/blog/2022-04-24-required-github-actions-jobs-in-a-monorepo
2+
3+ name : OpenAPI spec
4+
5+ on :
6+ pull_request :
7+ paths :
8+ - ' api/src/Entity'
9+ - ' .github/workflows/openapi.yaml'
10+ jobs :
11+ change-detection :
12+ runs-on : ubuntu-latest
13+ outputs :
14+ openapi : ${{ steps.changes.outputs.openapi }}
15+ steps :
16+ - uses : dorny/paths-filter@v2
17+ id : changes
18+ with :
19+ list-files : shell
20+ filters : |
21+ openapi:
22+ - 'api/src/Entity/**'
23+ build :
24+ needs : change-detection
25+ if : needs.change-detection.outputs.openapi == 'true'
26+ runs-on : ubuntu-latest
27+ steps :
28+ - uses : actions/checkout@v2
29+
30+ - name : Start the containers
31+ working-directory : ./api
32+ run : docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --build
33+
34+ - name : Install composer packages
35+ working-directory : ./api
36+ run : docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api composer install
37+
38+ - name : Run Database migrations
39+ working-directory : ./api
40+ run : docker-compose -f docker-compose.yml -f docker-compose.test.yml exec -T api bin/console --no-interaction doctrine:migration:migrate
41+
42+ - name : Generate openapi.yaml
43+ working-directory : ./api
44+ run : docker-compose exec -T api bash -c "bin/console api:openapi:export --yaml" > ../docs/generated/openapi.yaml
45+
46+ - name : Archive openapi artifacts
47+ uses : actions/upload-artifact@v3
48+ with :
49+ name : openapi_spec_artifact
50+ path : |
51+ docs/generated
52+
53+ - name : Stop containers
54+ working-directory : ./api
55+ if : always()
56+ run : docker-compose -f docker-compose.yml -f docker-compose.test.yml down
57+
58+ after-build :
59+ needs : build # run after tests
60+ runs-on : ubuntu-latest
61+ if : success() # only run when all test have passed
62+ # store success output flag for ci job
63+ outputs :
64+ success : ${{ steps.setoutput.outputs.success }}
65+ steps :
66+ - id : setoutput
67+ run : echo "::set-output name=success::true"
68+
69+ dummy-step :
70+ runs-on : ubuntu-latest
71+ needs : change-detection
72+ # runs if API was not changed
73+ if : needs.change-detection.outputs.openapi == 'false'
74+ outputs :
75+ success : ${{ steps.setoutput.outputs.success }}
76+ steps :
77+ - id : setoutput
78+ run : echo "::set-output name=success::true"
79+
80+
81+ # step that will be used for required status check
82+ # make sure it has a unique name! this will always run, but
83+ # after the tests & after-tests steps or the dummy step in case
84+ # the API was not modified
85+ ci_openapi :
86+ runs-on : ubuntu-20.04
87+ if : always()
88+ needs : [build, after-build, dummy-step]
89+ steps :
90+ - run : |
91+ passed="${{ needs.after-build.outputs.success || needs.dummy-step.outputs.success }}"
92+ if [[ $passed == "true" ]]; then
93+ echo "Build passed"
94+ exit 0
95+ else
96+ echo "Build failed"
97+ exit 1
98+ fi
0 commit comments