diff --git a/.github/main-push-pr.yml b/.github/main-push-pr.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/development-pr-open.yml b/.github/workflows/development-pr-open.yml new file mode 100644 index 0000000..a4319b7 --- /dev/null +++ b/.github/workflows/development-pr-open.yml @@ -0,0 +1,144 @@ +# 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: Dev Branch PR or Push + +on: + push: + branches: [dev] + pull_request: + branches: [dev] + types: [opened, reopened, synchronize] + +jobs: + install: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/iron + cache: "npm" + + - name: Clear Install Dependecies + run: npm ci + + build: + needs: install + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/iron + cache: "npm" + + - name: Clear Install Dependecies + run: npm ci + + - name: Build + run: npm run build + + lint: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/iron + + - name: Clear Install Dependecies + run: npm ci + + - name: Build + run: npm run build + + - name: Lint + run: npm run lint + + # e2e-install-all-deps-with-cypress: + # needs: lint + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Install dependencies + # uses: cypress-io/github-action@v6 + # with: + # # just perform install + # runTests: false + + # # - name: Lint + # # run: npm run lint + + # - name: Run e2e tests + # uses: cypress-io/github-action@v6 + # with: + # # we have already installed all dependencies above + # install: false + # build: npm run build + # start: npm start + # wait-on: http://localhost:3000 + # # Custom: Cypress tests and config file are in "e2e" folder + # # working-directory: e2e + + e2e-cypress-only: + needs: lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: | + ~/.cache/Cypress + node_modules + key: my-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install Cypress only + run: npm i cypress + + - name: Run e2e tests + uses: cypress-io/github-action@v6 + with: + # we have already installed all dependencies above + install: false + build: npm run build + start: npm start + wait-on: http://localhost:3000 + # Custom: Cypress tests and config file are in "e2e" folder + # working-directory: e2e + + deploy-preview: + needs: e2e-cypress-only + if: github.event.pull_request.merged == false + uses: ./.github/workflows/preview-pr-open.yml + secrets: inherit # needs this whenever we use reusables otherwise secrets won't work + + + # how to make a version to build for dev branch + # deploy-dev: diff --git a/.github/workflows/main-push-pr.yml b/.github/workflows/main-push-pr.yml new file mode 100644 index 0000000..d4ecb0a --- /dev/null +++ b/.github/workflows/main-push-pr.yml @@ -0,0 +1,147 @@ +# 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: Main Branch PR or Push + +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, reopened, synchronize] + +jobs: + install: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/iron + cache: "npm" + + - name: Clear Install Dependecies + run: npm ci + + build: + needs: install + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/iron + cache: "npm" + + - name: Clear Install Dependecies + run: npm ci + + - name: Build + run: npm run build + + lint: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/iron + + - name: Clear Install Dependecies + run: npm ci + + - name: Build + run: npm run build + + - name: Lint + run: npm run lint + + # e2e-install-all-deps-with-cypress: + # needs: lint + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Install dependencies + # uses: cypress-io/github-action@v6 + # with: + # # just perform install + # runTests: false + + # # - name: Lint + # # run: npm run lint + + # - name: Run e2e tests + # uses: cypress-io/github-action@v6 + # with: + # # we have already installed all dependencies above + # install: false + # build: npm run build + # start: npm start + # wait-on: http://localhost:3000 + # # Custom: Cypress tests and config file are in "e2e" folder + # # working-directory: e2e + + e2e-cypress-only: + needs: lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: | + ~/.cache/Cypress + node_modules + key: my-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Install Cypress only + run: npm i cypress + + - name: Run e2e tests + uses: cypress-io/github-action@v6 + with: + # we have already installed all dependencies above + install: false + build: npm run build + start: npm start + wait-on: http://localhost:3000 + # Custom: Cypress tests and config file are in "e2e" folder + # working-directory: e2e + + deploy-preview: + needs: e2e-cypress-only + if: github.event.pull_request.merged == false + uses: ./.github/workflows/reusable-preview-pr-open.yml + secrets: inherit # needs this whenever we use reusables otherwise secrets won't work + + deploy-prod: + needs: e2e-cypress-only + if: github.event.pull_request.merged == true + uses: ./.github/workflows/reusable-deploy-prod.yml + secrets: inherit # needs this whenever we use reusables otherwise secrets won't work + diff --git a/.github/workflows/reusable-deploy-prod.yml b/.github/workflows/reusable-deploy-prod.yml new file mode 100644 index 0000000..3edb2d9 --- /dev/null +++ b/.github/workflows/reusable-deploy-prod.yml @@ -0,0 +1,40 @@ +name: Vercel Production Deployment + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +on: + # push: + # branches: + # - main + workflow_call: + inputs: + stage: + type: string + required: false + environment: + type: string + required: false + affected: + type: boolean + default: false + required: false + +jobs: + Deploy-Production: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Project Artifacts + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} diff --git a/.github/workflows/reusable-preview-pr-open.yml b/.github/workflows/reusable-preview-pr-open.yml new file mode 100644 index 0000000..eed636f --- /dev/null +++ b/.github/workflows/reusable-preview-pr-open.yml @@ -0,0 +1,45 @@ +name: Vercel PR Preview Deployment + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +# on: +# push: +# branches-ignore: +# - main +# pull_request: +# branches: [main] +# types: [opened, reopened, synchronize] + +on: + workflow_call: + inputs: + stage: + type: string + required: false + environment: + type: string + required: false + affected: + type: boolean + default: false + required: false + +jobs: + Deploy-Preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Project Artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} diff --git a/README.md b/README.md index a7ab262..d66af9c 100644 --- a/README.md +++ b/README.md @@ -40,15 +40,53 @@ The following command runs the e2e test on the terminal only. npm run cy:run ``` -None of these commands will be used in the GitHub actions if `cypress-io/github-action@v6` is used because `cypress-io/github-action@v6` does it for you. +None of these commands will be used in the GitHub actions if `cypress-io/github-action@v6` is used because `cypress-io/github-action@v6` does all for you. ## Deploy on Vercel +The following steps overwrites or cancels the auto deploy on Vercel. Because, we want all the GitHub Actions checks to pass first before a deploy happens. If don't cancel the Vercel auto-deploy, then there's just gonna be a deployment to Vercel no matter what. + ### Add this project in Vercel Import this repo in Vercel. -### +### Vercel CLI + +```bash +vercel login +``` + +Link this app to Vercel + +```bash +vercel +``` + +Follow all the prompts. + +A `.vercel` folder with a `project.json` inside should generated. The `project.json` should have the `projectId` and `orgId`. + +### Generate a token (if you already haven't) + +Go the Vercel website. Login to your account. And generate a token. + +### Save the as GitHub Secrets + +The following variables should be saved as GitHub secrets. + +```bash +VERCEL_TOKEN +VERCEL_ORG_ID +VERCEL_PROJECT_ID +``` + +## GitHub Actions + +Have all the GitHub action jobs. Have a resuable YAML file that has the code to deploy to preview or to production on Vercel. This file will be triggered after all the previous required checks passed. Since we turned off the auto deploy for this project in Vercel, the resuable YAML file will make the deployment. + +### Preview link + +The preview link will be generated in the GitHub Actions check logs. You'd have to go to page to get the preview link that was generated. Unfortunately as of now, there's now way to make the fancy and convenient bar have the link that the Vercel Auto Deploy does. ## Setup Cypress diff --git a/cypress/e2e/modalForm.spec.ts b/cypress/e2e/modalForm.spec.ts index e5d39cc..ed334f7 100644 --- a/cypress/e2e/modalForm.spec.ts +++ b/cypress/e2e/modalForm.spec.ts @@ -178,15 +178,15 @@ describe("Modal Form", () => { .check("blueberry") .should("be.checked"); cy.wait(1000); - cy.getBySel("radio-choices-field") - .find("input[type='radio']") - .check("regular") - .should("be.checked"); - cy.wait(1000); - cy.getBySel("radio-choices-field") - .find("input[type='radio']") - .check("lime") - .should("be.checked"); - cy.wait(1000); + // cy.getBySel("radio-choices-field") + // .find("input[type='radio']") + // .check("regular") + // .should("be.checked"); + // cy.wait(1000); + // cy.getBySel("radio-choices-field") + // .find("input[type='radio']") + // .check("lime") + // .should("be.checked"); + // cy.wait(1000); }); }); diff --git a/src/components/ModalForm.tsx b/src/components/ModalForm.tsx index 314e138..1410871 100644 --- a/src/components/ModalForm.tsx +++ b/src/components/ModalForm.tsx @@ -288,8 +288,7 @@ export default function ModalForm(props: ModalFormType) { type="radio" className="radio checked:bg-red-500 mr-2" value={TopoChicoFlavor.Regular} - {...(register("topoChicoFlavor"), - { + {...register("topoChicoFlavor", { required: true, })} /> @@ -301,8 +300,7 @@ export default function ModalForm(props: ModalFormType) { type="radio" className="radio checked:bg-green-500 mr-2" value={TopoChicoFlavor.Lime} - {...(register("topoChicoFlavor"), - { + {...register("topoChicoFlavor", { required: true, })} /> @@ -314,8 +312,7 @@ export default function ModalForm(props: ModalFormType) { type="radio" className="radio checked:bg-blue-500 mr-2" value={TopoChicoFlavor.Blueberry} - {...(register("topoChicoFlavor"), - { + {...register("topoChicoFlavor", { required: true, })} />