run test workflow #219
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- test | |
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 |