Skip to content

Commit

Permalink
Feat: Prepare testing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelThamm committed Oct 5, 2023
1 parent a8acc05 commit 23d7ba3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/heroku-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ name: Deploy Website

on:
push:
# branches: [ "main" ]
branches: [ "main" ]
tags:
- 'v*'
#
# pull_request:
# branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Docker login
Expand All @@ -31,6 +26,15 @@ jobs:
docker login -u $DOCKER_USER -p $DOCKER_PSWD
docker build . -t michaelthamm/website:$GITHUB_REF_NAME
docker push michaelthamm/website:$GITHUB_REF_NAME
test-local:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Test index.html links
run: |
. ./app/tests/test-urls.sh
deploy:
runs-on: ubuntu-latest
steps:
Expand All @@ -40,3 +44,16 @@ jobs:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
heroku_app_name: "michaelthamm-website"

test-deployed:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Audit URLs using Lighthouse
uses: treosh/lighthouse-ci-action@v10
with:
urls: |
https://www.michaelthamm.com/
budgetPath: ./app/tests/budget.json # test performance budgets
uploadArtifacts: true # save results as an action artifacts
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
11 changes: 11 additions & 0 deletions app/tests/budget.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"path": "/*",
"resourceSizes": [
{
"resourceType": "total",
"budget": 200
}
]
}
]
23 changes: 23 additions & 0 deletions app/tests/test-urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Parse index.html and extract all href attributes starting with https://
links=$(grep -o 'href="https://[^"]*' ./app/templates/index.html | sed 's/href="//')

# Function to check if a given status code is acceptable
is_acceptable_status() {
case "$1" in
200|403|999) return 0 ;;
*) return 1 ;;
esac
}

# Loop through each https:// link and check existence with curl
for link in $links; do
response=$(curl -sL -w "%{http_code}" "$link" -o /dev/null)
if is_acceptable_status "$response"; then
echo "Link $link exists (HTTP $response)"
else
echo "Link $link does not exist or has an unacceptable status code (HTTP $response)"
exit 1
fi
done

0 comments on commit 23d7ba3

Please sign in to comment.