Skip to content

Merge pull request #2115 from bcgov/develop #68

Merge pull request #2115 from bcgov/develop

Merge pull request #2115 from bcgov/develop #68

Workflow file for this run

name: LCFS 1.0.0 Test CI
on:
push:
branches: [release]
workflow_dispatch:
env:
VERSION: 1.0.0
GIT_URL: https://github.com/bcgov/lcfs.git
TEST_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-test
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
install-oc:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.cache.outputs.cache-hit }}
steps:
- name: Check out repository
uses: actions/[email protected]
- name: Set up cache for OpenShift CLI
id: cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc # Path where the `oc` binary will be installed
key: oc-cli-${{ runner.os }}
- name: Install OpenShift CLI (if not cached)
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz
tar -xvf openshift-client-linux.tar.gz
sudo mv oc /usr/local/bin/
oc version --client
- name: Confirm OpenShift CLI is Available
run: oc version --client
run-tests:
name: Run Tests
runs-on: ubuntu-latest
needs: [install-oc]
steps:
- uses: actions/checkout@v3
with:
repository: bcgov/lcfs
ref: ${{ github.ref }}
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: "3.10.13"
# - name: Set up Node.js
# uses: actions/setup-node@v3
# with:
# node-version: "20"
# - name: Install Docker Compose
# run: |
# sudo apt-get update
# sudo apt-get install -y docker-compose
# - name: Cache Poetry dependencies
# uses: actions/cache@v3
# with:
# path: ~/.cache/pypoetry
# key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
# restore-keys: |
# ${{ runner.os }}-poetry-
# - name: Cache npm dependencies
# uses: actions/cache@v3
# with:
# path: ~/.npm
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-node-
# - name: Install Poetry
# run: pip install poetry==1.6.1
# - name: Install backend dependencies
# run: |
# cd backend
# poetry config virtualenvs.create false
# poetry install
# pip install pytest-github-actions-annotate-failures typing_extensions
# - name: Install frontend dependencies
# run: |
# cd frontend
# npm ci
# - name: Fix docker-compose.yml
# run: |
# sed -i 's/: true/: "true"/g; s/: false/: "false"/g' docker-compose.yml
# - name: Build and start services
# run: |
# docker-compose build
# docker-compose up -d
# - name: Run backend tests
# id: backend_tests
# continue-on-error: true
# run: |
# cd backend
# poetry run pytest --junitxml=pytest-results.xml
# env:
# LCFS_DB_HOST: localhost
# LCFS_DB_PORT: 5432
# LCFS_DB_USER: lcfs
# LCFS_DB_PASS: development_only
# LCFS_DB_BASE: lcfs
# LCFS_REDIS_HOST: localhost
# LCFS_REDIS_PORT: 6379
# LCFS_REDIS_PASSWORD: development_only
# APP_ENVIRONMENT: dev
# LCFS_CHES_CLIENT_ID: mock_client_id
# LCFS_CHES_CLIENT_SECRET: mock_client_secret
# LCFS_CHES_AUTH_URL: http://mock_auth_url
# LCFS_CHES_SENDER_EMAIL: [email protected]
# LCFS_CHES_SENDER_NAME: Mock Notification System
# LCFS_CHES_EMAIL_URL: http://mock_email_url
# - name: Run frontend tests
# id: frontend_tests
# continue-on-error: true
# run: |
# cd frontend
# npm run test:run -- --reporter=junit --outputFile=vitest-results.xml
# env:
# CI: true
# # Comment until all cypress tests are fixed for success.
# # - name: Create cypress.env.json
# # run: |
# # echo '{
# # "admin_idir_username": "${{ secrets.ADMIN_IDIR_USERNAME }}",
# # "admin_idir_password": "${{ secrets.ADMIN_IDIR_PASSWORD }}",
# # "org1_bceid_username": "${{ secrets.ORG1_BCEID_USERNAME }}",
# # "org1_bceid_password": "${{ secrets.ORG1_BCEID_PASSWORD }}",
# # "org1_bceid_id": "${{ secrets.ORG1_BCEID_ID }}",
# # "org1_bceid_userId": "${{ secrets.ORG1_BCEID_USERID }}",
# # "org2_bceid_username": "${{ secrets.ORG2_BCEID_USERNAME }}",
# # "org2_bceid_password": "${{ secrets.ORG2_BCEID_PASSWORD }}",
# # "org2_bceid_id": "${{ secrets.ORG2_BCEID_ID }}",
# # "org2_bceid_userId": "${{ secrets.ORG2_BCEID_USERID }}"
# # }' > frontend/cypress.env.json
# # - name: Run Cypress tests
# # id: cypress_tests
# # continue-on-error: true
# # uses: cypress-io/github-action@v6
# # with:
# # command: npm run cypress:run
# # wait-on: 'http://localhost:3000'
# # working-directory: frontend
# - name: Upload test results
# if: always()
# uses: actions/upload-artifact@v4
# with:
# name: test-results
# path: |
# backend/pytest-results.xml
# frontend/vitest-results.xml
# # frontend/cypress/reports/
# # frontend/cypress/screenshots/
# - name: Stop services
# if: always()
# run: docker-compose down
# - name: Check test results
# if: always()
# run: |
# if [ "${{ steps.backend_tests.outcome }}" == "failure" ] || \
# [ "${{ steps.frontend_tests.outcome }}" == "failure" ]; then
# echo "One or more tests failed"
# exit 1
# fi
set-pre-release:
name: Calculate pre-release number
runs-on: ubuntu-latest
needs: [run-tests]
outputs:
PRE_RELEASE: ${{ steps.set-pre-release.outputs.PRE_RELEASE }}
steps:
- id: set-pre-release
run: echo "PRE_RELEASE=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
build:
name: Build LCFS
runs-on: ubuntu-latest
needs: [set-pre-release]
timeout-minutes: 60
env:
PRE_RELEASE: ${{ needs.set-pre-release.outputs.PRE_RELEASE }}
steps:
- name: Check out repository
uses: actions/[email protected]
- name: Restore oc command from Cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc
key: oc-cli-${{ runner.os }}
- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.TOOLS_NAMESPACE }}
- name: Build LCFS Backend
run: |
cd openshift/templates
oc process -f ./backend-bc.yaml VERSION=${{ env.VERSION }}-${{ env.PRE_RELEASE }} GIT_URL=${{ env.GIT_URL }} GIT_REF=release | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }}
sleep 2s
oc -n ${{ env.TOOLS_NAMESPACE }} start-build lcfs-backend-${{ env.VERSION }}-${{ env.PRE_RELEASE }} --wait=true
- name: Build LCFS Frontend
run: |
cd openshift/templates
oc process -f ./frontend-bc.yaml VERSION=${{ env.VERSION }}-${{ env.PRE_RELEASE }} GIT_URL=${{ env.GIT_URL }} GIT_REF=release | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }}
sleep 2s
oc -n ${{ env.TOOLS_NAMESPACE }} start-build lcfs-frontend-${{ env.VERSION }}-${{ env.PRE_RELEASE }} --wait=true
- name: Tag the source code
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
testtag="${{ env.VERSION }}-${{ env.PRE_RELEASE }}"
git tag $testtag
git push origin $testtag
deploy-on-test:
name: Deploy LCFS on Test
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [set-pre-release, build]
env:
PRE_RELEASE: ${{ needs.set-pre-release.outputs.PRE_RELEASE }}
steps:
- id: get-current-time
run: |
echo "CURRENT_TIME=$(TZ='America/Vancouver' date '+%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_OUTPUT
- name: Ask for approval for LCFS ${{ env.VERSION }}-${{ env.PRE_RELEASE }} Test deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin,kevin-hashimoto
minimum-approvals: 1
issue-title: "LCFS ${{ env.VERSION }}-${{ env.PRE_RELEASE }} Test Deployment at ${{ steps.get-current-time.outputs.CURRENT_TIME }}"
- name: Restore oc command from Cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc
key: oc-cli-${{ runner.os }}
- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.TEST_NAMESPACE }}
- name: Tag LCFS images to Test
run: |
oc tag ${{ env.TOOLS_NAMESPACE }}/lcfs-backend:${{ env.VERSION }}-${{ env.PRE_RELEASE }} ${{ env.TEST_NAMESPACE }}/lcfs-backend:${{ env.VERSION }}-${{ env.PRE_RELEASE }}
oc tag ${{ env.TOOLS_NAMESPACE }}/lcfs-frontend:${{ env.VERSION }}-${{ env.PRE_RELEASE }} ${{ env.TEST_NAMESPACE }}/lcfs-frontend:${{ env.VERSION }}-${{ env.PRE_RELEASE }}
- name: Checkout Manifest repository
uses: actions/checkout@v3
with:
repository: bcgov-c/tenant-gitops-d2bd59
ref: main
ssh-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }}
- name: Update frontend tag
uses: mikefarah/[email protected]
with:
cmd: |
yq -i '.image.tag = "${{ env.VERSION }}-${{ env.PRE_RELEASE }}"' lcfs/charts/lcfs-frontend/values-test.yaml
yq -i '.image.tag = "${{ env.VERSION }}-${{ env.PRE_RELEASE }}"' lcfs/charts/lcfs-backend/values-test.yaml
- name: GitHub Commit & Push
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add lcfs/charts/lcfs-frontend/values-test.yaml
git add lcfs/charts/lcfs-backend/values-test.yaml
git commit -m "Update the image tag to ${{ env.VERSION }}-${{ env.PRE_RELEASE }} on LCFS Test Environment"
git push