-
Notifications
You must be signed in to change notification settings - Fork 1
113 lines (108 loc) · 4.48 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: CI/CD
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
jobs:
# Generate the site artifact and makes it available for future jobs
build:
runs-on: ubuntu-latest
steps:
# Download latest version of https://github.com/roquec/Portfolio
- name: Checkout portfolio repository
uses: actions/checkout@v4
# Execute script to make last changes to site source before Jekyll build
# - Sets data on version page (commit, build...)
# - Copies project README into the site's README page
- name: Run pre-build custom scripts
shell: pwsh
run: .\.github\actions\set-placeholders.ps1
# Set up Ruby and installs bundler and needed gems from project's Gemfile
- name: Install Ruby v3.2 and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
# Execute Jekyll build command to generate the final site
# - Uses source directory ./src
# - The output directory is ./_site
- name: Run Jekyll build
run: bundle exec jekyll build --source src
# Execute script to add a content hash to all asset links in generated site
- name: Generate asset hashes for links
shell: pwsh
run: .\.github\actions\asset-hash.ps1
# Upload generated site as an artifact so the following jobs can access it
# - Takes content from ./_site by default
# - The output artifact is called "github-pages"
- name: Upload website artifact
uses: actions/upload-pages-artifact@v3
# Downloads site artifact and publishes it to GitHub Pages
deploy:
runs-on: ubuntu-latest
needs: build
steps:
# Configure and enable GitHub Pages
- name: Configure GitHub Pages
uses: actions/configure-pages@v5
# Publish website content from github-pages artifact to our GitHub Pages environment
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Runs Lighthouse tests on live website and publishes results
lighthouse:
runs-on: ubuntu-latest
needs: deploy
steps:
# Checkout only needed scripts from repository
# - Downloads only files from .github/actions
- name: Download action scripts
uses: actions/checkout@v4
with:
sparse-checkout: '.github/actions'
# Install Node to be able to use npm later
- name: Install Node.js v18
uses: actions/setup-node@v4
with:
node-version: 18
# Install Lighthouse CI via npm
- name: Install Lighthouse CI
run: npm install -g @lhci/cli@0.12.x
# Execute Lighthouse CI for both mobile and desktop
# - Runs target only the main url https://roquec.com/
# - Executes 5 runs to get a reliable score
# - Results from mobile run are stored in ./reports/mobile
# - Results from mobile run are stored in ./reports/desktop
- name: Run Lighthouse
run: |
lhci autorun --collect.numberOfRuns=5 --collect.url='https://roquec.com?v=${{github.run_id}}&testing=true' --upload.target=filesystem --upload.outputDir=./reports/mobile
lhci autorun --collect.numberOfRuns=5 --collect.url='https://roquec.com?v=${{github.run_id}}&testing=true' --upload.target=filesystem --upload.outputDir=./reports/desktop --collect.settings.preset=desktop
# Use custom script to generate needed reports from Lighthouse results
# - Generates outputs in ./summary
# - Shield.io badge JSON files according to https://shields.io/badges/endpoint-badge
# - Copy of HTML report for representative runs
# - Markdown summary report
# - Prints markdown summary report to GITHUB_STEP_SUMMARY
- name: Generate Lighthouse report
shell: pwsh
run: .\.github\actions\lighthouse-report.ps1
env:
LIGHTHOUSE_PATH_MOBILE: ./reports/mobile
LIGHTHOUSE_PATH_DESKTOP: ./reports/desktop
LIGHTHOUSE_REPORT_OUTPUT_DIR: ./summary
# Make all Lighthouse report outputs available in a specified gist
- name: Publish reports to gist
shell: pwsh
env:
UPDATE_GIST_TOKEN: ${{ secrets.GISTS_ACCESS_TOKEN }}
UPDATE_GIST_ID: 3f8ee5d85053832ea374a05b301f57aa
UPDATE_GIST_PATH: summary
run: .\.github\actions\update-gist.ps1