Skip to content

Commit

Permalink
Updated SSL test / notification to fix quoting / substitution and SSL…
Browse files Browse the repository at this point in the history
…_EXPIRY_DAYS
  • Loading branch information
warrenchristian1telus committed Oct 1, 2024
1 parent ea1c117 commit 46445b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ jobs:
needs: [checkEnv, call-deploy-workflow]
outputs:
LHRESULT: ${{ steps.lighthouse.outputs.LHRESULT }}
SSL_EXPIRY_DAYS: ${{ steps.ssl-output.outputs.SSL_EXPIRY_DAYS }}
SSL_EXPIRY_DAYS: ${{ steps.ssl-test.outputs.SSL_EXPIRY_DAYS }}
if: |
always() &&
(
Expand All @@ -236,7 +236,6 @@ jobs:
- name: Run Lighthouse Tests
id: lighthouse
run: |
sleep 120 # Wait for the deployment to be ready
`echo "LHRESULT=$(node openshift/config/lighthouse/lighthouse-auth.js)" >> $GITHUB_OUTPUT`
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_NAME }}-${{ github.ref_name }}.apps.silver.devops.gov.bc.ca
Expand All @@ -254,10 +253,7 @@ jobs:
.then(info => console.log(info.daysRemaining))
.catch(err => console.error(err));
")
echo "SSL_EXPIRY_DAYS=$SSL_EXPIRY_DAYS" >> $GITHUB_ENV
- name: Set SSL Check Output
id: ssl-output
run: echo "SSL_EXPIRY_DAYS=${{ env.SSL_EXPIRY_DAYS }}" >> $GITHUB_OUTPUT
echo "SSL_EXPIRY_DAYS=$SSL_EXPIRY_DAYS" >> $GITHUB_OUTPUT
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -290,21 +286,21 @@ jobs:
with:
name: lighthouse-artifacts
path: artifacts
- name: Set Emoji for SSL Status Icon
- name: Set Emoji for Notification Status Icon
id: notification-emoji
run: |
if [[ "${{ needs.lighthouse-check.result }}" == "success" ]]; then
`echo "EMOJI=:rocket:" >> $GITHUB_OUTPUT`
else
`echo "EMOJI=:boom:" >> $GITHUB_OUTPUT`
fi
- name: Set Emoji for Notification Status Icon
- name: Set Emoji for SSL Status Icon
id: ssl-status-emoji
run: |
if [[ "${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }}" < ${{ env.SSL_EXPIRY_NOTICE_DAYS }} ]]; then
`echo "SSL_TEST_RESULT=:warn: Warning! SSL Certificate will EXPIRE in ${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }} days." >> $GITHUB_OUTPUT`
if [[ "${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }}" -lt ${{ env.SSL_EXPIRY_NOTICE_DAYS }} ]]; then
echo "SSL_TEST_RESULT=:warn: Warning! SSL Certificate will EXPIRE in ${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }} days." >> $GITHUB_OUTPUT
else
`echo "SSL_TEST_RESULT=:check: SSL Certificat EXPIRES in ${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }} days." >> $GITHUB_OUTPUT`
echo "SSL_TEST_RESULT=:check: SSL Certificat EXPIRES in ${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }} days." >> $GITHUB_OUTPUT
fi
- name: 📫 Send Notification
uses: muinmomin/[email protected]
Expand Down
25 changes: 23 additions & 2 deletions openshift/config/lighthouse/lighthouse-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,33 @@ const options = {
};
const testURL = 'https://' + process.env.APP_HOST_URL + '/login'

async function isSiteAvailable(url, timeout = 300000, interval = 10000) {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {
try {
const response = await fetch(url);
if (response.ok) {
return true;
}
} catch (error) {
// Ignore errors and continue retrying
}
await new Promise(resolve => setTimeout(resolve, interval));
}
throw new Error(`Site ${url} is not available after ${timeout / 1000} seconds`);
}

async function runLighthouse(url, options, config = null) {
// Import chrome-launcher
// Wait for the site to be available
await isSiteAvailable(url);

// Use Puppeteer to launch a browser and perform the login
const { launch } = await import('chrome-launcher');

// Detect encoding issues/warnings in returned HTML
const detectEncodingIssues = ['â', '€', '™', 'Â', 'œ', ''];
let errors = new Array();
let warnings = new Array();
const { launch } = await import('chrome-launcher');

// Launch a new Chrome instance
const chrome = await launch({chromeFlags: ['--headless']});
Expand Down

0 comments on commit 46445b8

Please sign in to comment.