From 13dd048e3f477ea36504be5aacf44466030ef847 Mon Sep 17 00:00:00 2001 From: Steve I <1615137+jixor@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:26:40 +0000 Subject: [PATCH] Reusable Workflow --- .github/workflows/cicd.yml | 67 ++++++++++++++++++++++++ .github/workflows/deploy.yml | 31 +++++++++++ .github/workflows/node.js.yml | 96 ----------------------------------- 3 files changed, 98 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/cicd.yml create mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..1786466 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,67 @@ +name: CICD Workflow + +on: + push: + branches: [master] + pull_request: + branches: [master] + +env: + NODE_ENV: production + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 20.x + - run: npm ci + - run: NODE_ENV=test npm run test:coverage + - uses: codecov/codecov-action@v3 + - run: npm run build + - uses: actions/upload-artifact@v3 + with: + name: build + path: build + + preview: + needs: build + if: github.event.pull_request.base.ref == 'master' + uses: ./.github/workflows/deploy.yml + secrets: inherit + + end-to-end: + needs: preview + runs-on: ubuntu-latest + env: + NODE_ENV: development + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 20.x + - uses: cypress-io/github-action@v6 + env: + CYPRESS_BASE_URL: ${{ needs.preview.outputs.details_url }} + - name: Upload Screenshots + if: failure() + uses: actions/upload-artifact@v3 + with: + name: cypress-screenshots + path: cypress/screenshots + - if: failure() + name: Upload Videos + uses: actions/upload-artifact@v3 + with: + name: cypress-videos + path: cypress/videos + + production: + needs: build + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/deploy.yml + secrets: inherit + with: + channelId: live diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..5102ebe --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,31 @@ +name: Deploy + +on: + workflow_call: + inputs: + channelId: + type: string + required: false + outputs: + details_url: + value: ${{ jobs.deploy.outputs.details_url }} + +jobs: + deploy: + runs-on: ubuntu-latest + outputs: + details_url: ${{ steps.firebase.outputs.details_url }} + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v3 + with: + name: build + path: build + - uses: FirebaseExtended/action-hosting-deploy@v0 + id: firebase + with: + repoToken: '${{ secrets.GITHUB_TOKEN }}' + firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MARGNI_DOUGH }}' + channelId: ${{ inputs.channelId }} + env: + FIREBASE_CLI_PREVIEWS: hostingchannels diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index 99b7ada..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,96 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [master] - pull_request: - branches: [master] - -env: - NODE_ENV: production - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version: 20.x - - run: npm ci - - run: NODE_ENV=test npm run test:coverage - - run: npm run build - - uses: codecov/codecov-action@v3 - - uses: actions/upload-artifact@v3 - with: - name: build - path: build - - preview: - needs: build - runs-on: ubuntu-latest - if: github.event.pull_request.base.ref == 'master' - outputs: - details_url: ${{ steps.deployPreview.outputs.details_url }} - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 - with: - name: build - path: build - - uses: FirebaseExtended/action-hosting-deploy@v0 - id: deployPreview - with: - repoToken: '${{ secrets.GITHUB_TOKEN }}' - firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MARGNI_DOUGH }}' - projectId: margni-dough - env: - FIREBASE_CLI_PREVIEWS: hostingchannels - - end-to-end: - needs: preview - runs-on: ubuntu-latest - env: - NODE_ENV: development - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version: 20.x - - uses: cypress-io/github-action@v6 - env: - CYPRESS_BASE_URL: ${{ needs.preview.outputs.details_url }} - - name: Upload Screenshots - uses: actions/upload-artifact@v3 - if: failure() - with: - name: cypress-screenshots - path: cypress/screenshots - - name: Upload Videos - uses: actions/upload-artifact@v3 - if: always() - with: - name: cypress-videos - path: cypress/videos - - deploy: - needs: build - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 - with: - name: build - path: build - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: '${{ secrets.GITHUB_TOKEN }}' - firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_MARGNI_DOUGH }}' - channelId: live - projectId: margni-dough - env: - FIREBASE_CLI_PREVIEWS: hostingchannels