From cd2af96beef75c555dd43ae8ca54affa14ff90a2 Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Wed, 17 Mar 2021 09:35:25 +0100 Subject: [PATCH] Utilise github actions pour le build de production --- .github/workflows/netlify.yaml | 55 ++++++++++++++++++++++++---------- netlify.toml | 24 --------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/.github/workflows/netlify.yaml b/.github/workflows/netlify.yaml index 8c68bdd56..06196bd28 100644 --- a/.github/workflows/netlify.yaml +++ b/.github/workflows/netlify.yaml @@ -2,20 +2,33 @@ name: Déploiement sur Netlify on: pull_request: types: [opened, synchronize] -env: - GITHUB_API_SECRET: ${{ secrets.GITHUB_TOKEN }} - ZAMMAD_API_SECRET_KEY: ${{ secrets.ZAMMAD_API_SECRET_KEY }} - ATINTERNET_API_SECRET_KEY: ${{ secrets.ATINTERNET_API_SECRET_KEY }} - ATINTERNET_API_ACCESS_KEY: ${{ secrets.ATINTERNET_API_ACCESS_KEY }} - INSEE_SIRENE_API_SECRET: ${{ secrets.INSEE_SIRENE_API_TOKEN }} - MATOMO_TOKEN: ${{ secrets.MATOMO_TOKEN }} - EN_SITE: "${path}?s=m" - FR_SITE: "${path}" - AT_INTERNET_SITE_ID: 617189 + push: + branches: [master, demo, next] + + jobs: build: runs-on: ubuntu-18.04 steps: + - name: Set branch name + id: vars + run: echo ::set-output name=branch::${GITHUB_REF#refs/*/} + - if: github.event_name == 'pull_request' + name: 'Set site name for pull request deploy' + run: + echo "FR_SITE=deploy-preview-${{ github.event.number }}--syso.netlify.app/\${path}" >> $GITHUB_ENV; + echo "EN_SITE=deploy-preview-${{ github.event.number }}--syso.netlify.app/\${path}?s%3Dm" >> $GITHUB_ENV; + - if: github.event_name == 'push' && github.ref != 'refs/heads/master' + name: 'Set site name for named branch deploy' + run: + echo "FR_SITE=https://${{ steps.vars.outputs.branch }}.mon-entreprise.fr/\${path}" >> $GITHUB_ENV; + echo "EN_SITE=https://${{ steps.vars.outputs.branch }}.mon-entreprise.fr/\${path}?s%3Dm" >> $GITHUB_ENV; + - if: github.ref == 'refs/heads/master' + name: 'Set site name for production deploy' + run: + echo "FR_SITE=https://mon-entreprise.fr/\${path}" >> $GITHUB_ENV; + echo "EN_SITE=https://mycompanyinfrance.fr/\${path}" >> $GITHUB_ENV + - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: @@ -24,9 +37,19 @@ jobs: with: path: '**/node_modules' key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}-v2 - - run: npm install yarn - run: yarn install - - run: yarn workspace mon-entreprise build + env: + # Secrets of all kinds for fetching stats & releases + GITHUB_API_SECRET: ${{ secrets.GITHUB_TOKEN }} + ZAMMAD_API_SECRET_KEY: ${{ secrets.ZAMMAD_API_SECRET_KEY }} + ATINTERNET_API_SECRET_KEY: ${{ secrets.ATINTERNET_API_SECRET_KEY }} + ATINTERNET_API_ACCESS_KEY: ${{ secrets.ATINTERNET_API_ACCESS_KEY }} + - name: Build app + run: yarn workspace mon-entreprise build + env: + # Deploy dependant config (change for production settings) + AT_INTERNET_SITE_ID: ${{ github.ref == 'refs/heads/master' && 617190 || 617189 }} + NODE_ENV: production - name: Deploy to Netlify id: deploy-netlify uses: nwtgck/actions-netlify@v1.1 @@ -34,16 +57,18 @@ jobs: publish-dir: './mon-entreprise/dist' netlify-config-path: ./netlify.toml production-branch: master + production-deploy: ${{ github.ref == 'refs/heads/master' }} github-token: ${{ secrets.GITHUB_TOKEN }} - enable-commit-comment: false + enable-commit-comment: ${{ github.event_name == 'push' }} # Disabled because we create our own customized comment enable-pull-request-comment: false - alias: deploy-preview-${{ github.event.number }} + alias: ${{ github.event_name == 'push' && steps.vars.outputs.branch || format('deploy-preview-{0}', github.event.number) }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} timeout-minutes: 1 - name: Find Comment + if: github.event_name == 'pull_request' uses: peter-evans/find-comment@v1 id: find-comment with: @@ -51,7 +76,7 @@ jobs: comment-author: 'github-actions[bot]' body-includes: netlify - name: Create comment - if: ${{ steps.find-comment.outputs.comment-id == 0 }} + if: steps.find-comment.outputs.comment-id == 0 uses: peter-evans/create-or-update-comment@v1 with: issue-number: ${{ github.event.pull_request.number }} diff --git a/netlify.toml b/netlify.toml index 21d3bde84..f2ce4d501 100644 --- a/netlify.toml +++ b/netlify.toml @@ -242,27 +242,3 @@ from = "/*" to = "/mon-entreprise.html" status = 200 - -[build] - # Hack while waiting for netlify to support workspace - # https://github.com/netlify/build-image/issues/196 - command = "npm i yarn && yarn && yarn workspaces run prepare && yarn workspace mon-entreprise build" - publish = "mon-entreprise/dist" - -[context.deploy-preview.environment] - EN_SITE = "${path}?s=m" - FR_SITE = "${path}" - AT_INTERNET_SITE_ID = "617189" - -[context.production.environment] - EN_SITE = "https://mycompanyinfrance.fr${path}" - FR_SITE = "https://mon-entreprise.fr${path}" - AT_INTERNET_SITE_ID = "617190" - -[context."demo".environment] - EN_SITE = "https://demo.mon-entreprise.fr${path}?s=m" - FR_SITE = "https://demo.mon-entreprise.fr${path}" - -[context."next".environment] - EN_SITE = "https://next.mon-entreprise.fr${path}?s=m" - FR_SITE = "https://next.mon-entreprise.fr${path}"