Skip to content

Déploiement

Déploiement #7013

Workflow file for this run

name: Déploiement
on:
pull_request:
types: [opened, synchronize]
push:
branches: [master, demo, next]
# We display the release notes in the "news" section of mon-entreprise.urssaf.fr so
# we want to re-deploy the site when a new release is published or edited on
# GitHub.
release:
types: [published, edited]
# The /stats data is generated during the build. To keep the daily data fresh,
# we relaunch a nightly full build of the app
schedule:
- cron: '0 4 * * *'
jobs:
deploy-context:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-22.04
outputs:
env-name: ${{ steps.deploy-env.outputs.name }}
api_url: ${{ steps.base-urls.outputs.api }}
server_url: ${{ steps.base-urls.outputs.server }}
fr_url: ${{ steps.base-urls.outputs.fr }}
en_url: ${{ steps.base-urls.outputs.en }}
steps:
- id: deploy-env
run: echo "name=${{ github.event.number || '${GITHUB_REF#refs/*/}' }}" >> $GITHUB_OUTPUT
- id: base-urls
run:
echo "server=${{ steps.deploy-env.outputs.name == 'master' && 'https://mon-entreprise-server.osc-fr1.scalingo.io' || format('https://mon-entreprise-server-pr{0}.osc-fr1.scalingo.io', steps.deploy-env.outputs.name) }}" >> $GITHUB_OUTPUT;
echo "api=${{ steps.deploy-env.outputs.name == 'master' && 'https://mon-entreprise-api.osc-fr1.scalingo.io' || format('https://mon-entreprise-api-pr{0}.osc-fr1.scalingo.io', steps.deploy-env.outputs.name) }}" >> $GITHUB_OUTPUT;
echo "fr=${{ steps.deploy-env.outputs.name == 'master' && 'https://mon-entreprise.urssaf.fr' || format('https://{0}--mon-entreprise.netlify.app', steps.deploy-env.outputs.name) }}" >> $GITHUB_OUTPUT;
echo "en=${{ steps.deploy-env.outputs.name == 'master' && 'https://mycompanyinfrance.urssaf.fr' || format('https://{0}-en--mon-entreprise.netlify.app', steps.deploy-env.outputs.name) }}" >> $GITHUB_OUTPUT;
build:
needs: deploy-context
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
env:
API_BASE_URL: ${{ needs.deploy-context.outputs.api_url }}
SERVER_BASE_URL: ${{ needs.deploy-context.outputs.server_url }}
VITE_FR_BASE_URL: ${{ needs.deploy-context.outputs.fr_url }}
VITE_EN_BASE_URL: ${{ needs.deploy-context.outputs.en_url }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install
env:
# Secrets of all kinds for fetching stats & releases
GITHUB_API_SECRET: ${{ secrets.GITHUB_TOKEN }}
ATINTERNET_API_SECRET_KEY: ${{ secrets.ATINTERNET_API_SECRET_KEY }}
ATINTERNET_API_ACCESS_KEY: ${{ secrets.ATINTERNET_API_ACCESS_KEY }}
CRISP_API_IDENTIFIER: ${{ secrets.CRISP_API_IDENTIFIER }}
CRISP_API_KEY: ${{ secrets.CRISP_API_KEY }}
CRISP_WEBSITE_ID: ${{ secrets.CRISP_WEBSITE_ID }}
- name: Build app
run: yarn workspace site build
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
VITE_AT_INTERNET_SITE_ID: ${{ needs.deploy-context.outputs.env-name == 'master' && 617190 || 617189 }}
VITE_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
VITE_ALGOLIA_SEARCH_KEY: ${{secrets.ALGOLIA_SEARCH_KEY}}
VITE_ALGOLIA_INDEX_PREFIX: monentreprise-${{needs.deploy-context.outputs.env-name}}-
VITE_GITHUB_REF: ${{ github.ref }}
VITE_GITHUB_HEAD_REF: ${{ github.head_ref }}
VITE_GITHUB_SHA: ${{ github.sha }}
- name: Build app SSR
run: |
yarn workspace site build:ssr
- name: Prerender common routes
run: |
yarn workspace site build:prerender --netlify-toml-path ./netlify.base.toml
- name: Replace site placeholders in netlify.toml redirection file
run: |
cp site/netlify.base.toml site/netlify.toml;
sed -i "s|:API_URL|$API_BASE_URL|g" site/netlify.toml;
sed -i "s|:SERVER_URL|$SERVER_BASE_URL|g" site/netlify.toml;
sed -i "s|:SITE_FR|$VITE_FR_BASE_URL|g" site/netlify.toml;
sed -i "s|:SITE_EN|$VITE_EN_BASE_URL|g" site/netlify.toml;
- name: Update Algolia index
run: yarn workspace site algolia:update
env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
ALGOLIA_SEARCH_KEY: ${{secrets.ALGOLIA_SEARCH_KEY}}
ALGOLIA_INDEX_PREFIX: monentreprise-${{needs.deploy-context.outputs.env-name}}-
- uses: actions/upload-artifact@v3
with:
name: static-site
path: |
site/dist/**
site/netlify.toml
if-no-files-found: error
build-storybook:
needs: deploy-context
env:
VITE_FR_BASE_URL: ${{ needs.deploy-context.outputs.fr_url }}
VITE_EN_BASE_URL: ${{ needs.deploy-context.outputs.en_url }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install
env:
# Secrets of all kinds for fetching stats & releases
GITHUB_API_SECRET: ${{ secrets.GITHUB_TOKEN }}
ATINTERNET_API_SECRET_KEY: ${{ secrets.ATINTERNET_API_SECRET_KEY }}
ATINTERNET_API_ACCESS_KEY: ${{ secrets.ATINTERNET_API_ACCESS_KEY }}
CRISP_API_IDENTIFIER: ${{ secrets.CRISP_API_IDENTIFIER }}
CRISP_API_KEY: ${{ secrets.CRISP_API_KEY }}
CRISP_WEBSITE_ID: ${{ secrets.CRISP_WEBSITE_ID }}
- name: Build Storybook
run: yarn workspace site build:storybook
- uses: actions/upload-artifact@v3
with:
name: static-storybook
path: |
site/storybook-static/**
if-no-files-found: error
build-api:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install
- name: Build API
run: yarn workspace api build
- uses: actions/upload-artifact@v3
with:
name: static-api
path: |
api/dist/**
if-no-files-found: error
deploy-preview:
needs: [build, build-storybook, deploy-context]
runs-on: ubuntu-22.04
if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && needs.deploy-context.outputs.env-name != 'master'
strategy:
matrix:
site: ['', 'en']
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: static-site
- uses: actions/download-artifact@v3
with:
name: static-storybook
path: dist/dev/storybook
- id: deploy-netlify
uses: nwtgck/actions-netlify@v2
with:
publish-dir: './dist'
netlify-config-path: ./netlify.toml
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-commit-status: true
enable-commit-comment: false
github-deployment-environment: ${{ needs.deploy-context.outputs.env-name }}
alias: ${{ needs.deploy-context.outputs.env-name }}${{ matrix.site && format('-{0}', matrix.site) }}
deploy-message: ${{ github.event.pull_request.title || needs.deploy-context.outputs.env-name }} (${{ matrix.site || 'fr' }})
fails-without-credentials: true
# Disabled because we create our own customized comment
enable-pull-request-comment: false
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
deploy-prod:
needs: [build, build-storybook, deploy-context]
runs-on: ubuntu-22.04
if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && needs.deploy-context.outputs.env-name == 'master'
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: static-site
- uses: actions/download-artifact@v3
with:
name: static-storybook
path: dist/dev/storybook
- id: deploy-netlify
uses: nwtgck/actions-netlify@v2
with:
publish-dir: './dist'
netlify-config-path: ./netlify.toml
production-deploy: true
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-commit-status: true
enable-commit-comment: false
github-deployment-environment: master
deploy-message: Deploy production branch
fails-without-credentials: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
post-comment:
runs-on: ubuntu-22.04
if: github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request'
needs: [deploy-preview, deploy-context]
steps:
- name: Find Comment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }} #e.g. 1
comment-author: 'github-actions[bot]'
body-includes: netlify
- name: Create comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
🚀 La branche est déployée !
- mon-entreprise : ${{ needs.deploy-context.outputs.fr_url }}
- mycompanyinfrance : ${{ needs.deploy-context.outputs.en_url }}
- storybook : ${{ needs.deploy-context.outputs.fr_url }}/dev/storybook/ ([version EN](${{ needs.deploy-context.outputs.en_url }}/dev/storybook/))
- API : ${{ needs.deploy-context.outputs.fr_url }}/api/v1/doc/
e2e-test-preview:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
runs-on: ubuntu-22.04
container: cypress/browsers:latest
# We need to specify always() https://github.com/actions/runner/issues/491
if: always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && needs.deploy-preview.result == 'success'
needs: [deploy-context, deploy-preview]
strategy:
fail-fast: false
matrix:
site: ['fr', 'en']
browser: [chrome] # Firefox is very slow…
viewport: [default, small]
container: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
include:
- site: fr
specPattern: mon-entreprise/**/*.{js,jsx,ts,tsx}
baseUrl: ${{ needs.deploy-context.outputs.fr_url }}
language: fr
- site: en
specPattern: mon-entreprise/english/**/*.{js,jsx,ts,tsx}
baseUrl: ${{ needs.deploy-context.outputs.en_url }}
language: en
# Use 4 containers for 'en' and 10 for 'fr'
exclude:
- site: en
container: 1
- site: en
container: 2
- site: en
container: 3
- site: en
container: 4
- site: en
container: 5
- site: en
container: 6
- site: en
container: 7
- site: en
container: 8
- site: en
container: 9
- site: en
container: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/install
- name: Test e2e mon-entreprise on preview (site=${{ matrix.site }}, browser=${{ matrix.browser}}, viewport=${{ matrix.viewport }})
uses: cypress-io/github-action@v5
with:
# Hack to use local node version, issue : https://github.com/cypress-io/github-action/issues/489#issuecomment-1021379037
command-prefix: '--'
install: false
working-directory: site
record: true
tag: ${{ needs.deploy-context.outputs.env-name }}_deploy
config: specPattern=cypress/integration/${{ matrix.specPattern }},baseUrl=${{ matrix.baseUrl }}${{ matrix.viewport == 'small' && ',viewportHeight=740,viewportWidth=360' || '' }}
env: language=${{ matrix.language }}
browser: ${{ matrix.browser }}
parallel: true
group: ${{ matrix.site }}-${{ matrix.browser }}-viewport_${{ matrix.viewport }}
ci-build-id: '${{ github.sha }}-${{ github.event_name }}-${{ github.run_id }}-${{ github.run_attempt }}'
env:
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
e2e-test-production:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
runs-on: ubuntu-22.04
container: cypress/browsers:latest
# We need to specify always() https://github.com/actions/runner/issues/491
if: always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && needs.deploy-prod.result == 'success'
needs: [deploy-context, deploy-prod]
strategy:
fail-fast: false
matrix:
site: ['fr', 'en']
browser: [chrome] # Firefox is very slow…
viewport: [default, small]
container: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
include:
- site: fr
specPattern: mon-entreprise/**/*.{js,jsx,ts,tsx}
baseUrl: ${{ needs.deploy-context.outputs.fr_url }}
language: fr
- site: en
specPattern: mon-entreprise/english/**/*.{js,jsx,ts,tsx}
baseUrl: ${{ needs.deploy-context.outputs.en_url }}
language: en
# Use 4 containers for 'en' and 10 for 'fr'
exclude:
- site: en
container: 1
- site: en
container: 2
- site: en
container: 3
- site: en
container: 4
- site: en
container: 5
- site: en
container: 6
- site: en
container: 7
- site: en
container: 8
- site: en
container: 9
- site: en
container: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/install
- name: Test e2e mon-entreprise on production (site=${{ matrix.site }}, browser=${{ matrix.browser}}, viewport=${{ matrix.viewport }})
uses: cypress-io/github-action@v5
with:
install: false
working-directory: site
record: true
tag: ${{ needs.deploy-context.outputs.env-name }}_deploy
config: specPattern=cypress/integration/${{ matrix.specPattern }},baseUrl=${{ matrix.baseUrl }}${{ matrix.viewport == 'small' && ',viewportHeight=740,viewportWidth=360' || '' }}
env: language=${{ matrix.language }}
browser: ${{ matrix.browser }}
parallel: true
group: ${{ matrix.site }}-${{ matrix.browser }}-viewport_${{ matrix.viewport }}
ci-build-id: '${{ github.sha }}-${{ github.event_name }}-${{ github.run_id }}-${{ github.run_attempt }}'
env:
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}