1+ name : Keboola Component Build & Deploy Pipeline
2+ on :
3+ push :
4+ branches :
5+ - ' feature/*'
6+ - ' bug/*'
7+ tags :
8+ - ' *' # Skip the workflow on the main branch without tags
9+
10+ concurrency : ci-${{ github.ref }} # to avoid tag collisions in the ECR
11+ env :
12+ # repository variables:
13+ KBC_DEVELOPERPORTAL_APP : " kds-team.ex-onedrive" # replace with your component id
14+ KBC_DEVELOPERPORTAL_VENDOR : " kds-team" # replace with your vendor
15+ DOCKERHUB_USER : ${{ secrets.DOCKERHUB_USER }}
16+ KBC_DEVELOPERPORTAL_USERNAME : " kds-team+github"
17+
18+ # repository secrets:
19+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }} # recommended for pushing to ECR
20+ KBC_DEVELOPERPORTAL_PASSWORD : ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
21+
22+ # (Optional) Test KBC project: https://connection.keboola.com/admin/projects/0000
23+ KBC_TEST_PROJECT_CONFIGS : " " # space separated list of config ids
24+ KBC_STORAGE_TOKEN : ${{ secrets.KBC_STORAGE_TOKEN }} # required for running KBC tests
25+
26+ jobs :
27+ push_event_info :
28+ name : Push Event Info
29+ runs-on : ubuntu-latest
30+ outputs :
31+ app_image_tag : ${{ steps.tag.outputs.app_image_tag }}
32+ is_semantic_tag : ${{ steps.tag.outputs.is_semantic_tag }}
33+ is_default_branch : ${{ steps.default_branch.outputs.is_default_branch }}
34+ is_deploy_ready : ${{ steps.deploy_ready.outputs.is_deploy_ready }}
35+ steps :
36+ - name : Checkout Repository
37+ uses : actions/checkout@v4
38+
39+ - name : Fetch all branches from remote repository
40+ run : git fetch --prune --unshallow --tags -f
41+
42+ - name : Get current branch name
43+ id : current_branch
44+ run : |
45+ if [[ ${{ github.ref }} != "refs/tags/"* ]]; then
46+ branch_name=${{ github.ref_name }}
47+ echo "branch_name=$branch_name" | tee -a $GITHUB_OUTPUT
48+ else
49+ raw=$(git branch -r --contains ${{ github.ref }})
50+ branch="$(echo ${raw//origin\//} | tr -d '\n')"
51+ echo "branch_name=$branch" | tee -a $GITHUB_OUTPUT
52+ fi
53+
54+ - name : Is current branch the default branch
55+ id : default_branch
56+ run : |
57+ echo "default_branch='${{ github.event.repository.default_branch }}'"
58+ if [ "${{ github.event.repository.default_branch }}" = "${{ steps.current_branch.outputs.branch_name }}" ]; then
59+ echo "is_default_branch=true" | tee -a $GITHUB_OUTPUT
60+ else
61+ echo "is_default_branch=false" | tee -a $GITHUB_OUTPUT
62+ fi
63+
64+ - name : Set image tag
65+ id : tag
66+ run : |
67+ TAG="${GITHUB_REF##*/}"
68+ IS_SEMANTIC_TAG=$(echo "$TAG" | grep -q '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$' && echo true || echo false)
69+ echo "is_semantic_tag=$IS_SEMANTIC_TAG" | tee -a $GITHUB_OUTPUT
70+ echo "app_image_tag=$TAG" | tee -a $GITHUB_OUTPUT
71+
72+ - name : Deploy-Ready check
73+ id : deploy_ready
74+ run : |
75+ if [[ "${{ steps.default_branch.outputs.is_default_branch }}" == "true" \
76+ && "${{ github.ref }}" == refs/tags/* \
77+ && "${{ steps.tag.outputs.is_semantic_tag }}" == "true" ]]; then
78+ echo "is_deploy_ready=true" | tee -a $GITHUB_OUTPUT
79+ else
80+ echo "is_deploy_ready=false" | tee -a $GITHUB_OUTPUT
81+ fi
82+
83+ build :
84+ name : Docker Image Build
85+ runs-on : ubuntu-latest
86+ needs :
87+ - push_event_info
88+ env :
89+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
90+ steps :
91+ - name : Checkout Repository
92+ uses : actions/checkout@v4
93+
94+ - name : Set up Docker Buildx
95+ uses : docker/setup-buildx-action@v3
96+
97+ - name : Build and push
98+ uses : docker/build-push-action@v5
99+ with :
100+ context : .
101+ file : ./Dockerfile
102+ tags : ${{ env.KBC_DEVELOPERPORTAL_APP }}:latest
103+ outputs : type=docker,dest=/tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
104+
105+ - name : Upload artifact
106+ uses : actions/upload-artifact@v4
107+ with :
108+ name : ${{ env.KBC_DEVELOPERPORTAL_APP }}
109+ path : /tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
110+
111+ tests :
112+ name : Run Tests
113+ runs-on : ubuntu-latest
114+ needs :
115+ - push_event_info
116+ - build
117+ steps :
118+ - name : Set up Docker Buildx
119+ uses : docker/setup-buildx-action@v3
120+
121+ - name : Download artifact
122+ uses : actions/download-artifact@v4
123+ with :
124+ name : ${{ env.KBC_DEVELOPERPORTAL_APP }}
125+ path : /tmp
126+
127+ - name : Load Image & Run Tests
128+ run : |
129+ docker load --input /tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
130+ docker image ls -a
131+ docker run ${{ env.KBC_DEVELOPERPORTAL_APP }}:latest flake8 . --config=flake8.cfg
132+ echo "Running unit-tests..."
133+ docker run ${{ env.KBC_DEVELOPERPORTAL_APP }}:latest python -m unittest discover
134+
135+ tests-kbc :
136+ name : Run KBC Tests
137+ needs :
138+ - push_event_info
139+ - build
140+ runs-on : ubuntu-latest
141+ steps :
142+ - name : Set up environment variables
143+ run : |
144+ echo "KBC_TEST_PROJECT_CONFIGS=${KBC_TEST_PROJECT_CONFIGS}" >> $GITHUB_ENV
145+ echo "KBC_STORAGE_TOKEN=${{ secrets.KBC_STORAGE_TOKEN }}" >> $GITHUB_ENV
146+
147+ - name : Run KBC test jobs
148+ if : env.KBC_TEST_PROJECT_CONFIGS != '' && env.KBC_STORAGE_TOKEN != ''
149+ uses : keboola/action-run-configs-parallel@master
150+ with :
151+ token : ${{ secrets.KBC_STORAGE_TOKEN }}
152+ componentId : ${{ env.KBC_DEVELOPERPORTAL_APP }}
153+ tag : ${{ needs.push_event_info.outputs.app_image_tag }}
154+ configs : ${{ env.KBC_TEST_PROJECT_CONFIGS }}
155+
156+ push :
157+ name : Docker Image Push
158+ runs-on : ubuntu-latest
159+ needs :
160+ - push_event_info
161+ - tests
162+ - tests-kbc
163+ env :
164+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
165+ steps :
166+ - name : Checkout Repository
167+ uses : actions/checkout@v4
168+
169+ - name : Download artifact
170+ uses : actions/download-artifact@v4
171+ with :
172+ name : ${{ env.KBC_DEVELOPERPORTAL_APP }}
173+ path : /tmp
174+
175+ - name : Load Image & Run Tests
176+ run : |
177+ docker load --input /tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
178+ docker image ls -a
179+
180+ - name : Docker login
181+ if : env.DOCKERHUB_TOKEN
182+ run : docker login --username "${{ env.DOCKERHUB_USER }}" --password "${{ env.DOCKERHUB_TOKEN }}"
183+
184+ - name : Push image to ECR
185+ uses : keboola/action-push-to-ecr@master
186+ with :
187+ vendor : ${{ env.KBC_DEVELOPERPORTAL_VENDOR }}
188+ app_id : ${{ env.KBC_DEVELOPERPORTAL_APP }}
189+ username : ${{ env.KBC_DEVELOPERPORTAL_USERNAME }}
190+ password : ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
191+ tag : ${{ needs.push_event_info.outputs.app_image_tag }}
192+ push_latest : ${{ needs.push_event_info.outputs.is_deploy_ready }}
193+ source_image : ${{ env.KBC_DEVELOPERPORTAL_APP }}
194+
195+ deploy :
196+ name : Deploy to KBC
197+ env :
198+ KBC_DEVELOPERPORTAL_PASSWORD : ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
199+ needs :
200+ - push_event_info
201+ - build
202+ - push
203+ if : needs.push_event_info.outputs.is_deploy_ready == 'true'
204+ runs-on : ubuntu-latest
205+ steps :
206+ - name : Set Developer Portal Tag
207+ uses : keboola/action-set-tag-developer-portal@master
208+ with :
209+ vendor : ${{ env.KBC_DEVELOPERPORTAL_VENDOR }}
210+ app_id : ${{ env.KBC_DEVELOPERPORTAL_APP }}
211+ username : ${{ env.KBC_DEVELOPERPORTAL_USERNAME }}
212+ password : ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
213+ tag : ${{ needs.push_event_info.outputs.app_image_tag }}
214+
215+ update_developer_portal_properties :
216+ name : Developer Portal Properties Update
217+ env :
218+ KBC_DEVELOPERPORTAL_PASSWORD : ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
219+ needs :
220+ - push_event_info
221+ - build
222+ - push
223+ runs-on : ubuntu-latest
224+ if : needs.push_event_info.outputs.is_deploy_ready == 'true'
225+ steps :
226+ - name : Checkout Repository
227+ uses : actions/checkout@v4
228+
229+ - name : Update developer portal properties
230+ run : |
231+ chmod +x scripts/developer_portal/*.sh
232+ scripts/developer_portal/update_properties.sh
0 commit comments