-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (155 loc) · 6.23 KB
/
qa.yml
File metadata and controls
172 lines (155 loc) · 6.23 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build QA
on:
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 100
- name: Print build name
run: echo "$GITHUB_ACTOR is building PR#$PR_NUMBER in '$GITHUB_REPOSITORY' (commit $GITHUB_SHA)"
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.m2/repository
key: ${{ runner.os }}-dependency-cache
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
server-id: github
settings-path: ${{ github.workspace }}
- name: Run KtLint
run: ./gradlew ktlintCheck
- name: Run OpenAPI validation
run: |
npm install -g --force @redocly/cli
echo "Validating API docs..."
redocly lint \
--skip-rule=operation-4xx-response \
--skip-rule=security-defined \
--format=stylish \
src/main/resources/static/docs/open-api/*.yaml
redocly stats \
--format=stylish \
src/main/resources/static/docs/open-api/consumer.yaml
redocly stats \
--format=stylish \
src/main/resources/static/docs/open-api/creator.yaml
- name: Build and test service
env:
BUILD_QUALITY: "PR"
run: ./gradlew build
- name: Generate SDK
if: "!contains(github.event.head_commit.message, 'skip ci')"
run: |
# Prepare the variables
VERSION=$(scripts/prop.sh version)
ROOT_DIR=$(pwd)
SPECS_DIR=$(pwd)/src/main/resources/static/docs/open-api
# Run the process for each spec
for SPEC in creator consumer; do
echo "Running SDK generation for $SPEC..."
# Prepare the output directory
OUTPUT_DIR=$(pwd)/build/libs/sdk/$SPEC
mkdir -p $OUTPUT_DIR
# Run the generator
docker run --rm \
-v $SPECS_DIR:/specs:ro \
-v $OUTPUT_DIR:/output:rw \
openapitools/openapi-generator-cli generate \
-i /specs/$SPEC.yaml \
-g python \
-o /output \
--enable-post-process-file \
--additional-properties=identifierNamingConvention=snake_case,packageName=appifyhub,packageVersion=${VERSION}
# Run the tests
cd $OUTPUT_DIR
pip install -r requirements.txt
pip install pytest
pytest
# Copy the SDK to the main directory
cd $ROOT_DIR
cp -r $OUTPUT_DIR $ROOT_DIR/sdk
done
# Publish as a commit
git config user.name 'GitHub Action'
git config user.email 'action@github.com'
git add sdk
if git diff --staged --quiet; then
echo "No changes detected in SDK docs."
else
git commit -m "Update SDK docs [skip ci]"
git push origin HEAD:${{ github.head_ref }}
fi
- name: Codacy Coverage Report
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
- name: Build Docker image
run: docker build . --file Dockerfile --tag service
- name: Auth for GitHub's Docker repository
env:
USER: ${{ secrets.PACKAGES_USER }}
TOKEN: ${{ secrets.PACKAGES_TOKEN }}
run: docker login docker.pkg.github.com -u $USER -p $TOKEN
- name: Tag Docker image
env:
PR_NUMBER: ${{ github.event.number }}
run: |
VERSION=$(scripts/prop.sh version)
echo "Tagging images with version '$VERSION'..."
docker tag service docker.pkg.github.com/$GITHUB_REPOSITORY/service:"$VERSION".pr_$PR_NUMBER
docker tag service docker.pkg.github.com/$GITHUB_REPOSITORY/service:latest_pr
docker tag service appifyhub/service:"$VERSION".pr_$PR_NUMBER
docker tag service appifyhub/service:latest_pr
- name: Publish Docker images to GitHub
env:
PR_NUMBER: ${{ github.event.number }}
run: |
VERSION=$(scripts/prop.sh version)
echo "Publishing images with version '$VERSION'..."
docker push docker.pkg.github.com/$GITHUB_REPOSITORY/service:"$VERSION".pr_$PR_NUMBER
docker push docker.pkg.github.com/$GITHUB_REPOSITORY/service:latest_pr
- name: Publish Docker images to DockerHub
id: docker_publish
env:
USER: ${{ secrets.DOCKER_HUB_USER }}
TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
run: |
VERSION=$(scripts/prop.sh version)
docker login docker.io -u $USER -p $TOKEN
echo "Publishing images with version '$VERSION'..."
docker push appifyhub/service:"$VERSION".pr_$PR_NUMBER
docker push appifyhub/service:latest_pr
echo ::set-output name=service_version::"$VERSION"
- name: Comment build information
env:
GITHUB_SHA: ${{ env.GITHUB_SHA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_RUN_ID: ${{ env.GITHUB_RUN_ID }}
GITHUB_REPOSITORY: ${{ env.GITHUB_REPOSITORY }}
GITHUB_SERVER_URL: ${{ env.GITHUB_SERVER_URL }}
PR_NUMBER: ${{ github.event.number }}
VERSION: ${{ steps.docker_publish.outputs.service_version }}
DOCKER_IMG: "docker pull appifyhub/service"
run: |
NL=$'\n'
CODE='```'
DOCKER_VERSIONED="$DOCKER_IMG:$VERSION.pr_$PR_NUMBER"
DOCKER_LATEST="# Valid until a new build${NL}${DOCKER_IMG}:latest_pr"
CODE_BLOCK="${CODE}shell${NL}${DOCKER_LATEST}${NL}${DOCKER_VERSIONED}${NL}${CODE}"
JOB="[${GITHUB_RUN_ID}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})"
NOTIFICATION="Build ${JOB} complete for ${GITHUB_SHA}.${NL}${NL}${CODE_BLOCK}${NL}"
gh pr comment "$PR_NUMBER" -b "$NOTIFICATION"