8000 ExampleSite: Configure to deploy to GH Pages · nginxinc/nginx-hugo-theme@66b2f80 · GitHub
[go: up one dir, main page]

Skip to content

ExampleSite: Configure to deploy to GitHub Pages #587

ExampleSite: Configure to deploy to GitHub Pages

ExampleSite: Configure to deploy to GitHub Pages #587

Workflow file for this run

name: build preview
on:
pull_request:
branches:
- "*"
env:
REPO_OWNER: "nginx"
REPO_NAME: "documentation"
FRONT_DOOR_USERNAME: ${{ secrets.FRONT_DOOR_USERNAME }}
FRONT_DOOR_PASSWORD: ${{ secrets.FRONT_DOOR_PASSWORD }}
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
MAIN_REPORT_ARTIFACT_NAME: "lighthouse-reports-main"
jobs:
deploy-example-site:
uses: nginxinc/docs-actions/.github/workflows/docs-build-push.yml@04ed2db338ee08cc560a327f412684d0c8260de2 # v1.0.11
with:
production_url_path: "/nginx-hugo-theme"
preview_url_path: "/previews/nginx-hugo-theme"
docs_source_path: "public"
docs_build_path: "./exampleSite"
doc_type: "hugo"
environment: "preview"
force_hugo_theme_version: ""
auto_deploy_branch: "main"
auto_deploy_env: "prod"
secrets:
AZURE_CREDENTIALS: ${{secrets.AZURE_CREDENTIALS_DOCS}}
AZURE_KEY_VAULT: ${{secrets.AZURE_KEY_VAULT_DOCS}}
lighthouseci:
if: github.event.pull_request
needs: deploy-example-site
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: ${{ github.event.workflow_run.head_branch }}
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 22
- name: Installing packages
run: cd performance && npm ci
- name: Generating lighthouse reports for PR...
env:
REPORT_NAME: "pr"
run: |
node performance/lighthouse-script.js
- name: Retrieve the latest artifact ID for lighthouse report main
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
id: fetch-artifact-id
with:
script: |
const { owner, repo } = context.issue;
const response = await github.rest.actions.listArtifactsForRepo({
owner,
repo,
});
const artifactName = process.env.MAIN_REPORT_ARTIFACT_NAME;
const filteredArtifacts = response.data.artifacts.filter(a => a.name === artifactName);
if(filteredArtifacts.length === 0) {
return core.setFailed(`Error: Not able to find artifact with name ${artifactName}`);
}
const latestArtifact = filteredArtifacts.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))[0];
console.log(`Success! Found the latest artifact with name ${artifactName}, with artifact id ${latestArtifact.id} | workflow id ${latestArtifact.workflow_run.id}`);
const download = await github.rest.actions.downloadArtifact({
owner: owner,
repo: repo,
artifact_id: latestArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('./artifact-lighthouse-report-main.zip', Buffer.from(download.data));
result-encoding: string
- name: Unzip the artifact
run: |
unzip ./artifact-lighthouse-report-main.zip
ls -al
- name: Move the main report artifact to same directory as pr report
run: |
mv main-report.json ./lighthouse-reports
- name: Compare the artifacts for negative differences in performance
continue-on-error: true
run: |
FIELDS=("performance" "accessibility")
TOLERANCE=0.05
FLOOR_VALUE=0.90
for FIELD in "${FIELDS[@]}"; do
PR_VALUE=$(cat lighthouse-reports/pr-report.json | jq -r ".categories.$FIELD.score")
MAIN_VALUE=$(cat lighthouse-reports/main-report.json | jq -r ".categories.$FIELD.score")
echo "$FIELD: PR - $PR_VALUE | Main - $MAIN_VALUE"
if (( $(echo "$PR_VALUE < $FLOOR_VALUE" | bc -l) )); then
echo "Error: $FIELD score in PR ($PR_VALUE) is less than accepted value ($FLOOR_VALUE)"
exit 1
fi
if [ $FIELD = "performance" ]; then
LOWER_BOUND=$(echo "$MAIN_VALUE - $TOLERANCE" | bc)
UPPER_BOUND=$(echo "$MAIN_VALUE + $TOLERANCE" | bc)
if (( $(echo "$PR_VALUE < $LOWER_BOUND" | bc -l) || $(echo "$PR_VALUE > $UPPER_BOUND" | bc -l) )); then
echo "Error: $FIELD score in PR ($PR_VALUE) is less than in MAIN ($MAIN_VALUE)"
exit 1
fi
else
if (( $(echo "$PR_VALUE < $MAIN_VALUE" | bc -l) )); then
echo "Error: $FIELD score in PR ($PR_VALUE) is less than in MAIN ($MAIN_VALUE)"
exit 1
fi
fi
done
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ !cancelled() }}
with:
name: lighthouse-reports-pr
path: lighthouse-reports/pr-report.json
retention-days: 3
0