-
Notifications
You must be signed in to change notification settings - Fork 68
155 lines (130 loc) · 5.92 KB
/
openapi.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# This workflow will build and run the application for oasdiff/oasdiff-action/breaking@main
# For more information see: https://github.com/oasdiff/oasdiff-action
name: OpenAPI breaking changes check
on: [push, pull_request]
env:
MAVEN_ARGS: '-B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn'
jobs:
opeanpi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Debug GitHub variables
run: |
echo "GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}"
echo "GITHUB_HEAD_REPOSITORY: ${GITHUB_HEAD_REPOSITORY}"
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}"
echo "GITHUB_REF: ${GITHUB_REF}"
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}"
- name: Determine PR source branch and fork repository
id: vars
run: |
# Set default FORK_REPO and BRANCH_NAME values.
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF##*/}}"
if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REPOSITORY" == "informatici/openhospital-api" ]]; then
# For pushes to the main repository, default to the main core repo
FORK_REPO="informatici/openhospital-core"
else
# For pull requests or other pushes, use the contributor fork if applicable
if [[ -n "$GITHUB_HEAD_REPOSITORY" ]]; then
FORK_REPO="$GITHUB_HEAD_REPOSITORY"
else
# Check if the actor's repo exists with the branch
FORK_REPO="${GITHUB_ACTOR}/openhospital-core"
CHECK_BRANCH_URL="https://github.com/$FORK_REPO/tree/$BRANCH_NAME"
echo "Checking branch existence with: curl -s -o /dev/null -w \"%{http_code}\" $CHECK_BRANCH_URL"
if curl -s -o /dev/null -w "%{http_code}" "$CHECK_BRANCH_URL" | grep -q "200"; then
echo "Branch $BRANCH_NAME exists in $FORK_REPO."
else
# Fallback to the main repository if the branch doesn’t exist in the fork
FORK_REPO="informatici/openhospital-core"
fi
fi
fi
# Export FORK_REPO and BRANCH_NAME to GITHUB_ENV for the next step
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "FORK_REPO=$FORK_REPO" >> $GITHUB_ENV
- name: Log variables
run: |
echo "FORK_REPO: ${{ env.FORK_REPO }}"
echo "BRANCH_NAME: ${{ env.BRANCH_NAME }}"
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
java-package: jdk
- name: Checkout core
run: |
git clone --depth=1 --no-single-branch https://github.com/${{ env.FORK_REPO }}.git openhospital-core
pushd openhospital-core
git checkout -B ${{ env.BRANCH_NAME }} origin/${{ env.BRANCH_NAME }} || git checkout develop
popd
- name: Install core
run: |
pushd openhospital-core
mvn install -DskipTests=true
popd
- name: Generate JWT Token
id: jwt
run: echo "token=7DlyD1SHR5pCa4HGgTLWSYm8YQ7oRL1wpPbxyjWyHU44vUrqrooRu3lHVFSXWChesc" >> $GITHUB_OUTPUT
- name: Build with Maven
run: |
cp rsc/database.properties.dist rsc/database.properties
cp rsc/log4j2-spring.properties.dist rsc/log4j2-spring.properties
cp rsc/settings.properties.dist rsc/settings.properties
sed -e "s/JWT_TOKEN_SECRET/${{ steps.jwt.outputs.token }}/g" -e "s/API_HOST/localhost/g" -e "s/API_PORT/8080/g" rsc/application.properties.dist > rsc/application.properties
mvn install -DskipTests=true
- name: Run API
run: |
pushd target
java -cp "openhospital-api-0.1.0.jar:rsc/:static/" org.springframework.boot.loader.launch.JarLauncher &
sleep 60
popd
- name: Generate OpenAPI yaml
run: mvn springdoc-openapi:generate -Dspringdoc.outputFileName=oh_rev.yaml
# Step 1: Check if oh_rev.yaml differs from the committed version
- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Install jq
run: sudo apt-get install -y jq
- name: Convert to JSON and sort
run: |
yq eval -o=json openapi/oh_rev.yaml > oh_rev.json
yq eval -o=json openapi/oh.yaml > oh.json
jq --sort-keys . oh_rev.json > sorted_oh_rev.json
jq --sort-keys . oh.json > sorted_oh.json
- name: Compare JSON files
if: github.event_name == 'pull_request'
run: |
if diff sorted_oh_rev.json sorted_oh.json; then
echo "No changes in OpenAPI spec. Everything is up to date."
else
echo "The OpenAPI spec has changed. Please update the committed version."
exit 1
fi
# Step 2: Check for breaking changes between destination branch oh.yaml and the generated oh_rev.yaml
- name: Checkout Base Branch
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}:base_branch
git checkout base_branch
- name: Run OpenAPI Spec breaking action
id: oasdiff
uses: oasdiff/oasdiff-action/breaking@main
with:
base: openapi/oh.yaml # destination branch oh.yaml
revision: openapi/oh_rev.yaml # generated oh_rev.yaml
format: detailed
# fail-on-diff: false
- name: Show breaking changes output
run: |
echo "Breaking changes output: ${{ steps.oasdiff.outputs.breaking }}"
if [[ "${{ steps.oasdiff.outputs.breaking }}" != "No breaking changes" ]]; then
echo "Warning: Breaking changes detected."
exit 1
fi