From d5838d354179e83977b8ac5df0d9a9ba99801a59 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 2 Dec 2020 09:34:21 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"Utilisation=20du=20CI=20de?= =?UTF-8?q?=20GitHub=20pour=20le=20d=C3=A9ploiement=20Netlify=20(#1249)""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7f9bf69603036b6b6adb97e25eeab0dc7000dc30. --- .github/workflows/netlify.yaml | 55 +++++++++++++++++++ .github/workflows/zammad-bot.yaml | 1 + .../source/sites/mon-entreprise.fr/App.tsx | 14 +++-- mon-entreprise/source/types/app-env.d.ts | 8 +-- mon-entreprise/webpack.common.js | 6 +- mon-entreprise/webpack.prod.legacyBrowser.js | 6 +- 6 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/netlify.yaml diff --git a/.github/workflows/netlify.yaml b/.github/workflows/netlify.yaml new file mode 100644 index 000000000..f02d4d035 --- /dev/null +++ b/.github/workflows/netlify.yaml @@ -0,0 +1,55 @@ +name: Déploiement sur Netlify +on: + pull_request: + types: [opened, synchronize] +env: + GITHUB_API_SECRET: ${{ secrets.GITHUB_TOKEN }} + INSEE_SIRENE_API_SECRET: ${{ secrets.INSEE_SIRENE_API_TOKEN }} + MATOMO_TOKEN: ${{ secrets.MATOMO_TOKEN }} +jobs: + build: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12' + - uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + - run: npm install yarn + - run: yarn install + - run: yarn workspace mon-entreprise build + - name: Deploy to Netlify + id: deploy-netlify + uses: nwtgck/actions-netlify@v1.1 + with: + publish-dir: './mon-entreprise/dist' + netlify-config-path: ./netlify.toml + production-branch: master + github-token: ${{ secrets.GITHUB_TOKEN }} + enable-commit-comment: false + # Disabled because we create our own customized comment + enable-pull-request-comment: false + alias: deploy-preview-${{ github.event.number }} + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + timeout-minutes: 1 + - name: Find Comment + uses: peter-evans/find-comment@v1 + 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 + if: ${{ steps.find-comment.outputs.comment-id == 0 }} + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + 🚀 La branche est déployée ! ${{ steps.deploy-netlify.outputs.deploy-url }} + + _Voir aussi : [version anglaise](${{ steps.deploy-netlify.outputs.deploy-url }}?s=m) | [site publicodes](${{ steps.deploy-netlify.outputs.deploy-url }}?s=p)_ diff --git a/.github/workflows/zammad-bot.yaml b/.github/workflows/zammad-bot.yaml index e130f2da5..165df262b 100644 --- a/.github/workflows/zammad-bot.yaml +++ b/.github/workflows/zammad-bot.yaml @@ -1,4 +1,5 @@ # This bot post a comment when issues with a given label are closed. +name: Message du robot Zammad on: issues: types: [closed] diff --git a/mon-entreprise/source/sites/mon-entreprise.fr/App.tsx b/mon-entreprise/source/sites/mon-entreprise.fr/App.tsx index d638c6e9e..b6c449d00 100644 --- a/mon-entreprise/source/sites/mon-entreprise.fr/App.tsx +++ b/mon-entreprise/source/sites/mon-entreprise.fr/App.tsx @@ -50,16 +50,20 @@ import redirects from './redirects' import { constructLocalizedSitePath } from './sitePaths' if (process.env.NODE_ENV === 'production') { + let branch: string | undefined = process.env.GITHUB_REF?.split('/')?.slice( + -1 + )?.[0] + if (branch === 'merge') { + branch = process.env.GITHUB_HEAD_REF + } const release = - process.env.HEAD && - process.env.COMMIT_REF && - process.env.HEAD + '-' + process.env.COMMIT_REF?.substring(0, 7) + branch && `${branch}-` + process.env.GITHUB_SHA?.substring(0, 7) const dsn = 'https://9051375f856646d694943532caf2b45f@sentry.data.gouv.fr/18' Sentry.init({ dsn, release }) - if (process.env.HEAD && process.env.HEAD !== 'master') { + if (branch && branch !== 'master') { console.log( - `ℹ Vous êtes sur la branche : %c${process.env.HEAD}`, + `ℹ Vous êtes sur la branche : %c${branch}`, 'font-weight: bold; text-decoration: underline;' ) } diff --git a/mon-entreprise/source/types/app-env.d.ts b/mon-entreprise/source/types/app-env.d.ts index 9884aa9fd..59e04ecf6 100644 --- a/mon-entreprise/source/types/app-env.d.ts +++ b/mon-entreprise/source/types/app-env.d.ts @@ -5,10 +5,10 @@ declare namespace NodeJS { NODE_ENV: 'development' | 'production' | 'test' ANALYZE_BUNDLE: '0' | '1' - // Netlify variables - // https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables - HEAD: string - COMMIT_REF: string + // Github actions env variables + // https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables + GITHUB_REF: string + GITHUB_SHA: string // .env variables GITHUB_API_SECRET: string diff --git a/mon-entreprise/webpack.common.js b/mon-entreprise/webpack.common.js index 77a2666e3..662c65cc8 100644 --- a/mon-entreprise/webpack.common.js +++ b/mon-entreprise/webpack.common.js @@ -34,7 +34,11 @@ module.exports.default = { EN_SITE: '/infrance${path}', FR_SITE: '/mon-entreprise${path}' }), - new EnvironmentPlugin({ HEAD: '', COMMIT_REF: '' }), + new EnvironmentPlugin({ + GITHUB_REF: '', + GITHUB_HEAD_REF: '', + GITHUB_SHA: '' + }), new CopyPlugin([ './manifest.webmanifest', { diff --git a/mon-entreprise/webpack.prod.legacyBrowser.js b/mon-entreprise/webpack.prod.legacyBrowser.js index 92d1ba1a2..3394c8560 100644 --- a/mon-entreprise/webpack.prod.legacyBrowser.js +++ b/mon-entreprise/webpack.prod.legacyBrowser.js @@ -17,7 +17,11 @@ module.exports = { }, plugins: [ new MonacoWebpackPlugin(), - new EnvironmentPlugin({ HEAD: '', COMMIT_REF: '' }), + new EnvironmentPlugin({ + GITHUB_REF: '', + GITHUB_HEAD_REF: '', + GITHUB_SHA: '' + }), new EnvironmentPlugin({ EN_SITE: '/infrance${path}', FR_SITE: '/mon-entreprise${path}'