forked from crater-invoice/crater
-
Notifications
You must be signed in to change notification settings - Fork 5
141 lines (126 loc) · 4.68 KB
/
ci.yaml
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
name: CI
on:
push:
branches:
- bahmni-master
tags:
- "*"
pull_request:
branches:
- bahmni-master
env:
CRATER_VERSION: 1.1.0
jobs:
build-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1']
name: PHP ${{ matrix.php }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: exif
- name: Install PHP 7 dependencies
run: composer update --no-interaction --no-progress
if: "matrix.php < 8"
- name: Install PHP 8 dependencies
run: composer update --ignore-platform-req=php --no-interaction --no-progress
if: "matrix.php >= 8"
- name: Yarn install
run: yarn
- name: Yarn build
run: yarn build
- name: Upload public folder
uses: actions/upload-artifact@v3
with:
name: crater-artifact
path: public/build/
# - name: Check coding style
# run: ./vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --config=.php-cs-fixer.dist.php
- name: Unit Tests
run: php ./vendor/bin/pest
docker:
if: ${{ needs.build-test.result == 'success' && github.event_name != 'pull_request'}}
# env is not avaialble in context of evaluating condition or building another env. workaround was to use seperate steps to construct VERSION_TAG env variable
# env:
# VERSION_TAG: ${{ startsWith(github.ref, 'refs/tags/v') && env.CRATER_VERSION || env.CRATER_VERSION-github.run_number }}
name: Docker build and publish
runs-on: ubuntu-latest
needs:
- build-test
env:
HELM_CHART_PATH: package/helm/crater
steps:
- name: check if prod release
if: startsWith(github.ref, 'refs/tags/bahmni')
run: |
echo "VERSION_TAG=${{ env.CRATER_VERSION }}"
echo "VERSION_TAG=${{ env.CRATER_VERSION }}" >> $GITHUB_ENV
- name: check if dev release
if: startsWith(github.ref, 'refs/tags/bahmni-') != true
run: |
echo "VERSION_TAG=${{ env.CRATER_VERSION }}-${{ github.run_number }}"
echo "VERSION_TAG=${{ env.CRATER_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v2
- name: Download public folder
uses: actions/download-artifact@v3
with:
name: crater-artifact
path: public/build/
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Docker Build and push crater-php
uses: docker/build-push-action@v2
with:
context: .
file: docker/Dockerfile
push: true
# :product is just a temp tag - eventually the crater-image would come from the craterapp dockerhub repo
# PR https://github.com/crater-invoice/crater/pull/922
tags: bahmni/crater-php:product,bahmni/crater-php:product-${{env.VERSION_TAG}}
- name: Docker Build and push crater-nginx
uses: docker/build-push-action@v2
with:
context: .
file: docker/nginx.Dockerfile
push: true
tags: bahmni/crater-nginx:${{env.VERSION_TAG}},bahmni/crater-nginx:latest
trigger-dependent-repos:
name: Trigger Workflows
needs: docker
runs-on: ubuntu-latest
steps:
- name: check if prod release
if: startsWith(github.ref, 'refs/tags/bahmni-')
run: |
echo "VERSION_TAG=${{ env.CRATER_VERSION }}"
echo "VERSION_TAG=${{ env.CRATER_VERSION }}" >> $GITHUB_ENV
- name: check if dev release
if: startsWith(github.ref, 'refs/tags/bahmni-') != true
run: |
echo "VERSION_TAG=${{ env.CRATER_VERSION }}-${{ github.run_number }}"
echo "VERSION_TAG=${{ env.CRATER_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV
- name: Create repository_dispatch
env:
REPOSITORY_NAME: crater-extensions
ORG_NAME: Bahmni
EVENT_TYPE: crater-php-trigger
run: |
trigger_result=$(curl -s -o trigger_response.txt -w "%{http_code}" -X POST -H "Accept: application/vnd.github.v3+json" -H 'authorization: Bearer ${{ secrets.BAHMNI_PAT }}' https://api.github.com/repos/${ORG_NAME}/${REPOSITORY_NAME}/dispatches -d '{"event_type":"'"${EVENT_TYPE}"'","client_payload":{"crater_nginx_version":"'"${VERSION_TAG}"'"}}')
if [ $trigger_result == 204 ];then
echo "Trigger to $ORG_NAME/$REPOSITORY_NAME Success"
else
echo "Trigger to $ORG_NAME/$REPOSITORY_NAME Failed"
cat trigger_response.txt
exit 1
fi