Merge pull request #89 from bcgov/update-readme #83
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: Test, Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
- test | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: "8.2" | |
extensions: mbstring, pdo_mysql, pdo_pgsql, pcntl, exif, bcmath, gd, intl, zip | |
ini-values: | | |
memory_limit=-1 | |
coverage: none | |
- name: Install system dependencies | |
run: | | |
sudo apt-get update && sudo apt-get install -y \ | |
libpq-dev \ | |
libpng-dev \ | |
libonig-dev \ | |
libxml2-dev \ | |
libzip-dev \ | |
libicu-dev \ | |
zip \ | |
unzip \ | |
git \ | |
curl \ | |
postgresql-client \ | |
nodejs \ | |
npm | |
- name: Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
path: vendor | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: ${{ runner.os }}-composer- | |
- name: Install Composer dependencies | |
run: composer install --prefer-dist --no-progress --no-suggest --no-interaction | |
- name: Install Node.js dependencies and build assets | |
run: | | |
npm install | |
npm run build | |
- name: Set up Laravel environment | |
run: | | |
cp .env.example .env | |
php artisan key:generate | |
- name: Run tests | |
run: vendor/bin/pest | |
build: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: | |
image_tag: ${{ steps.meta.outputs.tags }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
environment: ${{ github.ref == 'refs/heads/main' && 'prod' || (github.ref == 'refs/heads/dev' && 'dev') || github.ref == 'refs/heads/test' && 'test' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install oc CLI | |
uses: redhat-actions/oc-installer@v1 | |
- name: Authenticate and set context for OpenShift | |
uses: redhat-actions/oc-login@v1 | |
with: | |
openshift_server_url: ${{ vars.OPENSHIFT_SERVER }} | |
namespace: ${{ vars.OPENSHIFT_NAMESPACE }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
- name: Run Helm upgrade | |
run: | | |
helm upgrade --install klamm-app ./helm --set image.tag=${{ needs.build.outputs.image_tag }} | |
- name: Trigger OpenShift Rollout | |
run: | | |
oc rollout restart deployment/klamm-app |