Skip to content

[Blog] Accompagnement alternants - Ep 2 #1174

[Blog] Accompagnement alternants - Ep 2

[Blog] Accompagnement alternants - Ep 2 #1174

# Deploy a PR preview on GitHub Pages
name: Deploy preview
on:
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy-preview:
name: '🚧 Build & deploy 🚀'
runs-on: ubuntu-latest
timeout-minutes: 10
# Do not run on Draft PRs
if: "!github.event.pull_request || github.event.pull_request.draft == false"
environment:
name: staging
url: https://elao.github.io/elao_/pr/${{ github.event.number }}
steps:
- name: 'Checkout'
uses: actions/checkout@v4
# https://github.com/actions/setup-node
- name: 'Setup node'
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'npm'
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
coverage: "none"
ini-values: "memory_limit=-1"
php-version: "8.3"
- name: 'Cache resized images'
uses: actions/cache@v4
with:
path: public/resized
key: resized-images-${{ github.workflow }}-${{ secrets.CACHE_VERSION }}
- name: 'Determine composer cache directory'
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: 'Cache composer dependencies'
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: 'Install dependencies'
run: |
echo "::group::composer install"
composer install --no-progress --ansi
echo "::endgroup::"
echo "::group::npm install"
npm install --color=always --no-progress --no-audit --no-fund
echo "::endgroup::"
- name: 'Warmup'
run: |
echo "::group::warmup production env"
npx encore production --color
bin/console cache:clear --ansi
bin/console cache:warmup --ansi
echo "::endgroup::"
env:
APP_ENV: prod
WEBPACK_PUBLIC_PATH: /elao_/pr/${{ github.event.number }}/build
# Will re-use the staging resized images folder in resized image URLs
GLIDE_RESIZED_URL_BASE_PATH: '../../resized'
- name: 'Build static site'
run: bin/console stenope:build --no-interaction -vv --ansi --ignore-content-not-found
env:
APP_ENV: prod
APP_FORCE_NO_INDEX: 1
APP_GITHUB_REF: ${{ github.head_ref }}
ROUTER_DEFAULT_URI: https://elao.github.io/elao_/pr/${{ github.event.number }}
# Will re-use the staging resized images folder in resized image URLs
GLIDE_RESIZED_URL_BASE_PATH: '../../resized'
- name: 'Deduplicate images'
run: |
# Merge the resized images from PR build folder to the cached folder (`public/resized`)
rsync -a build/resized/ public/resized/
# Remove the build resized images folder
rm -rf build/resized/
- name: '🖼️ Push resized images'
uses: JamesIves/github-pages-deploy-action@v4
with:
commit-message: |
[AUTO] Deploy PR #${{ github.event.number }} images
for commit ${{ github.sha }}
branch: gh-pages
folder: public/resized
target-folder: resized
clean: false # Sync we rsynced the images to merge from all source, we'll never delete anything from here.
# https://github.com/marketplace/actions/deploy-to-github-pages
- name: '🚀 Deploy'
uses: JamesIves/github-pages-deploy-action@v4
with:
commit-message: |
[AUTO] Deploy PR #${{ github.event.number }}
for commit ${{ github.sha }}
branch: gh-pages # The branch the action should deploy to.
folder: build # The folder the action should deploy.
target-folder: pr/${{ github.event.number }} # The folder
clean: true # Automatically remove deleted files from the deploy branch